suibianwanwank commented on code in PR #3936:
URL: https://github.com/apache/calcite/pull/3936#discussion_r1738414575
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5185,6 +5187,61 @@ void testBitGetFunc(SqlOperatorFixture f, String
functionName) {
}
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6551">[CALCITE-6551]
+ * Add DATE_FORMAT function (enabled in MySQL library)</a>. */
+ @Test void testDateFormat() {
+ final SqlOperatorFixture f = fixture()
+ .withTester(t -> TESTER).withLibrary(SqlLibrary.MYSQL);
+ f.setFor(SqlLibraryOperators.DATE_FORMAT);
+ final Locale originalLocale = Locale.getDefault();
+
+ try {
+ Locale.setDefault(Locale.US);
+ f.checkString("date_format(timestamp '2009-10-04 22:23:00', '%W %M %Y')",
+ "Sunday October 2009",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '2009-10-04 22:23:00', '%H:%i:%s')",
+ "22:23:00",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1900-10-04 22:23:00', '%D %y %a %d
%m %b %j')",
+ "4th 00 Thu 04 10 Oct 277",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-10-04 22:23:00', '%H %k %I %r
%T %S %w')",
+ "22 22 10 10:23:00 PM 22:23:00 00 6",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1999-01-01', '%X %V')",
+ "1998 52",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-10-04 22:23:00.000000', '%c
%D %e %f %h')",
+ "10 4th 4 000000 10",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-01-04 22:23:00', '%w %U %u %V
%v %X %x')",
+ "6 00 01 52 01 1996 1997",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-01-05 22:23:00', '%w %U %u %V
%v %X %x')",
+ "0 01 01 01 01 1997 1997",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-01-06 22:23:00', '%w %U %u %V
%v %X %x')",
+ "1 01 02 01 02 1997 1997",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-10-04 22:23:00', '%V %v %X %x
%%')",
+ "39 40 1997 1997 %",
+ "VARCHAR NOT NULL");
+ f.checkString("date_format(timestamp '1997-10-04 22:23:00', '%l %p %U
%u')",
+ "10 PM 39 40",
+ "VARCHAR NOT NULL");
+ f.checkQueryFails(StringAndPos.of("date_format(^timestamp '2006-06-00'^,
'%d')"),
+ "Non-query expression encountered in illegal context");
+ f.checkNull("to_char(timestamp '2022-06-03 12:15:48.678', NULL)");
+// f.checkString("date_format('1999-13-01', '%X %V')",
+// null,
Review Comment:
Yes, implicit cast to timestamp this can be done in calcite, but if this
cast fails, calcite will throw an exception, but for mysql, it will return
null.
This is something that I don't think is easy to implement. unless we add a
Config that adds a Config in the checksum phase and returns NULL if the
implicit cast fails. WDYT
--
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]