tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-635: Improve tests of query semantic verification.
Date Thu, 27 Feb 2014 06:33:31 GMT
Repository: incubator-tajo
Updated Branches:
  refs/heads/master db5c017d4 -> 03718031a


TAJO-635: Improve tests of query semantic verification.


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

Branch: refs/heads/master
Commit: 03718031a113af7ccd7ddba2df7513f6b0b21c42
Parents: db5c017
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Thu Feb 27 15:30:30 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Thu Feb 27 15:30:30 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../org/apache/tajo/algebra/FunctionExpr.java   |  4 +++
 .../tajo/engine/eval/BasicEvalNodeVisitor.java  | 28 +++++++++++++++++---
 .../tajo/engine/eval/BetweenPredicateEval.java  | 12 +++++++++
 .../tajo/engine/eval/EvalNodeVisitor2.java      |  4 ++-
 .../tajo/engine/planner/BaseAlgebraVisitor.java |  6 +++--
 .../tajo/engine/planner/ExprsVerifier.java      | 11 ++++++++
 .../apache/tajo/engine/eval/ExprTestBase.java   | 25 ++++++++++++++---
 .../tajo/engine/eval/TestSQLExpression.java     |  4 +--
 9 files changed, 84 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index eef17d2..96543bb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -263,6 +263,8 @@ Release 0.8.0 - unreleased
 
   BUG FIXES
 
+    TAJO-635: Improve tests of query semantic verification. (hyunsik)
+
     TAJO-620: A join query can cause IndexOutOfBoundsException if one of tables is empty.
(jaehwa)
 
     TAJO-628: The second stage of distinct aggregation can be scheduled to

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
index 6635aeb..91517e7 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
@@ -55,6 +55,10 @@ public class FunctionExpr extends Expr {
     return this.signature;
   }
 
