Skip to content

Conversation

@CosmosNi
Copy link
Contributor

close #9325

Purpose of this pull request

Does this PR introduce any user-facing change?

How was this patch tested?

Check list

Copy link
Member

@Hisoka-X Hisoka-X left a 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.

@Hisoka-X Hisoka-X changed the title [Improve][transform-V2] SQL transform EXTRACT function support more … [Improve][transform-V2] SQL transform EXTRACT function support more fields May 21, 2025
@Hisoka-X Hisoka-X changed the title [Improve][transform-V2] SQL transform EXTRACT function support more fields [Improve][Transform-V2] SQL transform EXTRACT function support more fields May 21, 2025
Comment on lines 339 to 346
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));
Copy link
Member

Choose a reason for hiding this comment

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

move it to computeForValue

Copy link
Member

@Hisoka-X Hisoka-X left a 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

Copy link
Contributor

Copilot AI left a 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.extract with new cases and OffsetDateTime support
  • Added computeDateTimeLiteralExpression in ZetaSQLFunction for TIMESTAMPTZ
  • Created ExtractFunctionTest covering 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 in ExtractFunctionTest to cover ISO week extraction.
case "WEEK":

seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/DateTimeFunction.java:533

  • The new ISOYEAR unit lacks a corresponding test. Add a test in ExtractFunctionTest to 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 the datetime object without casting it to a TemporalAccessor subtype; this will not compile. Cast datetime to LocalDate, LocalDateTime, or OffsetDateTime (and extract the date component if needed) before calling get(WeekFields.ISO.weekOfYear()).
return datetime.get(WeekFields.ISO.weekOfYear());

return date.get(WeekFields.ISO.weekBasedYear());
}
break;
case "MILLENNIUM":
Copy link

Copilot AI May 26, 2025

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.

Copilot uses AI. Check for mistakes.
- `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
Copy link

Copilot AI May 26, 2025

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.

Suggested change
- `MILLISECONDS`: The seconds field, including fractional parts, multiplied by 1,000
- `MILLISECOND`: The seconds field, including fractional parts, multiplied by 1,000

Copilot uses AI. Check for mistakes.
@hailin0 hailin0 merged commit 5eb6822 into apache:dev May 27, 2025
4 checks passed
dybyte pushed a commit to dybyte/seatunnel that referenced this pull request Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][SQL] SQL transform EXTRACT function support more field

3 participants