This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 66498b4bfd fix: create_random_batch fails with timestamp types having
a timezone (#7162)
66498b4bfd is described below
commit 66498b4bfd56a5b5c2fd70a506985a61dd7e9ca4
Author: niebayes <[email protected]>
AuthorDate: Thu Feb 20 18:38:33 2025 +0800
fix: create_random_batch fails with timestamp types having a timezone
(#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]>
---
arrow/src/util/data_gen.rs | 54 ++++++++++++++++++++++++++++++++--------------
1 file changed, 38 insertions(+), 16 deletions(-)
diff --git a/arrow/src/util/data_gen.rs b/arrow/src/util/data_gen.rs
index 5f63812e51..d980f74985 100644
--- a/arrow/src/util/data_gen.rs
+++ b/arrow/src/util/data_gen.rs
@@ -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,
@@ -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();