davidradl commented on code in PR #25252:
URL: https://github.com/apache/flink/pull/25252#discussion_r1738474136
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/TimeFunctionsITCase.java:
##########
@@ -734,4 +739,107 @@ private Stream<TestSetSpec> floorTestCases() {
LocalDateTime.of(2001, 1, 1, 0, 0),
TIMESTAMP().nullable()));
}
+
+ private Stream<TestSetSpec> addMonthsTestCases() {
+ return Stream.of(
+ TestSetSpec.forFunction(BuiltInFunctionDefinitions.ADD_MONTHS)
+ .onFieldsWithData(
+ null,
+ LocalDate.of(2024, 7, 31),
+ LocalDateTime.of(2024, 6, 26, 1, 1, 1),
+ Instant.parse("2024-06-26T01:01:01Z"),
+ "2024-06-26 01:01:01")
+ .andDataTypes(DATE(), DATE(), TIMESTAMP(),
TIMESTAMP_LTZ(), STRING())
+ // null input
+ .testResult($("f0").addMonths(1), "ADD_MONTHS(f0, 1)",
null, DATE())
+ .testResult($("f1").addMonths(null), "ADD_MONTHS(f1,
NULL)", null, DATE())
+ // numMonths overflow
+ .testResult(
+ $("f1").addMonths(21474836470L),
+ "ADD_MONTHS(f1, 21474836470)",
+ null,
+ DATE())
+ .testResult(
+ $("f1").addMonths(-21474836470L),
+ "ADD_MONTHS(f1, -21474836470)",
+ null,
+ DATE())
+ // invalid date string
+ .testResult(
+ lit("2024-13-12").addMonths(1),
+ "ADD_MONTHS('2024-13-12', 1)",
+ null,
+ DATE())
+ // result overflow
+ .testResult(
+ $("f1").addMonths(-9999999),
+ "ADD_MONTHS(f1, -9999999)",
+ null,
+ DATE())
+ .testResult(
+ $("f1").addMonths(9999999), "ADD_MONTHS(f1,
9999999)", null, DATE())
+ // input cast
+ .testResult(
+ $("f2").addMonths(2),
+ "ADD_MONTHS(f2, 2)",
+ LocalDate.of(2024, 8, 26),
+ DATE())
+ .testResult(
+ $("f3").addMonths(2),
+ "ADD_MONTHS(f3, 2)",
+ LocalDate.of(2024, 8, 26),
+ DATE())
+ .testResult(
+ $("f4").addMonths(2),
+ "ADD_MONTHS(f4, 2)",
+ LocalDate.of(2024, 8, 26),
+ DATE())
+ // normal
+ .testResult(
+ $("f1").addMonths(2),
+ "ADD_MONTHS(f1, 2)",
+ LocalDate.of(2024, 9, 30),
+ DATE())
+ .testResult(
+ $("f1").addMonths(-2),
+ "ADD_MONTHS(f1, -2)",
+ LocalDate.of(2024, 5, 31),
+ DATE())
+ .testResult(
+ $("f1").addMonths(13),
+ "ADD_MONTHS(f1, 13)",
+ LocalDate.of(2025, 8, 31),
+ DATE())
+ .testResult(
+ $("f1").addMonths(-5),
+ "ADD_MONTHS(f1, -5)",
+ LocalDate.of(2024, 2, 29),
+ DATE())
+ .testResult(
+ $("f1").addMonths(-17),
+ "ADD_MONTHS(f1, -17)",
+ LocalDate.of(2023, 2, 28),
+ DATE())
+ .testResult(
+ $("f1").addMonths(7),
+ "ADD_MONTHS(f1, 7)",
+ LocalDate.of(2025, 2, 28),
+ DATE())
+ .testResult(
+ $("f1").addMonths(-720),
Review Comment:
NIT: Is it worth adding a test around the year 2100 this is not a leap year?
--
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]