+  public boolean hasParams() {
+    return params != null;
+  }
+
   public Expr[] getParams() {
     return params;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BasicEvalNodeVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BasicEvalNodeVisitor.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BasicEvalNodeVisitor.java
index 6053469..2208119 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BasicEvalNodeVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BasicEvalNodeVisitor.java
@@ -89,6 +89,9 @@ public class BasicEvalNodeVisitor<CONTEXT, RESULT> implements EvalNodeVisitor2<C
       case IS_NULL:
         result = visitIsNull(context, (IsNullEval) evalNode, stack);
         break;
+      case BETWEEN:
+        result = visitBetween(context, (BetweenPredicateEval) evalNode, stack);
+        break;
       case CASE:
         result = visitCaseWhen(context, (CaseWhenEval) evalNode, stack);
         break;
@@ -99,7 +102,7 @@ public class BasicEvalNodeVisitor<CONTEXT, RESULT> implements EvalNodeVisitor2<C
         result = visitInPredicate(context, (InEval) evalNode, stack);
         break;
 
-      // Pattern match predicates
+      // String operators and Pattern match predicates
       case LIKE:
         result = visitLike(context, (LikePredicateEval) evalNode, stack);
         break;
@@ -109,6 +112,9 @@ public class BasicEvalNodeVisitor<CONTEXT, RESULT> implements EvalNodeVisitor2<C
       case REGEX:
         result = visitRegex(context, (RegexPredicateEval) evalNode, stack);
         break;
+      case CONCATENATE:
+        result = visitConcatenate(context, (BinaryEval) evalNode, stack);
+        break;
 
       // Functions
       case FUNCTION:
@@ -143,8 +149,10 @@ public class BasicEvalNodeVisitor<CONTEXT, RESULT> implements EvalNodeVisitor2<C
   private RESULT visitDefaultFunctionEval(CONTEXT context, Stack<EvalNode> stack, FunctionEval
functionEval) {
     RESULT result = null;
     stack.push(functionEval);
-    for (EvalNode arg : functionEval.getArgs()) {
-      result = visitChild(context, arg, stack);
+    if (functionEval.getArgs() != null) {
+      for (EvalNode arg : functionEval.getArgs()) {
+        result = visitChild(context, arg, stack);
+      }
     }
     stack.pop();
     return result;
@@ -246,6 +254,15 @@ public class BasicEvalNodeVisitor<CONTEXT, RESULT> implements EvalNodeVisitor2<C
   }
 
   @Override
+  public RESULT visitBetween(CONTEXT context, BetweenPredicateEval evalNode, Stack<EvalNode>
stack) {
+    stack.push(evalNode);
+    RESULT result = visitChild(context, evalNode.getPredicand(), stack);
+    visitChild(context, evalNode.getBegin(), stack);
+    visitChild(context, evalNode.getEnd(), stack);
+    return result;
+  }
+
+  @Override
   public RESULT visitCaseWhen(CONTEXT context, CaseWhenEval evalNode, Stack<EvalNode>
stack) {
     RESULT result = null;
     stack.push(evalNode);
@@ -290,6 +307,11 @@ public class BasicEvalNodeVisitor<CONTEXT, RESULT> implements EvalNodeVisitor2<C
   }
 
   @Override
+  public RESULT visitConcatenate(CONTEXT context, BinaryEval evalNode, Stack<EvalNode>
stack) {
+    return visitDefaultBinaryEval(context, stack, evalNode);
+  }
+
+  @Override
   public RESULT visitFuncCall(CONTEXT context, GeneralFunctionEval evalNode, Stack<EvalNode>
stack) {
     return visitDefaultFunctionEval(context, stack, evalNode);
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BetweenPredicateEval.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BetweenPredicateEval.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BetweenPredicateEval.java
index 61dc02b..0f30ac9 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BetweenPredicateEval.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/BetweenPredicateEval.java
@@ -46,6 +46,18 @@ public class BetweenPredicateEval extends EvalNode {
     this.end = end;
   }
 
+  public EvalNode getPredicand() {
+    return predicand;
+  }
+
+  public EvalNode getBegin() {
+    return begin;
+  }
+
+  public EvalNode getEnd() {
+    return end;
+  }
+
   private static interface Checker {
     Datum eval(Schema schema, Tuple param);
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/EvalNodeVisitor2.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/EvalNodeVisitor2.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/EvalNodeVisitor2.java
index a77c9ea..024a988 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/EvalNodeVisitor2.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/EvalNodeVisitor2.java
@@ -50,14 +50,16 @@ public interface EvalNodeVisitor2<CONTEXT, RESULT> {
 
   // Other Predicates
   RESULT visitIsNull(CONTEXT context, IsNullEval evalNode, Stack<EvalNode> stack);
+  RESULT visitBetween(CONTEXT context, BetweenPredicateEval evalNode, Stack<EvalNode>
stack);
   RESULT visitCaseWhen(CONTEXT context, CaseWhenEval evalNode, Stack<EvalNode> stack);
   RESULT visitIfThen(CONTEXT context, CaseWhenEval.IfThenEval evalNode, Stack<EvalNode>
stack);
   RESULT visitInPredicate(CONTEXT context, InEval evalNode, Stack<EvalNode> stack);
 
-  // Pattern matching predicates
+  // String operator and Pattern matching predicates
   RESULT visitLike(CONTEXT context, LikePredicateEval evalNode, Stack<EvalNode> stack);
   RESULT visitSimilarTo(CONTEXT context, SimilarToPredicateEval evalNode, Stack<EvalNode>
stack);
   RESULT visitRegex(CONTEXT context, RegexPredicateEval evalNode, Stack<EvalNode> stack);
+  RESULT visitConcatenate(CONTEXT context, BinaryEval evalNode, Stack<EvalNode> stack);
 
   // Functions
   RESULT visitFuncCall(CONTEXT context, GeneralFunctionEval evalNode, Stack<EvalNode>
stack);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
index 5e4c893..cf36539 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
@@ -616,8 +616,10 @@ public class BaseAlgebraVisitor<CONTEXT, RESULT> implements AlgebraVisitor<CONTE
   public RESULT visitFunction(CONTEXT ctx, Stack<Expr> stack, FunctionExpr expr) throws
PlanningException {
     stack.push(expr);
     RESULT result = null;
-    for (Expr param : expr.getParams()) {
-      result = visit(ctx, stack, param);
+    if (expr.hasParams()) {
+      for (Expr param : expr.getParams()) {
+        result = visit(ctx, stack, param);
+      }
     }
     stack.pop();
     return result;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprsVerifier.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprsVerifier.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprsVerifier.java
index 2231df0..358cabd 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprsVerifier.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprsVerifier.java
@@ -194,4 +194,15 @@ public class ExprsVerifier extends BasicEvalNodeVisitor<VerificationState,
EvalN
     checkDivisionByZero(context, evalNode);
     return evalNode;
   }
+
+  @Override
+  public EvalNode visitFuncCall(VerificationState context, GeneralFunctionEval evalNode,
Stack<EvalNode> stack) {
+    super.visitFuncCall(context, evalNode, stack);
+    if (evalNode.getArgs() != null) {
+      for (EvalNode param : evalNode.getArgs()) {
+        visitChild(context, param, stack);
+      }
+    }
+    return evalNode;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
index 7e721c5..622da90 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
@@ -26,10 +26,8 @@ import org.apache.tajo.datum.NullDatum;
 import org.apache.tajo.datum.TextDatum;
 import org.apache.tajo.engine.json.CoreGsonHelper;
 import org.apache.tajo.engine.parser.SQLAnalyzer;
-import org.apache.tajo.engine.planner.LogicalPlan;
-import org.apache.tajo.engine.planner.LogicalPlanner;
-import org.apache.tajo.engine.planner.PlanningException;
-import org.apache.tajo.engine.planner.Target;
+import org.apache.tajo.engine.planner.*;
+import org.apache.tajo.engine.planner.logical.LogicalNode;
 import org.apache.tajo.engine.utils.SchemaUtil;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.storage.LazyTuple;
@@ -41,6 +39,7 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
 import java.io.IOException;
+import java.util.Stack;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -49,7 +48,10 @@ public class ExprTestBase {
   private static TajoTestingCluster util;
   private static CatalogService cat;
   private static SQLAnalyzer analyzer;
+  private static PreLogicalPlanVerifier preLogicalPlanVerifier;
   private static LogicalPlanner planner;
+  private static LogicalOptimizer optimizer;
+  private static LogicalPlanVerifier annotatedPlanVerifier;
 
   @BeforeClass
   public static void setUp() throws Exception {
@@ -61,7 +63,10 @@ public class ExprTestBase {
     }
 
     analyzer = new SQLAnalyzer();
+    preLogicalPlanVerifier = new PreLogicalPlanVerifier(cat);
     planner = new LogicalPlanner(cat);
+    optimizer = new LogicalOptimizer(util.getConfiguration());
+    annotatedPlanVerifier = new LogicalPlanVerifier(util.getConfiguration(), cat);
   }
 
   @AfterClass
@@ -77,7 +82,19 @@ public class ExprTestBase {
 
   private static Target[] getRawTargets(String query) throws PlanningException {
     Expr expr = analyzer.parse(query);
+    VerificationState state = new VerificationState();
+    preLogicalPlanVerifier.visit(state, new Stack<Expr>(), expr);
+    if (state.getErrorMessages().size() > 0) {
+      assertFalse(state.getErrorMessages().get(0), true);
+    }
     LogicalPlan plan = planner.createPlan(expr, true);
+    optimizer.optimize(plan);
+    annotatedPlanVerifier.visit(state, plan, plan.getRootBlock(), plan.getRootBlock().getRoot(),
+        new Stack<LogicalNode>());
+    if (state.getErrorMessages().size() > 0) {
+      assertFalse(state.getErrorMessages().get(0), true);
+    }
+
     Target [] targets = plan.getRootBlock().getRawTargets();
     if (targets == null) {
       throw new PlanningException("Wrong query statement or query plan: " + query);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/03718031/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
index 6520f9c..a7b0a9e 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
@@ -84,8 +84,8 @@ public class TestSQLExpression extends ExprTestBase {
         new String[]{"123.0", "234.0"});
     testEval(schema, "table1", "123,234", "select col1::float, col2::float from table1",
         new String[]{"123.0", "234.0"});
-    testEval(schema, "table1", "1980-04-01 01:50:01,234", "select col1::timestamp, col2::float
from table1 " +
-        "where col1 = '1980-04-01 01:50:01'::timestamp",
+    testEval(schema, "table1", "1980-04-01 01:50:01,234", "select col1::timestamp as t1,
col2::float from table1 " +
+        "where t1 = '1980-04-01 01:50:01'::timestamp",
         new String[]{"1980-04-01 01:50:01", "234.0"});
 
     testSimpleEval("select '1980-04-01 01:50:01'::timestamp;", new String [] {"1980-04-01
01:50:01"});


Mime
View raw message