You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/03/06 07:32:20 UTC
[GitHub] [calcite] chunweilei opened a new pull request #1848:
[CALCITE-3845] CASE WHEN expression with nullability CAST is considered as
reduced wrongly in ReduceExpressionsRule
chunweilei opened a new pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1848:
[CALCITE-3845] CASE WHEN expression with nullability CAST is considered as
reduced wrongly in ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848#discussion_r389754090
##########
File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
##########
@@ -3480,6 +3481,51 @@ private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) {
sql(sql).with(program).check();
}
+ @Test public void testReduceCaseWhenWithCast() {
+ final RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build());
+ final RexBuilder rexBuilder = relBuilder.getRexBuilder();
+ final RelDataType type = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
+
+ RelNode left = relBuilder
+ .values(new String[]{"x", "y"}, 1, 2).build();
+ RexNode ref = rexBuilder.makeInputRef(left, 0);
+ RexNode literal1 = rexBuilder.makeLiteral(1, type, false);
+ RexNode literal2 = rexBuilder.makeLiteral(2, type, false);
+ RexNode literal3 = rexBuilder.makeLiteral(3, type, false);
+
+ // CASE WHEN x % 2 = 1 THEN x < 2
+ // WHEN x % 3 = 2 THEN x < 1
+ // ELSE x < 3
+ final RexNode caseRexNode = rexBuilder.makeCall(SqlStdOperatorTable.CASE,
+ rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
+ rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal2), literal1),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal2),
+ rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
+ rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal3), literal2),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal1),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal3));
Review comment:
What I mean is signal to noise ratio leaves much to be desired here.
The dance of `rexBuilder.makeCall(SqlStdOperatorTable` repeats again and again :(
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] chunweilei commented on a change in pull request #1848:
[CALCITE-3845] CASE WHEN expression with nullability CAST is considered as
reduced wrongly in ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
chunweilei commented on a change in pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848#discussion_r389749749
##########
File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
##########
@@ -3480,6 +3481,51 @@ private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) {
sql(sql).with(program).check();
}
+ @Test public void testReduceCaseWhenWithCast() {
+ final RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build());
+ final RexBuilder rexBuilder = relBuilder.getRexBuilder();
+ final RelDataType type = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
+
+ RelNode left = relBuilder
+ .values(new String[]{"x", "y"}, 1, 2).build();
+ RexNode ref = rexBuilder.makeInputRef(left, 0);
+ RexNode literal1 = rexBuilder.makeLiteral(1, type, false);
+ RexNode literal2 = rexBuilder.makeLiteral(2, type, false);
+ RexNode literal3 = rexBuilder.makeLiteral(3, type, false);
+
+ // CASE WHEN x % 2 = 1 THEN x < 2
+ // WHEN x % 3 = 2 THEN x < 1
+ // ELSE x < 3
+ final RexNode caseRexNode = rexBuilder.makeCall(SqlStdOperatorTable.CASE,
+ rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
+ rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal2), literal1),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal2),
+ rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
+ rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal3), literal2),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal1),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal3));
Review comment:
I wish I can provide a more simple case, but I cannot. Because CASE WHEN will be changed to OR in many cases and thus it will not reproduce the issue.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1848:
[CALCITE-3845] CASE WHEN expression with nullability CAST is considered as
reduced wrongly in ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848#discussion_r389708007
##########
File path: core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
##########
@@ -302,6 +302,7 @@ public ProjectReduceExpressionsRule(Class<? extends Project> projectClass,
Lists.newArrayList(project.getProjects());
if (reduceExpressions(project, expList, predicates, false,
matchNullability)) {
+ assert !project.getProjects().equals(expList);
Review comment:
Can you please add a message, so the failure looks human-readable?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] chunweilei merged pull request #1848: [CALCITE-3845] CASE
WHEN expression with nullability CAST is considered as reduced wrongly in
ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
chunweilei merged pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1848:
[CALCITE-3845] CASE WHEN expression with nullability CAST is considered as
reduced wrongly in ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848#discussion_r389726120
##########
File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
##########
@@ -3480,6 +3481,51 @@ private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) {
sql(sql).with(program).check();
}
+ @Test public void testReduceCaseWhenWithCast() {
+ final RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build());
+ final RexBuilder rexBuilder = relBuilder.getRexBuilder();
+ final RelDataType type = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
+
+ RelNode left = relBuilder
+ .values(new String[]{"x", "y"}, 1, 2).build();
+ RexNode ref = rexBuilder.makeInputRef(left, 0);
+ RexNode literal1 = rexBuilder.makeLiteral(1, type, false);
+ RexNode literal2 = rexBuilder.makeLiteral(2, type, false);
+ RexNode literal3 = rexBuilder.makeLiteral(3, type, false);
+
+ // CASE WHEN x % 2 = 1 THEN x < 2
+ // WHEN x % 3 = 2 THEN x < 1
+ // ELSE x < 3
+ final RexNode caseRexNode = rexBuilder.makeCall(SqlStdOperatorTable.CASE,
+ rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
+ rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal2), literal1),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal2),
+ rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
+ rexBuilder.makeCall(SqlStdOperatorTable.MOD, ref, literal3), literal2),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal1),
+ rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, ref, literal3));
Review comment:
This looks way too verbose :-/
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] DonnyZone commented on issue #1848: [CALCITE-3845] CASE
WHEN expression with nullability CAST is considered as reduced wrongly in
ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
DonnyZone commented on issue #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848#issuecomment-596311598
LGTM
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] chunweilei commented on a change in pull request #1848:
[CALCITE-3845] CASE WHEN expression with nullability CAST is considered as
reduced wrongly in ReduceExpressionsRule
Posted by GitBox <gi...@apache.org>.
chunweilei commented on a change in pull request #1848: [CALCITE-3845] CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
URL: https://github.com/apache/calcite/pull/1848#discussion_r389748026
##########
File path: core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
##########
@@ -302,6 +302,7 @@ public ProjectReduceExpressionsRule(Class<? extends Project> projectClass,
Lists.newArrayList(project.getProjects());
if (reduceExpressions(project, expList, predicates, false,
matchNullability)) {
+ assert !project.getProjects().equals(expList);
Review comment:
Ok. Will do.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services