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

Double type argument for to_timestamp function #8159

Merged
merged 10 commits into from
Nov 30, 2023
Merged

Conversation

spaydar
Copy link
Contributor

@spaydar spaydar commented Nov 14, 2023

Which issue does this PR close?

Closes #7868.

Rationale for this change

Supports double type argument for to_timestamp function to align with Postgres.

What changes are included in this PR?

This PR adds double type argument for the to_timestamp function, however this function still returns a timestamp type and not a timestamp with time zone type as it does in Postgres because timezone support for to_timestamp*() functions in DataFusion is still an open issue.

Are these changes tested?

Yes, there are sqllogictests for this change

Are there any user-facing changes?

Yes, an additional type is added to the to_timestamp function signature. This change has been added to the User Guide documentation.

@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt) labels Nov 14, 2023
@spaydar
Copy link
Contributor Author

spaydar commented Nov 14, 2023

How can I resolve the one failed check Rust / cargo test datafusion-cli (amd64) (pull_request)? Seems like it failed with a one-off container init issue

@alamb
Copy link
Contributor

alamb commented Nov 16, 2023

How can I resolve the one failed check Rust / cargo test datafusion-cli (amd64) (pull_request)? Seems like it failed with a
one-off container init issue

One trick is to close/reopen the PR

Anther is to merge up to latest master (which will retrigger the PR)

@spaydar spaydar closed this Nov 16, 2023
@spaydar spaydar reopened this Nov 16, 2023
Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

This might be affected by #8193

Thanks @spaydar
Please add tests for cast, ::timestamp as well like in https://github.com/apache/arrow-datafusion/pull/8193/files

all 3 functions should work the same

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

Hi @spaydar any plans to finish this ticket any time soon?

@spaydar
Copy link
Contributor Author

spaydar commented Nov 27, 2023

Hi @spaydar any plans to finish this ticket any time soon?

@comphead Yes, I will finish this soon. Sorry for the delay -- been busy lately

@alamb
Copy link
Contributor

alamb commented Nov 27, 2023

Marking as draft to signify this isn't waiting on feedback anymore. Please mark it as ready for review when it is

@alamb alamb marked this pull request as draft November 27, 2023 22:49
@spaydar spaydar marked this pull request as ready for review November 29, 2023 06:36
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can_cast_types was returning false in my testing yesterday for Float64 -> Timestamp(Nanosecond, None), seemingly because the line you linked has not been released yet. The type check was changed from is_integer to is_numeric only a few days ago, whereas the last arrow-rs release was 3 weeks ago.

Should we wait until the next arrow-rs release so I can leverage this change?

Copy link
Contributor

Choose a reason for hiding this comment

The 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

{
if let ScalarValue::Float64(Some(float_ts)) = scalar {
ScalarValue::Int64(
Some((float_ts * 1_000_000_000_f64).trunc() as i64),
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

Thanks @spaydar for the PR
I think we are really really close.

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm, thanks @spaydar

@comphead
Copy link
Contributor

Filed #8370 I'll pick it up when arrow-rs has released

@alamb alamb merged commit 5c02664 into apache:main Nov 30, 2023
23 checks passed
@alamb
Copy link
Contributor

alamb commented Nov 30, 2023

Thank you @comphead and @spaydar 🦾 Great work

appletreeisyellow pushed a commit to appletreeisyellow/datafusion that referenced this pull request Dec 14, 2023
* feat: test queries for to_timestamp(float) WIP

* feat: Float64 input for to_timestamp

* cargo fmt

* clippy

* docs: double input type for to_timestamp

* feat: cast floats to timestamp

* style: cargo fmt

* fix: float64 cast for timestamp nanos only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support float arguments to to_timestamp function
3 participants