Skip to content

Apache DataFusion SQL Query Engine

date_trunc small update for readability (#12479)

Piotr Findeisen5c7721bd768f
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"
+ );
}
})
}