This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 5c7721bd76 date_trunc small update for readability (#12479)
5c7721bd76 is described below
commit 5c7721bd768f2e05d14b0c452839aa5aa7f11505
Author: Piotr Findeisen <[email protected]>
AuthorDate: Mon Sep 16 20:31:58 2024 +0200
date_trunc small update for readability (#12479)
* Fix date_trunc error message
It was suggesting only nanosecond timestamps are supported, while all
arrow time units are.
* Remove dead code from date_trunc
`process_array::<TimestampNanosecondType>` can succeed only for an array
that can be downcast to array of nanosecond timestamps, but that case is
explicitly handled earlier.
* Simplify date_trunc time unit switch
Make it clear to the compiler (and the reader) that all time units are
covered.
---
datafusion/functions/src/datetime/date_trunc.rs | 51 +++++++++++++------------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/datafusion/functions/src/datetime/date_trunc.rs
b/datafusion/functions/src/datetime/date_trunc.rs
index 308ea668d3..0ef839c49f 100644
--- a/datafusion/functions/src/datetime/date_trunc.rs
+++ b/datafusion/functions/src/datetime/date_trunc.rs
@@ -189,36 +189,37 @@ impl ScalarUDFImpl for DateTruncFunc {
}
ColumnarValue::Array(array) => {
let array_type = array.data_type();
- match array_type {
- Timestamp(Second, tz_opt) => {
- process_array::<TimestampSecondType>(array,
granularity, tz_opt)?
+ if let Timestamp(unit, tz_opt) = array_type {
+ match unit {
+ Second => process_array::<TimestampSecondType>(
+ array,
+ granularity,
+ tz_opt,
+ )?,
+ Millisecond =>
process_array::<TimestampMillisecondType>(
+ array,
+ granularity,
+ tz_opt,
+ )?,
+ Microsecond =>
process_array::<TimestampMicrosecondType>(
+ array,
+ granularity,
+ tz_opt,
+ )?,
+ Nanosecond => process_array::<TimestampNanosecondType>(
+ array,
+ granularity,
+ tz_opt,
+ )?,
}
- Timestamp(Millisecond, tz_opt) => process_array::<
- TimestampMillisecondType,
- >(
- array, granularity, tz_opt
- )?,
- Timestamp(Microsecond, tz_opt) => process_array::<
- TimestampMicrosecondType,
- >(
- array, granularity, tz_opt
- )?,
- Timestamp(Nanosecond, tz_opt) => process_array::<
- TimestampNanosecondType,
- >(
- array, granularity, tz_opt
- )?,
- _ => process_array::<TimestampNanosecondType>(
- array,
- granularity,
- &None,
- )?,
+ } else {
+ return exec_err!("second argument of `date_trunc` is an
unsupported array type: {array_type}");
}
}
_ => {
return exec_err!(
- "second argument of `date_trunc` must be nanosecond timestamp
scalar or array"
- );
+ "second argument of `date_trunc` must be timestamp scalar
or array"
+ );
}
})
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]