jubins commented on code in PR #29948:
URL: https://github.com/apache/flink/pull/29948#discussion_r4610284590
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java:
##########
@@ -809,6 +809,63 @@ private Stream<TestSetSpec> floorTestCases() {
"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()),
+ TestSetSpec.forFunction(BuiltInFunctionDefinitions.FLOOR,
"TIMESTAMP before 1970")
+ // f0 is a Saturday on the last day of a year and f1
the last day of a
+ // quarter, so that rounding toward 1970 moves them to
the next week,
+ // month, quarter and year. f1 and its quarter start
are on the same
+ // side of daylight saving time in most time zones.
+ .onFieldsWithData(
+ LocalDateTime.of(1966, 12, 31, 10, 0),
+ LocalDateTime.of(1966, 9, 30, 10, 0))
+ .andDataTypes(TIMESTAMP(3), TIMESTAMP(3))
+ .testResult(
+ $("f0").floor(TimeIntervalUnit.WEEK),
+ "FLOOR(f0 TO WEEK)",
+ LocalDateTime.of(1966, 12, 25, 0, 0),
+ TIMESTAMP(3).nullable())
+ .testResult(
+ $("f0").floor(TimeIntervalUnit.MONTH),
+ "FLOOR(f0 TO MONTH)",
+ LocalDateTime.of(1966, 12, 1, 0, 0),
+ TIMESTAMP(3).nullable())
+ .testResult(
+ $("f1").floor(TimeIntervalUnit.QUARTER),
+ "FLOOR(f1 TO QUARTER)",
+ LocalDateTime.of(1966, 7, 1, 0, 0),
+ TIMESTAMP(3).nullable())
+ .testResult(
+ $("f0").floor(TimeIntervalUnit.YEAR),
+ "FLOOR(f0 TO YEAR)",
+ LocalDateTime.of(1966, 1, 1, 0, 0),
+ TIMESTAMP(3).nullable())
+ .testResult(
+ $("f0").cast(TIMESTAMP_LTZ(3))
+ .floor(TimeIntervalUnit.WEEK)
+ .cast(STRING()),
+ "CAST(FLOOR(CAST(f0 AS TIMESTAMP_LTZ(3)) TO
WEEK) AS STRING)",
+ LocalDateTime.of(1966, 12, 25, 0,
0).format(TIMESTAMP_FORMATTER),
+ STRING().nullable())
+ .testResult(
+ $("f0").cast(TIMESTAMP_LTZ(3))
+ .floor(TimeIntervalUnit.MONTH)
+ .cast(STRING()),
+ "CAST(FLOOR(CAST(f0 AS TIMESTAMP_LTZ(3)) TO
MONTH) AS STRING)",
+ LocalDateTime.of(1966, 12, 1, 0,
0).format(TIMESTAMP_FORMATTER),
+ STRING().nullable())
+ .testResult(
+ $("f1").cast(TIMESTAMP_LTZ(3))
+ .floor(TimeIntervalUnit.QUARTER)
+ .cast(STRING()),
+ "CAST(FLOOR(CAST(f1 AS TIMESTAMP_LTZ(3)) TO
QUARTER) AS STRING)",
+ LocalDateTime.of(1966, 7, 1, 0,
0).format(TIMESTAMP_FORMATTER),
+ STRING().nullable())
+ .testResult(
+ $("f0").cast(TIMESTAMP_LTZ(3))
+ .floor(TimeIntervalUnit.YEAR)
+ .cast(STRING()),
+ "CAST(FLOOR(CAST(f0 AS TIMESTAMP_LTZ(3)) TO
YEAR) AS STRING)",
Review Comment:
thanks for taking a look @snuyanzin
before the fix, `FLOOR(TIMESTAMP '1966-12-31 10:00:00' TO WEEK)` returned
1967-01-01 instead of 1966-12-25, bcz the epoch day calculation truncated
toward zero for negative values
I've added `DECADE` and `CENTURY` unit tests, which fail without the fix
(1969-12-31 and 1900-12-31). I left out `MILLENNIUM`, as it goes through the
same code, but a case that fails without the fix would need a date in the year
1000, which isn't a useful test.
--
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]