Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.3k
Double type argument for to_timestamp function#8159
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c964a2f34c72b99256de4e489e93c784ca961fbfdad5c908c340688f7fdb7e455ffc5cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -176,7 +176,20 @@ pub fn cast_column( | ||
| kernels::cast::cast_with_options(array, cast_type, &cast_options)?, | ||
| )), | ||
| ColumnarValue::Scalar(scalar) => { | ||
| let scalar_array = scalar.to_array()?; | ||
| let scalar_array = if cast_type | ||
| == &DataType::Timestamp(arrow_schema::TimeUnit::Nanosecond, None) | ||
| { | ||
| if let ScalarValue::Float64(Some(float_ts)) = scalar { | ||
| ScalarValue::Int64( | ||
| Some((float_ts * 1_000_000_000_f64).trunc() as i64), | ||
| ) | ||
| .to_array()? | ||
| } else { | ||
| scalar.to_array()? | ||
| } | ||
| } else { | ||
| scalar.to_array()? | ||
| }; | ||
| let cast_array = kernels::cast::cast_with_options( | ||
| &scalar_array, | ||
| cast_type, | ||
| @@ -201,7 +214,10 @@ pub fn cast_with_options( | ||
| let expr_type = expr.data_type(input_schema)?; | ||
| if expr_type == cast_type { | ||
| Ok(expr.clone()) | ||
| } else if can_cast_types(&expr_type, &cast_type) { | ||
| } else if can_cast_types(&expr_type, &cast_type) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to have a followup PR in arrow-rs, I'll do it ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if this can be pushed down to the arrow crate, the complexity in datafusion would be reduced. I wasn't sure if doing so was appropriate Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just checked arrow-rs so such cast is supported https://github.com/apache/arrow-rs/blob/master/arrow-cast/src/cast.rs#L224 ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should we wait until the next arrow-rs release so I can leverage this change? Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay to let it go, because this is important piece. I'll create a followup issue to move to arrow-rs cast and small other refactoring. Thanks @spaydar for your work | ||
| || (expr_type == DataType::Float64 | ||
| && cast_type == DataType::Timestamp(arrow_schema::TimeUnit::Nanosecond, None)) | ||
| { | ||
| Ok(Arc::new(CastExpr::new(expr, cast_type, cast_options))) | ||
| } else { | ||
| not_impl_err!("Unsupported CAST from {expr_type:?} to {cast_type:?}") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here complexity can be reduced. too many conditions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are allowing this type cast to be pushed down to the arrow crate, then I can add this logic to
kernel::compute::cast_with_optionsor the appropriate fn