suibianwanwank commented on code in PR #3936:
URL: https://github.com/apache/calcite/pull/3936#discussion_r1734965576


##########
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:
   MySQL supports this writing and will return null if the timestamp type is 
not declared and the parameter does not satisfy the timestamp format, which 
seems to be difficult to do in calcite



##########
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')",

Review Comment:
   Here are 4 cases testing mysql's weekForYear in two modes.
   https://stackoverflow.com/questions/30364141/mysql-convert-yearweek-to-date



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -4919,7 +4920,8 @@ void testBitGetFunc(SqlOperatorFixture f, String 
functionName) {
   }
 
   @Test void testToCharPg() {
-    final SqlOperatorFixture f = fixture().withLibrary(SqlLibrary.POSTGRESQL);

Review Comment:
   I noticed that the default tester doesn't check the results, so I added this.



-- 
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]

Reply via email to