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

[SPARK-51442][SQL] Add time formatters #50190

Closed
wants to merge 9 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Mar 6, 2025

What changes were proposed in this pull request?

In the PR, I propose two new formatters: Iso8601TimeFormatter and FractionTimeFormatter similar to the date or timestamp formatters:

  • The ISO 8601 formatter is capable of formatting and parsing the ISO-8601 extended time format,
  • The fraction formatter is similar to the previous one but does not output trailing zeros in the fraction.

Why are the changes needed?

The datetime formatters are used in CAST and other parsing/formatting expressions.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running new test suite:

$ build/sbt "test:testOnly *TimeFormatterSuite"
$ build/sbt "test:testOnly *TimestampFormatterSuite"

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

No.

@github-actions github-actions bot added the SQL label Mar 6, 2025
@MaxGekk MaxGekk changed the title [WIP][SQL] Add TimeFormatter [WIP][SPARK-51442][SQL] Add time formatters Mar 8, 2025
@MaxGekk MaxGekk changed the title [WIP][SPARK-51442][SQL] Add time formatters [SPARK-51442][SQL] Add time formatters Mar 8, 2025
@MaxGekk MaxGekk marked this pull request as ready for review March 8, 2025 19:58
@MaxGekk
Copy link
Member Author

MaxGekk commented Mar 9, 2025

@LuciferYang @gengliangwang Could you review this PR, please.

Copy link
Contributor

@LuciferYang LuciferYang left a comment

Choose a reason for hiding this comment

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

+1, LGTM
Thanks @MaxGekk

with DateTimeFormatterHelper {

@transient
protected lazy val formatter = getOrCreateFormatter(pattern, locale, isParsing)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for a protected field, readability might be improved if a type declaration could be added.

isParsing = false) {

@transient
override protected lazy val formatter = DateTimeFormatterHelper.fractionTimeFormatter
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -112,4 +112,15 @@ object DateTimeTestUtils {
result = Math.addExact(result, Math.multiplyExact(seconds, MICROS_PER_SECOND))
result
}

// Returns microseconds since midnight
def localtime(
Copy link
Contributor

Choose a reason for hiding this comment

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

def localtime -> def localTime

@MaxGekk
Copy link
Member Author

MaxGekk commented Mar 9, 2025

Merging to master. Thank you, @LuciferYang for review.

@MaxGekk MaxGekk closed this in aab1934 Mar 9, 2025
anoopj pushed a commit to anoopj/spark that referenced this pull request Mar 15, 2025
### What changes were proposed in this pull request?
In the PR, I propose two new formatters: `Iso8601TimeFormatter` and `FractionTimeFormatter` similar to the date or timestamp formatters:
- The ISO 8601 formatter is capable of formatting and parsing the ISO-8601 extended time format,
- The fraction formatter is similar to the previous one but does not output trailing zeros in the fraction.

### Why are the changes needed?
The datetime formatters are used in `CAST` and other parsing/formatting expressions.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By running new test suite:
```
$ build/sbt "test:testOnly *TimeFormatterSuite"
$ build/sbt "test:testOnly *TimestampFormatterSuite"
```

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

Closes apache#50190 from MaxGekk/time-formatter.

Authored-by: Max Gekk <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
kazemaksOG pushed a commit to kazemaksOG/spark-custom-scheduler that referenced this pull request Mar 27, 2025
### What changes were proposed in this pull request?
In the PR, I propose two new formatters: `Iso8601TimeFormatter` and `FractionTimeFormatter` similar to the date or timestamp formatters:
- The ISO 8601 formatter is capable of formatting and parsing the ISO-8601 extended time format,
- The fraction formatter is similar to the previous one but does not output trailing zeros in the fraction.

### Why are the changes needed?
The datetime formatters are used in `CAST` and other parsing/formatting expressions.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By running new test suite:
```
$ build/sbt "test:testOnly *TimeFormatterSuite"
$ build/sbt "test:testOnly *TimestampFormatterSuite"
```

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

Closes apache#50190 from MaxGekk/time-formatter.

Authored-by: Max Gekk <[email protected]>
Signed-off-by: Max Gekk <[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