hanyuzheng7 commented on code in PR #25897:
URL: https://github.com/apache/flink/pull/25897#discussion_r1906221025
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/FloorCeilCallGen.scala:
##########
@@ -65,15 +65,17 @@ class FloorCeilCallGen(
unit match {
// for Timestamp with timezone info
case MILLENNIUM | CENTURY | DECADE | YEAR | QUARTER | MONTH | WEEK
| DAY | HOUR |
- MINUTE | SECOND | MILLISECOND
- if terms.length + 1 == method.getParameterCount &&
- method.getParameterTypes()(terms.length) ==
classOf[TimeZone] =>
+ MINUTE | SECOND | MILLISECOND | MICROSECOND | NANOSECOND
+ if terms.length + 2 == method.getParameterCount &&
+ method.getParameterTypes()(terms.length + 1) ==
classOf[TimeZone] =>
val timeZone = ctx.addReusableSessionTimeZone()
val longTerm = s"${terms.head}.getMillisecond()"
+ val nanosTerm = s"${terms.head}.getNanoOfMillisecond()"
s"""
|$TIMESTAMP_DATA.fromEpochMillis(
Review Comment:
You can see here, the precision of
[fromEpochMillis](https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/TimestampData.java#L41)
is millis, so the functions `timestampFloor` and `timestampCeil` will return
the time which precision is millis.
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java:
##########
@@ -588,34 +588,50 @@ private Stream<TestSetSpec> ceilTestCases() {
LocalDateTime.of(3001, 1, 1, 0, 0),
TIMESTAMP().nullable())
.testResult(
- $("f3").cast(TIMESTAMP_LTZ(3))
+ $("f3").cast(TIMESTAMP_LTZ(4))
.ceil(TimeIntervalUnit.HOUR)
.cast(STRING()),
- "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(3)) TO
HOUR) AS STRING)",
+ "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(4)) TO
HOUR) AS STRING)",
LocalDateTime.of(2021, 9, 24, 10, 0, 0, 0)
.format(TIMESTAMP_FORMATTER),
STRING().nullable())
.testResult(
- $("f3").cast(TIMESTAMP_LTZ(3))
+ $("f3").cast(TIMESTAMP_LTZ(4))
.ceil(TimeIntervalUnit.MINUTE)
.cast(STRING()),
- "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(3)) TO
MINUTE) AS STRING)",
+ "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(4)) TO
MINUTE) AS STRING)",
LocalDateTime.of(2021, 9, 24, 9, 21, 0, 0)
.format(TIMESTAMP_FORMATTER),
STRING().nullable())
.testResult(
- $("f3").cast(TIMESTAMP_LTZ(3))
+ $("f3").cast(TIMESTAMP_LTZ(4))
.ceil(TimeIntervalUnit.SECOND)
.cast(STRING()),
- "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(3)) TO
SECOND) AS STRING)",
+ "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(4)) TO
SECOND) AS STRING)",
LocalDateTime.of(2021, 9, 24, 9, 20, 51, 0)
.format(TIMESTAMP_FORMATTER),
STRING().nullable())
.testResult(
- $("f3").cast(TIMESTAMP_LTZ(3))
+ $("f3").cast(TIMESTAMP_LTZ(4))
.ceil(TimeIntervalUnit.MILLISECOND)
.cast(STRING()),
- "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(3)) TO
MILLISECOND) AS STRING)",
+ "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(4)) TO
MILLISECOND) AS STRING)",
+ LocalDateTime.of(2021, 9, 24, 9, 20, 50,
925_000_000)
+ .format(TIMESTAMP_FORMATTER),
+ STRING().nullable())
+ .testResult(
+ $("f3").cast(TIMESTAMP_LTZ(4))
+ .ceil(TimeIntervalUnit.MICROSECOND)
+ .cast(STRING()),
+ "CAST(CEIL(CAST(f3 AS TIMESTAMP_LTZ(4)) TO
MICROSECOND) AS STRING)",
+ LocalDateTime.of(2021, 9, 24, 9, 20, 50,
924_000_000)
+ .format(TIMESTAMP_FORMATTER),
Review Comment:
Because of this reason
https://github.com/apache/flink/pull/25897#discussion_r1906221025,
if I change the TIMESTAMP_FORMATTER from
`DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSSS")`; to
`DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss.SSSSSSSSS")`; the result is
same `LocalDateTime.of(2021, 9, 24, 9, 20, 50, 924_000_000)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]