xuzifu666 commented on code in PR #4966:
URL: https://github.com/apache/calcite/pull/4966#discussion_r3295798765
##########
core/src/test/java/org/apache/calcite/test/RexImplicationCheckerTest.java:
##########
@@ -556,4 +556,101 @@ public class RexImplicationCheckerTest {
}
}
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7304">[CALCITE-7304]
+ * Floor/Ceil can not simplify with WEEK TimeUnit</a>. */
+ @Test void testSimplifyCeilFloorWeek() {
+ final Fixture f = new Fixture();
+ // RexInterpreter does not support WEEK and DAY, so we disable paranoid
+ // verification for this test.
+ final RexSimplify nonParanoidSimplify = f.simplify.withParanoid(false);
+ final RexNode literalTs =
+ f.timestampLiteral(new TimestampString("2010-10-10 00:00:00"));
+
+ // Positive tests: floor(floor(x, inner), WEEK) -> floor(x, WEEK)
+ // when inner is DAY or finer.
+ for (TimeUnitRange innerRange : ImmutableList.of(
+ TimeUnitRange.WEEK, TimeUnitRange.DAY)) {
+ final RexNode innerFloorCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.FLOOR, literalTs,
+ f.rexBuilder.makeFlag(innerRange));
+ final RexNode innerCeilCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.CEIL, literalTs,
+ f.rexBuilder.makeFlag(innerRange));
+ final RexNode outerFloorCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.FLOOR, innerFloorCall,
+ f.rexBuilder.makeFlag(TimeUnitRange.WEEK));
+ final RexNode outerCeilCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.CEIL, innerCeilCall,
+ f.rexBuilder.makeFlag(TimeUnitRange.WEEK));
+ final RexCall floorSimplifiedExpr =
+ (RexCall) nonParanoidSimplify.simplifyPreservingType(outerFloorCall,
+ RexUnknownAs.UNKNOWN, true);
+ assertThat(floorSimplifiedExpr.getKind(), is(SqlKind.FLOOR));
+ assertThat(((RexLiteral) floorSimplifiedExpr.getOperands().get(1))
+ .getValue(),
+ hasToString(TimeUnitRange.WEEK.toString()));
+ assertThat(floorSimplifiedExpr.getOperands().get(0),
+ hasToString(literalTs.toString()));
+ final RexCall ceilSimplifiedExpr =
+ (RexCall) nonParanoidSimplify.simplifyPreservingType(outerCeilCall,
+ RexUnknownAs.UNKNOWN, true);
+ assertThat(ceilSimplifiedExpr.getKind(), is(SqlKind.CEIL));
+ assertThat(((RexLiteral) ceilSimplifiedExpr.getOperands().get(1))
+ .getValue(),
+ hasToString(TimeUnitRange.WEEK.toString()));
+ assertThat(ceilSimplifiedExpr.getOperands().get(0),
+ hasToString(literalTs.toString()));
+ }
+
+ // Negative tests: WEEK cannot rollup to MONTH or DAY,
+ // and MONTH cannot rollup to WEEK.
+ for (TimeUnitRange outerRange : ImmutableList.of(
+ TimeUnitRange.MONTH, TimeUnitRange.DAY)) {
+ final RexNode innerFloorCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.FLOOR, literalTs,
+ f.rexBuilder.makeFlag(TimeUnitRange.WEEK));
+ final RexNode innerCeilCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.CEIL, literalTs,
+ f.rexBuilder.makeFlag(TimeUnitRange.WEEK));
+ final RexNode outerFloorCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.FLOOR, innerFloorCall,
+ f.rexBuilder.makeFlag(outerRange));
+ final RexNode outerCeilCall =
+ f.rexBuilder.makeCall(SqlStdOperatorTable.CEIL, innerCeilCall,
+ f.rexBuilder.makeFlag(outerRange));
+ final RexCall floorSimplifiedExpr =
+ (RexCall) nonParanoidSimplify.simplifyPreservingType(outerFloorCall,
+ RexUnknownAs.UNKNOWN, true);
+ assertThat(floorSimplifiedExpr, hasToString(outerFloorCall.toString()));
Review Comment:
I'd like to know if you are happy with the changes made in the current test.
@mihaibudiu
--
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]