Skip to content

Commit

Permalink
fix: create_random_batch fails with timestamp types having a timezone (
Browse files Browse the repository at this point in the history
…#7162)

* fix: create_random_batch fail with timestamp types with timezone

* Apply suggestions from code review

Co-authored-by: Matthijs Brobbel <[email protected]>

---------

Co-authored-by: Matthijs Brobbel <[email protected]>
  • Loading branch information
niebayes and mbrobbel authored Feb 20, 2025
1 parent 6d6c939 commit 66498b4
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions arrow/src/util/data_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,33 @@ pub fn create_random_array(
size,
primitive_null_density,
)),
Timestamp(unit, _) => {
match unit {
TimeUnit::Second => Arc::new(create_random_temporal_array::<TimestampSecondType>(
Timestamp(unit, tz) => match unit {
TimeUnit::Second => Arc::new(
create_random_temporal_array::<TimestampSecondType>(size, primitive_null_density)
.with_timezone_opt(tz.clone()),
),
TimeUnit::Millisecond => Arc::new(
create_random_temporal_array::<TimestampMillisecondType>(
size,
primitive_null_density,
)),
TimeUnit::Millisecond => Arc::new(create_random_temporal_array::<
TimestampMillisecondType,
>(size, primitive_null_density)),
TimeUnit::Microsecond => Arc::new(create_random_temporal_array::<
TimestampMicrosecondType,
>(size, primitive_null_density)),
TimeUnit::Nanosecond => Arc::new(create_random_temporal_array::<
TimestampNanosecondType,
>(size, primitive_null_density)),
}
}
)
.with_timezone_opt(tz.clone()),
),
TimeUnit::Microsecond => Arc::new(
create_random_temporal_array::<TimestampMicrosecondType>(
size,
primitive_null_density,
)
.with_timezone_opt(tz.clone()),
),
TimeUnit::Nanosecond => Arc::new(
create_random_temporal_array::<TimestampNanosecondType>(
size,
primitive_null_density,
)
.with_timezone_opt(tz.clone()),
),
},
Date32 => Arc::new(create_random_temporal_array::<Date32Type>(
size,
primitive_null_density,
Expand Down Expand Up @@ -519,7 +529,19 @@ mod tests {
#[test]
fn test_create_batch() {
let size = 32;
let fields = vec![Field::new("a", DataType::Int32, true)];
let fields = vec![
Field::new("a", DataType::Int32, true),
Field::new(
"timestamp_without_timezone",
DataType::Timestamp(TimeUnit::Nanosecond, None),
true,
),
Field::new(
"timestamp_with_timezone",
DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into())),
true,
),
];
let schema = Schema::new(fields);
let schema_ref = Arc::new(schema);
let batch = create_random_batch(schema_ref.clone(), size, 0.35, 0.7).unwrap();
Expand Down

0 comments on commit 66498b4

Please sign in to comment.