drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [7/9] drill git commit: DRILL-4971: Query encounters system error, when there aren't eval subexpressions of any function in boolean and/or expressions
Date Mon, 03 Apr 2017 05:12:07 GMT
DRILL-4971: Query encounters system error, when there aren't eval subexpressions of any function
in boolean and/or expressions

- New evaluated blocks for boolean operators should be with braces always, since they use
labels.

close #792


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/e0121d5f
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/e0121d5f
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/e0121d5f

Branch: refs/heads/master
Commit: e0121d5f953a9f4ecd71d74e97ddaa1a169a5102
Parents: 4c7e3a1
Author: Vitalii Diravka <vitalii.diravka@gmail.com>
Authored: Fri Mar 17 11:41:46 2017 +0000
Committer: Jinfeng Ni <jni@apache.org>
Committed: Fri Mar 31 15:32:44 2017 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/expr/ClassGenerator.java  | 20 +++++++++++++
 .../drill/exec/expr/EvaluationVisitor.java      | 11 ++++---
 .../java/org/apache/drill/TestBugFixes.java     | 31 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/e0121d5f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ClassGenerator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ClassGenerator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ClassGenerator.java
index 0b6adaa..5310334 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ClassGenerator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ClassGenerator.java
@@ -186,6 +186,26 @@ public class ClassGenerator<T>{
     return getEvalBlock().label(prefix + labelIndex ++);
   }
 
+  /**
+   * Creates an inner braced and indented block
+   * @param type type of the created block
+   * @return a newly created inner block
+   */
+  private JBlock createInnerBlock(BlockType type) {
+    final JBlock currBlock = getBlock(type);
+    final JBlock innerBlock = new JBlock();
+    currBlock.add(innerBlock);
+    return innerBlock;
+  }
+
+  /**
+   * Creates an inner braced and indented block for evaluation of the expression.
+   * @return a newly created inner eval block
+   */
+  protected JBlock createInnerEvalBlock() {
+    return createInnerBlock(BlockType.EVAL);
+  }
+
   public JVar declareVectorValueSetupAndMember(String batchName, TypedFieldId fieldId) {
     return declareVectorValueSetupAndMember(DirectExpression.direct(batchName), fieldId);
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/e0121d5f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
index 53bd8b8..75b83c9 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -144,6 +144,9 @@ public class EvaluationVisitor {
     previousExpressions = mapStack.pop();
   }
 
+  /**
+   * Get a HoldingContainer for the expression if it had been already evaluated
+   */
   private HoldingContainer getPrevious(LogicalExpression expression, MappingSet mappingSet)
{
     HoldingContainer previous = previousExpressions.get(new ExpressionHolder(expression,
mappingSet));
     if (previous != null) {
@@ -671,8 +674,8 @@ public class EvaluationVisitor {
       HoldingContainer out = generator.declare(op.getMajorType());
 
       JLabel label = generator.getEvalBlockLabel("AndOP");
-      JBlock eval = generator.getEvalBlock().block();  // enter into nested block
-      generator.nestEvalBlock(eval);
+      JBlock eval = generator.createInnerEvalBlock();
+      generator.nestEvalBlock(eval);  // enter into nested block
 
       HoldingContainer arg = null;
 
@@ -733,7 +736,7 @@ public class EvaluationVisitor {
       HoldingContainer out = generator.declare(op.getMajorType());
 
       JLabel label = generator.getEvalBlockLabel("OrOP");
-      JBlock eval = generator.getEvalBlock().block();
+      JBlock eval = generator.createInnerEvalBlock();
       generator.nestEvalBlock(eval);   // enter into nested block.
 
       HoldingContainer arg = null;

http://git-wip-us.apache.org/repos/asf/drill/blob/e0121d5f/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java b/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
index 526a7e3..27df710 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
@@ -241,4 +241,35 @@ public class TestBugFixes extends BaseTestQuery {
     query.append("(CAST('1951-05-16' AS DATE))) tbl(dt)");
     test(query.toString());
   }
+
+  @Test // DRILL-4971
+  public void testVisitBooleanOrWithoutFunctionsEvaluation() throws Exception {
+    String query = "SELECT\n" +
+        "CASE WHEN employee_id IN (1) THEN 1 ELSE 0 END `first`\n" +
+        ", CASE WHEN employee_id IN (2) THEN 1 ELSE 0 END `second`\n" +
+        ", CASE WHEN employee_id IN (1, 2) THEN 1 ELSE 0 END `any`\n" +
+        "FROM cp.`employee.json` ORDER BY employee_id limit 2";
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("first", "second", "any")
+        .baselineValues(1, 0, 1)
+        .baselineValues(0, 1, 1)
+        .go();
+  }
+
+  @Test // DRILL-4971
+  public void testVisitBooleanAndWithoutFunctionsEvaluation() throws Exception {
+    String query = "SELECT employee_id FROM cp.`employee.json` WHERE\n" +
+        "((employee_id > 1 AND employee_id < 3) OR (employee_id > 9 AND employee_id
< 11))\n" +
+        "AND (employee_id > 1 AND employee_id < 3)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("employee_id")
+        .baselineValues((long) 2)
+        .go();
+  }
 }


Mime
View raw message