twdsilva commented on code in PR #2876:
URL: https://github.com/apache/calcite/pull/2876#discussion_r1038666571


##########
core/src/test/java/org/apache/calcite/rex/RexProgramTest.java:
##########
@@ -3027,6 +3028,43 @@ private void checkSarg(String message, Sarg sarg,
         is(false));
   }
 
+  private void helpTestFloorCeil(String timestampString, String 
expectedFloorString,
+      String expectedCeilString, TimeUnitRange timeUnitRange) {
+    final RexLiteral timestampLiteral = rexBuilder.makeTimestampLiteral(
+        new TimestampString(timestampString), 3);
+    final RexLiteral flagLiteral = rexBuilder.makeFlag(timeUnitRange);
+
+    RexNode flooredLiteral = rexBuilder.makeCall(SqlStdOperatorTable.FLOOR,
+        ImmutableList.of(timestampLiteral, flagLiteral));
+    long expectedFloorValue = new 
TimestampString(expectedFloorString).getMillisSinceEpoch();
+    assertThat(eval(flooredLiteral), is(expectedFloorValue));
+
+    RexNode ceiledLiteral = rexBuilder.makeCall(SqlStdOperatorTable.CEIL,
+        ImmutableList.of(timestampLiteral, flagLiteral));
+    long expectedCeiledFloorValue = new 
TimestampString(expectedCeilString).getMillisSinceEpoch();
+    assertThat(eval(ceiledLiteral), is(expectedCeiledFloorValue));
+  }
+
+  @Test void testInterpreterFloorCeil() {
+    String timestampString = "2011-07-20 12:34:18.078";
+    helpTestFloorCeil(timestampString, "2011-07-20 12:34:18", "2011-07-20 
12:34:19",
+        TimeUnitRange.SECOND);
+    helpTestFloorCeil(timestampString, "2011-07-20 12:34:00", "2011-07-20 
12:35:00",
+        TimeUnitRange.MINUTE);
+    helpTestFloorCeil(timestampString, "2011-07-20 12:00:00", "2011-07-20 
13:00:00",
+        TimeUnitRange.HOUR);
+    helpTestFloorCeil(timestampString, "2011-07-20 00:00:00", "2011-07-21 
00:00:00",
+        TimeUnitRange.DAY);
+    helpTestFloorCeil("2011-07-20 12:34:59.078", "2011-07-17 00:00:00", 
"2011-07-24 00:00:00",

Review Comment:
   From the comment on CALCITE-3412 I think `FLOOR(timestamp TO WEEK)` will 
always round down to the previous Sunday. 
   
https://issues.apache.org/jira/browse/CALCITE-3412?focusedCommentId=16953504&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16953504



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