Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow-arith/src/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ impl ExtractDatePartExt for PrimitiveArray<DurationNanosecondType> {

macro_rules! return_compute_error_with {
($msg:expr, $param:expr) => {
return { Err(ArrowError::ComputeError(format!("{}: {:?}", $msg, $param))) }
return { Err(ArrowError::ComputeError(format!("{}: {}", $msg, $param))) }
};
}

Expand Down
30 changes: 15 additions & 15 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ mod tests {
let arr: PrimitiveArray<TimestampMillisecondType> =
TimestampMillisecondArray::from(vec![1546214400000, 1546214400000, -1546214400000]);
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, None)>\n[\n 2018-12-31T00:00:00,\n 2018-12-31T00:00:00,\n 1921-01-02T00:00:00,\n]",
"PrimitiveArray<Timestamp(ms)>\n[\n 2018-12-31T00:00:00,\n 2018-12-31T00:00:00,\n 1921-01-02T00:00:00,\n]",
format!("{arr:?}")
);
}
Expand All @@ -2110,7 +2110,7 @@ mod tests {
TimestampMillisecondArray::from(vec![1546214400000, 1546214400000, -1546214400000])
.with_timezone_utc();
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"+00:00\"))>\n[\n 2018-12-31T00:00:00+00:00,\n 2018-12-31T00:00:00+00:00,\n 1921-01-02T00:00:00+00:00,\n]",
"PrimitiveArray<Timestamp(ms, \"+00:00\")>\n[\n 2018-12-31T00:00:00+00:00,\n 2018-12-31T00:00:00+00:00,\n 1921-01-02T00:00:00+00:00,\n]",
format!("{arr:?}")
);
}
Expand All @@ -2122,7 +2122,7 @@ mod tests {
TimestampMillisecondArray::from(vec![1546214400000, 1546214400000, -1546214400000])
.with_timezone("Asia/Taipei".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"Asia/Taipei\"))>\n[\n 2018-12-31T08:00:00+08:00,\n 2018-12-31T08:00:00+08:00,\n 1921-01-02T08:00:00+08:00,\n]",
"PrimitiveArray<Timestamp(ms, \"Asia/Taipei\")>\n[\n 2018-12-31T08:00:00+08:00,\n 2018-12-31T08:00:00+08:00,\n 1921-01-02T08:00:00+08:00,\n]",
format!("{arr:?}")
);
}
Expand All @@ -2137,7 +2137,7 @@ mod tests {
println!("{arr:?}");

assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"Asia/Taipei\"))>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n]",
"PrimitiveArray<Timestamp(ms, \"Asia/Taipei\")>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n]",
format!("{arr:?}")
);
}
Expand All @@ -2148,7 +2148,7 @@ mod tests {
TimestampMillisecondArray::from(vec![1546214400000, 1546214400000, -1546214400000])
.with_timezone("+08:00".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"+08:00\"))>\n[\n 2018-12-31T08:00:00+08:00,\n 2018-12-31T08:00:00+08:00,\n 1921-01-02T08:00:00+08:00,\n]",
"PrimitiveArray<Timestamp(ms, \"+08:00\")>\n[\n 2018-12-31T08:00:00+08:00,\n 2018-12-31T08:00:00+08:00,\n 1921-01-02T08:00:00+08:00,\n]",
format!("{arr:?}")
);
}
Expand All @@ -2159,7 +2159,7 @@ mod tests {
TimestampMillisecondArray::from(vec![1546214400000, 1546214400000, -1546214400000])
.with_timezone("xxx".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"xxx\"))>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'xxx'),\n]",
"PrimitiveArray<Timestamp(ms, \"xxx\")>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'xxx'),\n]",
format!("{arr:?}")
);
}
Expand All @@ -2175,7 +2175,7 @@ mod tests {
])
.with_timezone("America/Denver".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"America/Denver\"))>\n[\n 2022-03-13T01:59:59-07:00,\n 2022-03-13T03:00:00-06:00,\n 2022-11-06T00:59:59-06:00,\n 2022-11-06T01:00:00-06:00,\n]",
"PrimitiveArray<Timestamp(ms, \"America/Denver\")>\n[\n 2022-03-13T01:59:59-07:00,\n 2022-03-13T03:00:00-06:00,\n 2022-11-06T00:59:59-06:00,\n 2022-11-06T01:00:00-06:00,\n]",
format!("{arr:?}")
);
}
Expand All @@ -2193,7 +2193,7 @@ mod tests {
fn test_time32second_fmt_debug() {
let arr: PrimitiveArray<Time32SecondType> = vec![7201, 60054].into();
assert_eq!(
"PrimitiveArray<Time32(Second)>\n[\n 02:00:01,\n 16:40:54,\n]",
"PrimitiveArray<Time32(s)>\n[\n 02:00:01,\n 16:40:54,\n]",
format!("{arr:?}")
);
}
Expand All @@ -2203,8 +2203,8 @@ mod tests {
// chrono::NaiveDatetime::from_timestamp_opt returns None while input is invalid
let arr: PrimitiveArray<Time32SecondType> = vec![-7201, -60054].into();
assert_eq!(
"PrimitiveArray<Time32(Second)>\n[\n Cast error: Failed to convert -7201 to temporal for Time32(Second),\n Cast error: Failed to convert -60054 to temporal for Time32(Second),\n]",
// "PrimitiveArray<Time32(Second)>\n[\n null,\n null,\n]",
"PrimitiveArray<Time32(s)>\n[\n Cast error: Failed to convert -7201 to temporal for Time32(s),\n Cast error: Failed to convert -60054 to temporal for Time32(s),\n]",
// "PrimitiveArray<Time32(s)>\n[\n null,\n null,\n]",
format!("{arr:?}")
)
}
Expand All @@ -2214,7 +2214,7 @@ mod tests {
// replicate the issue from https://github.com/apache/arrow-datafusion/issues/3832
let arr: PrimitiveArray<TimestampMicrosecondType> = vec![9065525203050843594].into();
assert_eq!(
"PrimitiveArray<Timestamp(Microsecond, None)>\n[\n null,\n]",
"PrimitiveArray<Timestamp(µs)>\n[\n null,\n]",
format!("{arr:?}")
)
}
Expand Down Expand Up @@ -2855,7 +2855,7 @@ mod tests {
]
.into();
let debug_str = format!("{array:?}");
assert_eq!("PrimitiveArray<Time32(Second)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(Second),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400 to temporal for Time32(Second),\n Cast error: Failed to convert 86401 to temporal for Time32(Second),\n null,\n]",
assert_eq!("PrimitiveArray<Time32(s)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(s),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400 to temporal for Time32(s),\n Cast error: Failed to convert 86401 to temporal for Time32(s),\n null,\n]",
debug_str
);
}
Expand All @@ -2872,7 +2872,7 @@ mod tests {
]
.into();
let debug_str = format!("{array:?}");
assert_eq!("PrimitiveArray<Time32(Millisecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(Millisecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000 to temporal for Time32(Millisecond),\n Cast error: Failed to convert 86401000 to temporal for Time32(Millisecond),\n null,\n]",
assert_eq!("PrimitiveArray<Time32(ms)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(ms),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000 to temporal for Time32(ms),\n Cast error: Failed to convert 86401000 to temporal for Time32(ms),\n null,\n]",
debug_str
);
}
Expand All @@ -2890,7 +2890,7 @@ mod tests {
.into();
let debug_str = format!("{array:?}");
assert_eq!(
"PrimitiveArray<Time64(Nanosecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(Nanosecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000000 to temporal for Time64(Nanosecond),\n Cast error: Failed to convert 86401000000000 to temporal for Time64(Nanosecond),\n null,\n]",
"PrimitiveArray<Time64(ns)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(ns),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000000 to temporal for Time64(ns),\n Cast error: Failed to convert 86401000000000 to temporal for Time64(ns),\n null,\n]",
debug_str
);
}
Expand All @@ -2907,7 +2907,7 @@ mod tests {
]
.into();
let debug_str = format!("{array:?}");
assert_eq!("PrimitiveArray<Time64(Microsecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(Microsecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000 to temporal for Time64(Microsecond),\n Cast error: Failed to convert 86401000000 to temporal for Time64(Microsecond),\n null,\n]", debug_str);
assert_eq!("PrimitiveArray<Time64(µs)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(µs),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000 to temporal for Time64(µs),\n Cast error: Failed to convert 86401000000 to temporal for Time64(µs),\n null,\n]", debug_str);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/builder/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ mod tests {

#[test]
#[should_panic(
expected = "Incorrect datatype for StructArray field \\\"timestamp\\\", expected Timestamp(Nanosecond, Some(\\\"UTC\\\")) got Timestamp(Nanosecond, None)"
expected = "Incorrect datatype for StructArray field \\\"timestamp\\\", expected Timestamp(ns, \\\"UTC\\\") got Timestamp(ns)"
)]
fn test_struct_array_mismatch_builder() {
let fields = vec![Field::new(
Expand Down
3 changes: 1 addition & 2 deletions arrow-cast/src/cast/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ where
parse_string_to_decimal_native::<T>(v, scale as usize)
.map_err(|_| {
ArrowError::CastError(format!(
"Cannot cast string '{}' to value of {:?} type",
v,
"Cannot cast string '{v}' to value of {} type",
T::DATA_TYPE,
))
})
Expand Down
22 changes: 17 additions & 5 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4905,7 +4905,10 @@ mod tests {
format_options: FormatOptions::default(),
};
let err = cast_with_options(array, &to_type, &options).unwrap_err();
assert_eq!(err.to_string(), "Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(Second) type");
assert_eq!(
err.to_string(),
"Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(s) type"
);
}
}

Expand Down Expand Up @@ -4947,7 +4950,10 @@ mod tests {
format_options: FormatOptions::default(),
};
let err = cast_with_options(array, &to_type, &options).unwrap_err();
assert_eq!(err.to_string(), "Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(Millisecond) type");
assert_eq!(
err.to_string(),
"Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(ms) type"
);
}
}

