-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Improve][Transform-V2] SQL transform EXTRACT function support more fields #9342
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
Conversation
Hisoka-X
left a comment
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.
Thanks @CosmosNi ! Please update the doc.
| if (extract.getExpression() instanceof DateTimeLiteralExpression) { | ||
| DateTimeLiteralExpression dateTimeLiteralExpression = | ||
| (DateTimeLiteralExpression) extract.getExpression(); | ||
| String value = dateTimeLiteralExpression.getValue(); | ||
| if (value.startsWith("'") && value.endsWith("'")) { | ||
| value = value.substring(1, value.length() - 1); | ||
| } | ||
| functionArgs.add(LocalDateTime.parse(value)); |
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.
move it to computeForValue
Hisoka-X
left a comment
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.
LGTM if ci passes. Thanks @CosmosNi
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.
Pull Request Overview
This PR enhances the SQL EXTRACT function to support more temporal units (e.g., week, ISO year, epoch, microseconds, millennium) and adds literal parsing for all four datetime types, including timezones.
- Extended
DateTimeFunction.extractwith new cases andOffsetDateTimesupport - Added
computeDateTimeLiteralExpressioninZetaSQLFunctionfor TIMESTAMPTZ - Created
ExtractFunctionTestcovering LocalDateTime, LocalDate, Sunday behavior, and literal expressions - Updated English and Chinese docs to list all supported fields and literal types
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/DateTimeFunction.java | Extend EXTRACT implementation with new units and OffsetDateTime handling |
| seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLFunction.java | Add DateTimeLiteralExpression parsing for TIMESTAMPTZ |
| seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/ExtractFunctionTest.java | New tests for EXTRACT on datetime, date, Sunday, and literals |
| docs/en/transform-v2/sql-functions.md | Document new EXTRACT units and literal support |
| docs/zh/transform-v2/sql-functions.md | Document new EXTRACT units and literal support |
Comments suppressed due to low confidence (3)
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/DateTimeFunction.java:466
- There is no unit test verifying
EXTRACT(WEEK FROM ...). Please add a test case inExtractFunctionTestto cover ISO week extraction.
case "WEEK":
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/DateTimeFunction.java:533
- The new
ISOYEARunit lacks a corresponding test. Add a test inExtractFunctionTestto ensure ISO week-based year extraction is correct.
case "ISOYEAR":
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/DateTimeFunction.java:468
- The code calls
get(...)on thedatetimeobject without casting it to aTemporalAccessorsubtype; this will not compile. CastdatetimetoLocalDate,LocalDateTime, orOffsetDateTime(and extract the date component if needed) before callingget(WeekFields.ISO.weekOfYear()).
return datetime.get(WeekFields.ISO.weekOfYear());
| return date.get(WeekFields.ISO.weekBasedYear()); | ||
| } | ||
| break; | ||
| case "MILLENNIUM": |
Copilot
AI
May 26, 2025
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.
OffsetDateTime is not handled in the MILLENNIUM case. Add an instanceof OffsetDateTime branch similar to other units so timestamptz values can return the correct millennium.
| - `ISOYEAR`: The ISO 8601 week-numbering year | ||
| - `MICROSECONDS`: The seconds field, including fractional parts, multiplied by 1,000,000 | ||
| - `MILLENNIUM`: The millennium; for interval values, the year field divided by 1000 | ||
| - `MILLISECONDS`: The seconds field, including fractional parts, multiplied by 1,000 |
Copilot
AI
May 26, 2025
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.
The docs list the field as MILLISECONDS (plural), but the implementation uses MILLISECOND (singular). Align the documentation with the actual field name or update the code to accept the plural form.
| - `MILLISECONDS`: The seconds field, including fractional parts, multiplied by 1,000 | |
| - `MILLISECOND`: The seconds field, including fractional parts, multiplied by 1,000 |
close #9325
Purpose of this pull request
Does this PR introduce any user-facing change?
How was this patch tested?
Check list
New License Guide