tjbanghart commented on code in PR #2913:
URL: https://github.com/apache/calcite/pull/2913#discussion_r975975647


##########
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##########
@@ -4083,6 +4083,55 @@ void subTestIntervalSecondNegative() {
         .fails("(?s).*Was expecting one of.*");
   }
 
+  @Test void testTimestampTrunc() {
+    List<String> timeUnits = ImmutableList.<String>builder()
+        .add("MINUTE")
+        .add("HOUR")
+        .add("DAY")
+        .add("WEEK")
+        .add("MONTH")
+        .add("QUARTER")
+        .add("YEAR")
+        .add("ISOYEAR")
+        .build();
+
+    final SqlOperatorTable opTable = operatorTableFor(SqlLibrary.BIG_QUERY);
+    String test = "TIMESTAMP_TRUNC(TIMESTAMP '2000-01-01 01:00:00', %s)";
+
+    for (String unit : timeUnits) {
+      wholeExpr(String.format(Locale.ROOT, test, unit))
+          .fails("No match found for function signature "
+              + "TIMESTAMP_TRUNC\\(<TIMESTAMP>,.*\\)");
+      expr(String.format(Locale.ROOT, test, unit))
+          .withOperatorTable(opTable)
+          .columnType("TIMESTAMP(0) NOT NULL");
+    }
+  }
+
+  @Test void testTimeTrunc() {
+    List<String> timeUnits = ImmutableList.<String>builder()
+        .add("MILLISECOND")
+        .add("SECOND")
+        .add("MINUTE")
+        .add("HOUR")
+        .build();
+
+    final SqlOperatorTable opTable = operatorTableFor(SqlLibrary.BIG_QUERY);
+    String test = "TIME_TRUNC(TIME '15:30:00.00', %s)";
+
+    for (String unit : timeUnits) {
+      wholeExpr(String.format(Locale.ROOT, test, unit))
+          .fails("No match found for function signature "
+              + "TIME_TRUNC\\(<TIME>,.*\\)");
+      expr(String.format(Locale.ROOT, test, unit))
+          .withOperatorTable(opTable)
+          .columnType("TIME(0) NOT NULL");
+    }
+    // should fail on incompatible time unit
+    expr("TIME_TRUNC(TIME '15:30:00.00', ^DAY^)")
+        .fails("(?s).*Was expecting one of.*");
+  }
+

Review Comment:
   These can probably be simplified to run a single time unit but they validate 
for an error message if the BigQuery operator table is not used. I can add 
similar check in `SqlOperatorTest` so this file isn't touched.



##########
testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java:
##########
@@ -520,7 +520,9 @@ public class SqlParserTest {
       "TEMPORARY",                     "92", "99",
       "THEN",                          "92", "99", "2003", "2011", "2014", "c",
       "TIME",                          "92", "99", "2003", "2011", "2014", "c",
+      "TIME_TRUNC", // BigQuery

Review Comment:
   This is me following an example commit too closely.



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