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


##########
site/_docs/reference.md:
##########
@@ -2944,6 +2944,7 @@ In the following:
 | b | TIME_SUB(time, interval)                       | Returns the TIME value 
that is *interval* before *time*
 | b | TIME_TRUNC(time, timeUnit)                     | Truncates *time* to the 
granularity of *timeUnit*, rounding to the beginning of the unit
 | m o p r | TO_CHAR(timestamp, format)               | Converts *timestamp* to 
a string using the format *format*
+| m | DATE_FORMAT(timestamp, format)                 | Converts *timestamp* to 
a string using the format *format*

Review Comment:
   Do DATE-FORMAT and TO_CHAR have the same functional description? Are their 
functions confirmed to be consistent?



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5185,6 +5187,60 @@ 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')",

Review Comment:
   In MySQL,This will throw exception `ERROR 1525 (HY000) at line 1: Incorrect 
DATETIME value: '1994-01-01'`



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

Review Comment:
   > SELECT DATE_FORMAT(timestamp '0000-01-01', '%X %V');
   
   This failed because '0000-01-01' is not a timestamp. You can try:
   ```
   SELECT DATE_FORMAT(data '0000-01-01', '%X %V');
   ```



##########
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:
   We check the results by CalciteSqlOperatorTest. In SqlOperatorTest we check 
the return type.



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