Expand Down Expand Up @@ -4981,7 +4987,10 @@ mod tests {
format_options: FormatOptions::default(),
};
let err = cast_with_options(array, &to_type, &options).unwrap_err();
assert_eq!(err.to_string(), "Cast error: Cannot cast string 'Not a valid time' to value of Time64(Microsecond) type");
assert_eq!(
err.to_string(),
"Cast error: Cannot cast string 'Not a valid time' to value of Time64(µs) type"
);
}
}

Expand Down Expand Up @@ -5015,7 +5024,10 @@ mod tests {
format_options: FormatOptions::default(),
};
let err = cast_with_options(array, &to_type, &options).unwrap_err();
assert_eq!(err.to_string(), "Cast error: Cannot cast string 'Not a valid time' to value of Time64(Nanosecond) type");
assert_eq!(
err.to_string(),
"Cast error: Cannot cast string 'Not a valid time' to value of Time64(ns) type"
);
}
}

Expand Down Expand Up @@ -8704,7 +8716,7 @@ mod tests {
};
assert_eq!(
t,
r#"Casting from Map(Field { "entries": Struct(key Utf8, value nullable Interval(DayTime)) }, false) to Map(Field { "entries": Struct(key Utf8, value Duration(Second)) }, true) not supported"#
r#"Casting from Map(Field { "entries": Struct(key Utf8, value nullable Interval(DayTime)) }, false) to Map(Field { "entries": Struct(key Utf8, value Duration(s)) }, true) not supported"#
);
}

