Skip to content

[SPARK-52656][SQL] Fix current_time() #51351

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Jul 2, 2025

What changes were proposed in this pull request?

After switching of internal representation of TIME values from microseconds to nanoseconds by the PR #51156, the current_time(p) returns incorrect result. In the PR, I propose to fix two datetime functions truncateTimeToPrecision() and instantToNanosOfDay(), and apparently the expression CurrentTime.

Why are the changes needed?

It fixes incorrect behaviour of the current_time() function.

Does this PR introduce any user-facing change?

No, the TIME data type and related functions haven't been released yet.

How was this patch tested?

By running new tests:

$ build/sbt "test:testOnly *DateTimeUtilsSuite"
$ build/sbt "test:testOnly *ComputeCurrentTimeSuite"

and by manual testing:

spark-sql (default)> SELECT current_time(2);
00:01:12.24

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Jul 2, 2025
@MaxGekk MaxGekk changed the title [WIP][SQL] Fix truncation of TIME values to the given precision [WIP][SPARK-52656][SQL] Fix truncation of TIME values to the given precision Jul 2, 2025
@MaxGekk MaxGekk changed the title [WIP][SPARK-52656][SQL] Fix truncation of TIME values to the given precision [WIP][SPARK-52656][SQL] Fix current_time() Jul 2, 2025
@MaxGekk MaxGekk changed the title [WIP][SPARK-52656][SQL] Fix current_time() [SPARK-52656][SQL] Fix current_time() Jul 2, 2025
@MaxGekk MaxGekk marked this pull request as ready for review July 2, 2025 21:34
@MaxGekk MaxGekk requested a review from cloud-fan July 2, 2025 21:34
@MaxGekk
Copy link
Member Author

MaxGekk commented Jul 2, 2025

@cloud-fan @the-sakthi Could you review this bug fix, please.

@MaxGekk
Copy link
Member Author

MaxGekk commented Jul 3, 2025

@dongjoon-hyun @LuciferYang Could you review this PR, please.

*
* For example, if `p = 3`, we keep millisecond resolution and discard any digits beyond the
* thousand-microsecond place. So a value like `123456` microseconds (12:34:56.123456) becomes
* thousand-nanosecond place. So a value like `123456` microseconds (12:34:56.123456) becomes
Copy link
Contributor

Choose a reason for hiding this comment

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

So a value like `123456` microseconds (12:34:56.123456) becomes
   * `123000` microseconds (12:34:56.123).

Is it still "microseconds" in this comment? Is that correct?

@the-sakthi
Copy link
Member

Lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants