You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by kg...@apache.org on 2019/02/20 07:53:41 UTC
[calcite] branch master updated: [CALCITE-2848] Simplifying a case
statement's first branch should ignore its safety
This is an automated email from the ASF dual-hosted git repository.
kgyrtkirk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 9924699 [CALCITE-2848] Simplifying a case statement's first branch should ignore its safety
9924699 is described below
commit 9924699e534516f47363aa30d23fb9e64e34ed29
Author: Zoltan Haindrich <ki...@rxd.hu>
AuthorDate: Fri Feb 15 00:42:38 2019 +0100
[CALCITE-2848] Simplifying a case statement's first branch should ignore its safety
Earlier when a CASE expression had any condition/value which contained probably dangerous instructions,
the rewrite to a boolean expression was abandoned.
This change relaxes the check to omit it for first branch's condition - because that would be evaluated anyway.
---
core/src/main/java/org/apache/calcite/rex/RexSimplify.java | 3 ++-
core/src/test/java/org/apache/calcite/test/RexProgramTest.java | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
index 8fa8a8b..fb98d8d 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
@@ -952,7 +952,8 @@ public class RexSimplify {
// but not interfere with the normal simplifcation recursion
List<CaseBranch> branches = new ArrayList<>();
for (CaseBranch branch : inputBranches) {
- if (!isSafeExpression(branch.cond) || !isSafeExpression(branch.value)) {
+ if ((branches.size() > 0 && !isSafeExpression(branch.cond))
+ || !isSafeExpression(branch.value)) {
return null;
}
RexNode cond;
diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
index 0fa89d6..2304522 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -1874,6 +1874,13 @@ public class RexProgramTest extends RexProgramBuilderBase {
checkSimplifyUnchanged(caseNode);
}
+ @Test public void testSimplifyCaseFirstBranchIsSafe() {
+ RexNode caseNode = case_(
+ gt(div(vIntNotNull(), literal(1)), literal(1)), falseLiteral,
+ trueLiteral);
+ checkSimplify(caseNode, "<=(/(?0.notNullInt0, 1), 1)");
+ }
+
@Test public void testSimplifyAnd() {
RelDataType booleanNotNullableType =
typeFactory.createTypeWithNullability(