-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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-36862][table] Implement additional TO_TIMESTAMP_LTZ() functions #25763
base: master
Are you sure you want to change the base?
Conversation
...able-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java
Outdated
Show resolved
Hide resolved
...-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java
Outdated
Show resolved
Hide resolved
...me/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java
Outdated
Show resolved
Hide resolved
...me/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java
Outdated
Show resolved
Hide resolved
bd3ff92
to
77a36af
Compare
1936203
to
0bf526d
Compare
0bf526d
to
750f965
Compare
...le-planner/src/test/scala/org/apache/flink/table/planner/expressions/TemporalTypesTest.scala
Outdated
Show resolved
Hide resolved
...me/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java
Outdated
Show resolved
Hide resolved
...me/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java
Outdated
Show resolved
Hide resolved
return DateTimeUtils.toTimestampData(epoch, precision); | ||
} | ||
|
||
public TimestampData eval(Double epoch, Integer precision) { |
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.
This I didn't get, why do we have anything with floating point here?
Can you please clarify
first what does fractional epoch actually means? Does any vendor support it?
Second floating points have issues with exact data
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.
Hi Sergey, they are for existing tests like:
Line 1159 in 2d9fb79
toTimestampLtz(100.01.cast(DataTypes.FLOAT()), 0), |
public TimestampData eval(Float value, Integer precision) { | ||
if (value == null || precision == null) { | ||
return null; | ||
} | ||
return DateTimeUtils.toTimestampData(value.longValue(), precision); | ||
} | ||
|
||
public TimestampData eval(Byte value, Integer precision) { | ||
if (value == null || precision == null) { | ||
return null; | ||
} | ||
return DateTimeUtils.toTimestampData(value.longValue(), precision); | ||
} | ||
|
||
public TimestampData eval(DecimalData epoch, Integer precision) { | ||
if (epoch == null || precision == null) { | ||
return null; | ||
} | ||
|
||
return DateTimeUtils.toTimestampData(epoch, precision); | ||
} |
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.
We need only numeric (exact numeric)
or did I miss anything?
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.
same as above
.../main/java/org/apache/flink/table/types/inference/strategies/ToTimestampLtzTypeStrategy.java
Outdated
Show resolved
Hide resolved
.../main/java/org/apache/flink/table/types/inference/strategies/ToTimestampLtzTypeStrategy.java
Outdated
Show resolved
Hide resolved
.../main/java/org/apache/flink/table/types/inference/strategies/ToTimestampLtzTypeStrategy.java
Show resolved
Hide resolved
public static TimestampData toTimestampData(long epoch) { | ||
return toTimestampData(epoch, 3); | ||
} | ||
|
||
public static TimestampData toTimestampData(double epoch) { | ||
return toTimestampData(epoch, 3); | ||
} | ||
|
||
public static TimestampData toTimestampData(DecimalData epoch) { | ||
return toTimestampData(epoch, 3); | ||
} | ||
|
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.
from any user outside of TO_TIMESTAMP_LTZ
3 here is a magic number.
I would suggest to have such calls only in your toTimestampLtzFunction class and don't put them here
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.
addressed here: 5335325#r1886093369
...me/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java
Outdated
Show resolved
Hide resolved
public TimestampData eval(Long epoch) { | ||
if (epoch == null) { | ||
return null; | ||
} | ||
|
||
return eval(epoch, 3); | ||
} | ||
|
||
public TimestampData eval(Float epoch) { | ||
if (epoch == null) { | ||
return null; | ||
} | ||
|
||
return eval(epoch, 3); | ||
} |
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.
Can not we replace a number of these duplicating methods with something like
public TimestampData eval(Number epoch) {
if (epoch == null) {
return null;
}
return eval(epoch, 3);
}
?
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.
Address here: 5335325#r1886090826
...me/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java
Outdated
Show resolved
Hide resolved
408214d
to
497f3a0
Compare
@flinkbot run azure |
497f3a0
to
afbf75f
Compare
Reviewed by Chi on 12/12/24 Group to test and/or review outside of the meeting (Nic Townsend from IBM has some insight he will add on this) |
@@ -1158,7 +1157,7 @@ class TemporalTypesTest extends ExpressionTestBase { | |||
testAllApis( | |||
toTimestampLtz(100.01.cast(DataTypes.FLOAT()), 0), | |||
"TO_TIMESTAMP_LTZ(CAST(100.01 AS FLOAT), 0)", | |||
"1970-01-01 08:01:40.010") | |||
"1970-01-01 08:01:40.000") |
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.
why is it like that?
why are we missing millis now?
Or are we casting to timestamp with precision zero?
If so, do we have a similar test with cast to timestamp with precision 3?
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.
Hi @snuyanzin, the 010 is the original test case. I reverted it back to 010 and the test passes now.
I added a precision with 3 in the new Java test.
afbf75f
to
5335325
Compare
@@ -2332,7 +2332,8 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL) | |||
|
|||
public static final BuiltInFunctionDefinition TO_TIMESTAMP_LTZ = | |||
BuiltInFunctionDefinition.newBuilder() | |||
.name("TO_TIMESTAMP_LTZ") | |||
.name("toTimestampLtz") | |||
.sqlName("TO_TIMESTAMP_LTZ") |
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.
Reverted the change of function name. Added necessary logic register the function.
TIMESTAMP_LTZ(0).nullable()) | ||
null, | ||
TIMESTAMP_LTZ(3).nullable()) | ||
.testResult( |
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.
To address this comment, added a FLOAT case with precision 3.
|
||
// FLOAT -> TIMESTAMP_LTZ | ||
testAllApis( | ||
toTimestampLtz(100.01.cast(DataTypes.FLOAT()), 0), | ||
"TO_TIMESTAMP_LTZ(CAST(100.01 AS FLOAT), 0)", | ||
"1970-01-01 08:01:40") | ||
"1970-01-01 08:01:40.010") |
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.
Revert to the original test case.
"Cannot apply 'TO_TIMESTAMP_LTZ' to arguments of type" + | ||
" 'TO_TIMESTAMP_LTZ(<CHAR(16)>, <INTEGER>)'. Supported form(s):" + | ||
" 'TO_TIMESTAMP_LTZ(<NUMERIC>, <INTEGER>)'", | ||
"SQL validation failed. From line 1, column 8 to line 1, column 46: Cannot apply " + |
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.
Need to change these existing scala tests, because I changed the function signature. The change reflects the expected function behaviors.
@@ -92,74 +121,72 @@ public TimestampData eval(Integer epoch) { | |||
return null; | |||
} | |||
|
|||
return eval(epoch, 3); |
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.
Replying to this comment:
This is not possible, because we handle exact numeric and fractional data differently. Therefore, we can’t use the umbrella Number for them.
I keep them as is to be consistent with existing logic.
@snuyanzin , if you have a better way, please shed some lights here.
Can not we replace a number of these duplicating methods with something like
public TimestampData eval(Number epoch) { if (epoch == null) { return null; } return eval(epoch, 3); }
@@ -385,6 +388,18 @@ public static TimestampData toTimestampData(int v, int precision) { | |||
} | |||
} | |||
|
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.
To address this comment, I replaced 3 with a constant.
After giving it some thought, I believe it's better to keep these functions in DateTimeUtils.java rather than moving them to toTimestampLtzFunction, since toTimestampLtzFunction already depends on DateTimeUtils.java as a library. What are your thoughts on this? @snuyanzin
from any user outside of TO_TIMESTAMP_LTZ 3 here is a magic number.
I would suggest to have such calls only in your toTimestampLtzFunction class and don't put them here
Hi @davidradl, I appreciate your involvement with this PR. As a new member to this community, this means a lot to me! I've also just submitted another commit to address the previous comments, added tests, and made other updates, which may have rendered some of your current feedback outdated. Given the time constraints, can I proceed with the Flink committer's approval, and address your comments in a separate PR? |
5335325
to
5a6f93c
Compare
What is the purpose of the change
The Flink TO_TIMESTAMP_LTZ is lacking some behaviors, compared with other vendors. eg. https://docs.snowflake.com/en/sql-reference/functions/to_timestamp
This PR adds the following additional functions for TO_TIMESTAMP_LTZ.
Brief change log
Verifying this change
This change is already covered by existing tests,
TemporalTypesTest.scala
.Added additional tests in
TimeFunctionsITCase.java
.Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation