Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return correct scalar types for date_trunc #6638

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Changes from 1 commit
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
22 changes: 11 additions & 11 deletions datafusion/physical-expr/src/datetime_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,31 +285,31 @@ pub fn date_trunc(args: &[ColumnarValue]) -> Result<ColumnarValue> {
let nano = (f)(*v)?;
match granularity.as_str() {
"minute" => {
// cast to second
let second = ScalarValue::TimestampSecond(
Some(nano.unwrap() / 1_000_000_000),
// trunc to minute
let second = ScalarValue::TimestampNanosecond(
Some(nano.unwrap() / 1_000_000_000 * 1_000_000_000),
tz_opt.clone(),
);
ColumnarValue::Scalar(second)
}
"second" => {
// cast to millisecond
let mill = ScalarValue::TimestampMillisecond(
Some(nano.unwrap() / 1_000_000),
// trunc to second
let mill = ScalarValue::TimestampNanosecond(
Some(nano.unwrap() / 1_000_000 * 1_000_000),
tz_opt.clone(),
);
ColumnarValue::Scalar(mill)
}
"millisecond" => {
// cast to microsecond
let micro = ScalarValue::TimestampMicrosecond(
Some(nano.unwrap() / 1_000),
// trunc to microsecond
let micro = ScalarValue::TimestampNanosecond(
Some(nano.unwrap() / 1_000 * 1_000),
tz_opt.clone(),
);
ColumnarValue::Scalar(micro)
}
_ => {
// cast to nanosecond
// trunc to nanosecond
let nano = ScalarValue::TimestampNanosecond(
Some(nano.unwrap()),
tz_opt.clone(),
Expand All @@ -329,7 +329,7 @@ pub fn date_trunc(args: &[ColumnarValue]) -> Result<ColumnarValue> {
}
_ => {
return Err(DataFusionError::Execution(
"array of `date_trunc` must be non-null scalar Utf8".to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message also doesn't read correctly.

"second argument of `date_trunc` must be nanosecond timestamp scalar or array".to_string(),
));
}
})
Expand Down