-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Double type argument for to_timestamp function #8159
Changes from all commits
c964a2f
34c72b9
9256de4
e489e93
c784ca9
61fbfda
d5c908c
340688f
7fdb7e4
55ffc5c
File filter
Filter by extension
Conversations
Jump to
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) | ||
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 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 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 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? 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_options
or the appropriate fn