caicancai commented on code in PR #3915:
URL: https://github.com/apache/calcite/pull/3915#discussion_r1722599804
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -13824,6 +13824,63 @@ void testTimestampDiff(boolean coercionEnabled) {
f.checkNull("date_add(CAST(NULL AS DATE), interval 5 day)");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6527">[CALCITE-6527]
+ * Add DATE_ADD function (enabled in Spark library)</a>.
+ */
+ @Test void testDateAddSpark() {
+ final SqlOperatorFixture f0 = fixture()
+ .setFor(SqlLibraryOperators.DATE_ADD_SPARK);
+ f0.checkFails("^date_add(date '2008-12-25', "
+ + "5)^",
+ "No match found for function signature "
+ + "DATE_ADD\\(<DATE>, <NUMERIC>\\)", false);
+
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+ f.checkScalar("date_add(date '2016-02-22', 2)",
+ "2016-02-24",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '2016-02-28', 2)",
+ "2016-03-01",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '2016-03-01', -2)",
+ "2016-02-28",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '2016-03-01', -2)",
+ "2016-02-28",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '2016-03-01', -2.0)",
+ "2016-02-28",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '2016-02-28', 2.0)",
+ "2016-03-01",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '2016-02-28', '2.0')",
+ "2016-03-01",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(timestamp '2016-02-22 13:00:01', '-2.0')",
+ "2016-02-20",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(timestamp '2016-02-22 13:00:01', -2)",
+ "2016-02-20",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(timestamp '2016-02-22 13:00:01', -2.0)",
+ "2016-02-20",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '0001-01-01', '-2.0')",
+ "0000-12-30",
+ "DATE NOT NULL");
+ f.checkScalar("date_add(date '0001-01-01', '-367')",
Review Comment:
> If a test passes that shouldn't it means that there's somewhere another
bug that is masking a problem.
agree.
I will fix it, the date function does validation when it handles 000/or 0000
as a parameter, but when 000/or 0000 is returned as a result, no such
validation is done, I think this is the bug
--
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]