Expand Down
3 changes: 1 addition & 2 deletions arrow-cast/src/cast/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ fn parse_string_iter<
.map(|x| match x {
Some(v) => P::parse(v).ok_or_else(|| {
ArrowError::CastError(format!(
"Cannot cast string '{}' to value of {:?} type",
v,
"Cannot cast string '{v}' to value of {} type",
P::DATA_TYPE
))
}),
Expand Down
11 changes: 11 additions & 0 deletions arrow-schema/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ pub enum TimeUnit {
Nanosecond,
}

impl std::fmt::Display for TimeUnit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TimeUnit::Second => write!(f, "s"),
TimeUnit::Millisecond => write!(f, "ms"),
TimeUnit::Microsecond => write!(f, "µs"),
TimeUnit::Nanosecond => write!(f, "ns"),
}
}
}

/// YEAR_MONTH, DAY_TIME, MONTH_DAY_NANO interval in SQL style.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
24 changes: 14 additions & 10 deletions arrow-schema/src/datatype_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ impl fmt::Display for DataType {
Self::Float32 => write!(f, "Float32"),
Self::Float64 => write!(f, "Float64"),
Self::Timestamp(time_unit, timezone) => {
write!(f, "Timestamp({time_unit:?}, {timezone:?})")
if let Some(timezone) = timezone {
write!(f, "Timestamp({time_unit}, {timezone:?})")
} else {
write!(f, "Timestamp({time_unit})")
}
}
Self::Date32 => write!(f, "Date32"),
Self::Date64 => write!(f, "Date64"),
Self::Time32(time_unit) => write!(f, "Time32({time_unit:?})"),
Self::Time64(time_unit) => write!(f, "Time64({time_unit:?})"),
Self::Duration(time_unit) => write!(f, "Duration({time_unit:?})"),
Self::Time32(time_unit) => write!(f, "Time32({time_unit})"),
Self::Time64(time_unit) => write!(f, "Time64({time_unit})"),
Self::Duration(time_unit) => write!(f, "Duration({time_unit})"),
Self::Interval(interval_unit) => write!(f, "Interval({interval_unit:?})"),
Self::Binary => write!(f, "Binary"),
Self::FixedSizeBinary(bytes_per_value) => {
Expand Down Expand Up @@ -131,13 +135,13 @@ impl fmt::Display for DataType {
write!(f, "Union({union_fields:?}, {union_mode:?})")
}
Self::Dictionary(data_type, data_type1) => {
write!(f, "Dictionary({data_type}, {data_type1:?})")
write!(f, "Dictionary({data_type}, {data_type1})")
}
Self::Decimal32(precision, scale) => write!(f, "Decimal32({precision:?}, {scale:?})"),
Self::Decimal64(precision, scale) => write!(f, "Decimal64({precision:?}, {scale:?})"),
Self::Decimal128(precision, scale) => write!(f, "Decimal128({precision:?}, {scale:?})"),
Self::Decimal256(precision, scale) => write!(f, "Decimal256({precision:?}, {scale:?})"),
Self::Map(field, keys_are_sorted) => write!(f, "Map({field}, {keys_are_sorted:?})"),
Self::Decimal32(precision, scale) => write!(f, "Decimal32({precision}, {scale})"),
Self::Decimal64(precision, scale) => write!(f, "Decimal64({precision}, {scale})"),
Self::Decimal128(precision, scale) => write!(f, "Decimal128({precision}, {scale})"),
Self::Decimal256(precision, scale) => write!(f, "Decimal256({precision}, {scale})"),
Self::Map(field, keys_are_sorted) => write!(f, "Map({field}, {keys_are_sorted})"),
Self::RunEndEncoded(run_ends_field, values_field) => {
write!(f, "RunEndEncoded({run_ends_field}, {values_field})")
}
Expand Down
Loading
Loading