-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
[FLINK-35241][table]Support SQL FLOOR and CEIL functions with SECOND and MINUTE for TIMESTAMP_TLZ #25759
Conversation
df6a968
to
b498656
Compare
@flinkbot run azure |
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
Is there any documentation for this function? If it mentions details, we may need to update them. |
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
@flinkbot run azure |
104f37c
to
63ce219
Compare
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.
Tested locally
if I floor
/ceil
to millisecond
/nanosecond
I still receive same issue as in jira description
@snuyanzin Yes, because this ticket just handle the SECOND and MINUTE case. |
the root cause is same, if you compare output for different inputs, it will be same. |
@snuyanzin
for DAY and HOUR now base on
We can use 1L to stand for MILLIS_PER_MILLISECOND, but how can we stand for NANOSECOND, it is smaller than MILLISECOND. If we want to support it, we need change the time base from MILLISECOND to NANOSECOND, it will change lots of behavior for ceil and floor, so I suggest to generate an new ticket to support |
At least we have to support it for all timeunits for which we have already existing tests Lines 449 to 458 in 72b32fc
then same should be supported for case with cast as well. If there is no such for |
Support |
I will have a look at this tomorrow |
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
I will open an jira ticket for it |
Create an apache flink jira ticket to handle rest issue: https://issues.apache.org/jira/browse/FLINK-36898 |
7d7e77b
to
949ba81
Compare
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
Reviewed by Chi on 12/12/24. appears that this PR is healthily progressing |
744f4d7
to
0cfaa8e
Compare
Reviewed by Chi on 12/12/24. appears that this PR is healthily progressing |
a5294e4
to
8aa5a90
Compare
@flinkbot run azure |
@snuyanzin can I get an another code review, thank you. |
} | ||
|
||
private static String formatAsTimestamp(LocalDateTime dateTime) { | ||
return dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSS")); |
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.
One last comment
extract this into a separate constant
DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSS")
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.
Thank you for your suggestion. I have a question: if we extract DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSS")
as a separate constant, should we still keep the formatAsTimestamp
method?
For example, is it better to write:
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSS");
private static String formatAsTimestamp(LocalDateTime dateTime) {
return dateTime.format(TIMESTAMP_FORMATTER);
}
.testResult(
$("f2").cast(TIMESTAMP_LTZ(3))
.floor(TimeIntervalUnit.MILLISECOND)
.cast(STRING()),
"CAST(FLOOR(CAST(f2 AS TIMESTAMP_LTZ(3)) TO MILLISECOND) AS STRING)",
formatAsTimestamp(
LocalDateTime.of(2020, 2, 29, 1, 56, 59, 987_000_000)
),
STRING().nullable()
);
Or should we directly use TIMESTAMP_FORMATTER like this:
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSS");
.testResult(
$("f2").cast(TIMESTAMP_LTZ(3))
.floor(TimeIntervalUnit.MILLISECOND)
.cast(STRING()),
"CAST(FLOOR(CAST(f2 AS TIMESTAMP_LTZ(3)) TO MILLISECOND) AS STRING)",
LocalDateTime.of(2020, 2, 29, 1, 56, 59, 987_000_000)
.format(TIMESTAMP_FORMATTER),
STRING().nullable()
);
However, I prefer a third approach: passing DateTimeFormatter as a parameter to the formatAsTimestamp method. This keeps the method flexible and reusable while encapsulating the formatting logic. For example:
private static String formatAsTimestamp(LocalDateTime dateTime, DateTimeFormatter formatter) {
return dateTime.format(formatter);
}
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSS");
.testResult(
$("f2").cast(TIMESTAMP_LTZ(3))
.floor(TimeIntervalUnit.MILLISECOND)
.cast(STRING()),
"CAST(FLOOR(CAST(f2 AS TIMESTAMP_LTZ(3)) TO MILLISECOND) AS STRING)",
formatAsTimestamp(
LocalDateTime.of(2020, 2, 29, 1, 56, 59, 987_000_000),
TIMESTAMP_FORMATTER
),
STRING().nullable()
);
This approach offers better flexibility, as it allows us to use different formatters for varying requirements without needing to redefine the logic. It also makes the code more extensible for future changes.
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.
Yep, I think we could go without this method
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.
ok
…and MINUTE for TIMESTAMP_TLZ
dfb1026
to
c6ad86f
Compare
What is the purpose of the change
We need a fix for both SECOND and MINUTE.
The following query doesn't work:
These two queries work:
Stack trace for the first not working query from above:
Brief change log
(for example:)
Verifying this change
TimeFunctionsITCase
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (yes / no)Documentation