Skip to content

Conversation

@uros-db
Copy link
Contributor

@uros-db uros-db commented Jul 29, 2025

What changes were proposed in this pull request?

Implement the time_diff function, which returns the difference between two times measured in units.

Syntax

time_diff(unit, start, end)

unit
 { MICROSECOND |
   MILLISECOND |
   SECOND |
   MINUTE |
   HOUR }

Arguments

  • unit: A unit of measure.
  • start: A starting TIME expression.
  • end: An ending TIME expression.

Returns
An INTEGER.
If start is greater than end the result is negative.

Why are the changes needed?

Users will be able to calculate time difference in specified units.

Does this PR introduce any user-facing change?

Yes, this PR introduces a new expression.

How was this patch tested?

New unit tests for time truncation, catalyst expression level unit tests with & without codegen, e2e SQL tests / golden files in both ANSI and non-ANSI modes.

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

No.

@github-actions github-actions bot added the SQL label Jul 29, 2025
@uros-db uros-db changed the title [SPARK-51555][SQL] Add the timediff() function [SPARK-51555][SQL] Add the time_diff() function Jul 30, 2025
Copy link
Contributor Author

@uros-db uros-db left a comment

Choose a reason for hiding this comment

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

@cloud-fan Please review.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in b03a869 Jul 31, 2025
cloud-fan pushed a commit that referenced this pull request Aug 4, 2025
…n the time_diff() function

### What changes were proposed in this pull request?
Following up on the original PR that introduces the `time_diff` function (#51715), this PR fixes the error message to include the correct SQL function name.

### Why are the changes needed?
Fix error messages for the `time_diff` function.

### Does this PR introduce _any_ user-facing change?
Changes the error message for the new SQL function.

### How was this patch tested?
Updated relevant scala tests and golden files.

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

Closes #51777 from uros-db/time_diff_FOLLOWUP.

Authored-by: Uros Bojanic <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
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.

2 participants