tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [1/3] TAJO-539: Change some EvalNode::eval to directly return a Datum value.
Date Sat, 25 Jan 2014 06:35:01 GMT
Updated Branches:
  refs/heads/master 0386268e8 -> e23e78ccd


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
index 6264961..e70e6c2 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
@@ -23,10 +23,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.SortSpec;
-import org.apache.tajo.engine.eval.EvalNode;
-import org.apache.tajo.engine.eval.EvalTreeUtil;
-import org.apache.tajo.engine.eval.EvalType;
-import org.apache.tajo.engine.eval.FieldEval;
+import org.apache.tajo.engine.eval.*;
 import org.apache.tajo.engine.planner.*;
 import org.apache.tajo.engine.planner.logical.*;
 import org.apache.tajo.engine.utils.SchemaUtil;
@@ -412,12 +409,19 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    // Getting target names
-    final int targetNum = node.getTargets().length;
-    final String [] targetNames = new String[targetNum];
-    for (int i = 0; i < targetNum; i++) {
-      Target target = node.getTargets()[i];
-      targetNames[i] = newContext.addExpr(target);
+    // Getting eval names
+
+    final String [] aggEvalNames;
+    if (node.hasAggFunctions()) {
+      final int evalNum = node.getAggFunctions().length;
+      aggEvalNames = new String[evalNum];
+      for (int evalIdx = 0, targetIdx = groupingKeyNum; targetIdx < node.getTargets().length;
evalIdx++, targetIdx++) {
+        Target target = node.getTargets()[targetIdx];
+        EvalNode evalNode = node.getAggFunctions()[evalIdx];
+        aggEvalNames[evalIdx] = newContext.addExpr(new Target(evalNode, target.getCanonicalName()));
+      }
+    } else {
+      aggEvalNames = null;
     }
 
     // visit a child node
@@ -444,23 +448,50 @@ public class ProjectionPushDownRule extends
     }
 
     // Getting projected targets
-    List<Target> projectedTargets = TUtil.newList();
-    for (Iterator<String> it = getFilteredReferences(targetNames, context.requiredSet);
it.hasNext();) {
-      String referenceName = it.next();
-      Target target = context.targetListMgr.getTarget(referenceName);
+    if (node.hasAggFunctions()) {
+      AggregationFunctionCallEval [] aggEvals = new AggregationFunctionCallEval[aggEvalNames.length];
+      int i = 0;
+      for (Iterator<String> it = getFilteredReferences(aggEvalNames, TUtil.newList(aggEvalNames));
it.hasNext();) {
 
-      if (context.targetListMgr.isResolved(referenceName)) {
-        projectedTargets.add(new Target(new FieldEval(target.getNamedColumn())));
-      } else if (LogicalPlanner.checkIfBeEvaluatedAtGroupBy(target.getEvalTree(), node))
{
-        projectedTargets.add(target);
-        context.targetListMgr.resolve(target);
+        String referenceName = it.next();
+        Target target = context.targetListMgr.getTarget(referenceName);
+
+        if (LogicalPlanner.checkIfBeEvaluatedAtGroupBy(target.getEvalTree(), node)) {
+          aggEvals[i++] = target.getEvalTree();
+          context.targetListMgr.resolve(target);
+        }
+      }
+      if (aggEvals.length > 0) {
+        node.setAggFunctions(aggEvals);
       }
     }
     node.setInSchema(child.getOutSchema());
-    node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()]));
+    Target [] targets = buildGroupByTarget(node, aggEvalNames);
+    node.setTargets(targets);
+
     return node;
   }
 
+  public static Target [] buildGroupByTarget(GroupbyNode groupbyNode, String [] aggEvalNames)
{
+    final int groupingKeyNum = groupbyNode.getGroupingColumns().length;
+    final int aggrFuncNum = aggEvalNames != null ? aggEvalNames.length : 0;
+    EvalNode [] aggEvalNodes = groupbyNode.getAggFunctions();
+    Target [] targets = new Target[groupingKeyNum + aggrFuncNum];
+
+    for (int groupingKeyIdx = 0; groupingKeyIdx < groupingKeyNum; groupingKeyIdx++) {
+      targets[groupingKeyIdx] = new Target(new FieldEval(groupbyNode.getGroupingColumns()[groupingKeyIdx]));
+    }
+
+    if (aggEvalNames != null) {
+      for (int aggrFuncIdx = 0, targetIdx = groupingKeyNum; aggrFuncIdx < aggrFuncNum;
aggrFuncIdx++, targetIdx++) {
+        targets[targetIdx] =
+            new Target(new FieldEval(aggEvalNames[aggrFuncIdx], aggEvalNodes[aggrFuncIdx].getValueType()));
+      }
+    }
+
+    return targets;
+  }
+
   public LogicalNode visitFilter(Context context, LogicalPlan plan, LogicalPlan.QueryBlock
block,
                                  SelectionNode node, Stack<LogicalNode> stack) throws
PlanningException {
     Context newContext = new Context(context);
@@ -548,14 +579,14 @@ public class ProjectionPushDownRule extends
     return new FilteredStringsIterator(targetNames, required);
   }
 
-  static Iterator<String> getFilteredReferences(String [] targetNames, Set<String>
required) {
+  static Iterator<String> getFilteredReferences(String [] targetNames, Collection<String>
required) {
     return new FilteredStringsIterator(targetNames, required);
   }
 
   static class FilteredStringsIterator implements Iterator<String> {
     Iterator<String> iterator;
 
-    FilteredStringsIterator(Collection<String> targetNames, Set<String> required)
{
+    FilteredStringsIterator(Collection<String> targetNames, Collection<String>
required) {
       List<String> filtered = TUtil.newList();
       for (String name : targetNames) {
         if (required.contains(name)) {
@@ -566,7 +597,7 @@ public class ProjectionPushDownRule extends
       iterator = filtered.iterator();
     }
 
-    FilteredStringsIterator(String [] targetNames, Set<String> required) {
+    FilteredStringsIterator(String [] targetNames, Collection<String> required) {
       this(TUtil.newList(targetNames), required);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
index e7eaf40..42508a0 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
@@ -32,14 +32,12 @@ import org.apache.tajo.catalog.statistics.ColumnStats;
 import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.NullDatum;
-import org.apache.tajo.engine.eval.EvalContext;
 import org.apache.tajo.engine.eval.EvalNode;
 import org.apache.tajo.engine.planner.PlannerUtil;
 import org.apache.tajo.storage.RowStoreUtil;
 import org.apache.tajo.storage.Tuple;
 import org.apache.tajo.storage.TupleRange;
 import org.apache.tajo.storage.VTuple;
-import org.apache.tajo.util.TUtil;
 import org.apache.tajo.worker.dataserver.HttpUtil;
 
 import java.io.UnsupportedEncodingException;
@@ -418,14 +416,12 @@ public class TupleUtil {
 
   private static class TupleBlockFilterScanner {
     private EvalNode qual;
-    private EvalContext qualCtx;
     private Iterator<Tuple> iterator;
     private Schema schema;
 
     public TupleBlockFilterScanner(Schema schema, Collection<Tuple> tuples, EvalNode
qual) {
       this.schema = schema;
       this.qual = qual;
-      this.qualCtx = qual.newContext();
       this.iterator = tuples.iterator();
     }
 
@@ -435,8 +431,7 @@ public class TupleUtil {
       Tuple tuple;
       while (iterator.hasNext()) {
         tuple = iterator.next();
-        qual.eval(qualCtx, schema, tuple);
-        if (qual.terminate(qualCtx).asBool()) {
+        if (qual.eval(schema, tuple).isTrue()) {
           results.add(tuple);
         }
       }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
index cfe3b61..a969326 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
@@ -83,7 +83,7 @@ public class GlobalEngine extends AbstractService {
     try  {
       analyzer = new SQLAnalyzer();
       converter = new HiveConverter();
-      preVerifier = new PreLogicalPlanVerifier();
+      preVerifier = new PreLogicalPlanVerifier(context.getCatalog());
       planner = new LogicalPlanner(context.getCatalog());
       optimizer = new LogicalOptimizer(context.getConf());
       annotatedPlanVerifier = new LogicalPlanVerifier(context.getConf(), context.getCatalog());

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/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 07655a2..299703c 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
@@ -130,13 +130,10 @@ public class ExprTestBase {
     try {
       targets = getRawTargets(query);
 
-      EvalContext [] evalContexts = new EvalContext[targets.length];
       Tuple outTuple = new VTuple(targets.length);
       for (int i = 0; i < targets.length; i++) {
         EvalNode eval = targets[i].getEvalTree();
-        evalContexts[i] = eval.newContext();
-        eval.eval(evalContexts[i], inputSchema, vtuple);
-        outTuple.put(i, eval.terminate(evalContexts[i]));
+        outTuple.put(i, eval.eval(inputSchema, vtuple));
       }
 
       for (int i = 0; i < expected.length; i++) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
index 34ba1ca..0489e37 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
@@ -19,7 +19,6 @@
 package org.apache.tajo.engine.eval;
 
 import org.apache.tajo.TajoTestingCluster;
-import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
@@ -28,13 +27,6 @@ import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.engine.function.GeneralFunction;
 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.logical.NodeType;
-import org.apache.tajo.engine.planner.logical.SelectionNode;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.storage.Tuple;
 import org.apache.tajo.storage.VTuple;
@@ -43,8 +35,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.io.IOException;
-
 import static org.apache.tajo.common.TajoDataTypes.Type.*;
 import static org.junit.Assert.*;
 
@@ -136,15 +126,13 @@ public class TestEvalTree extends ExprTestBase{
     schema1.addColumn("table1.score", INT4);
     
     BinaryEval expr = new BinaryEval(EvalType.PLUS, e1, e2);
-    EvalContext evalCtx = expr.newContext();
     assertCloneEqual(expr);
     VTuple tuple = new VTuple(2);
     tuple.put(0, DatumFactory.createInt4(1)); // put 0th field
     tuple.put(1, DatumFactory.createInt4(99)); // put 0th field
 
     // the result of evaluation must be 100.
-    expr.eval(evalCtx, schema1, tuple);
-    assertEquals(expr.terminate(evalCtx).asInt4(), 100);
+    assertEquals(expr.eval(schema1, tuple).asInt4(), 100);
   }
 
   public static class MockTrueEval extends EvalNode {
@@ -159,7 +147,7 @@ public class TestEvalTree extends ExprTestBase{
     }
 
     @Override
-    public Datum terminate(EvalContext ctx) {
+    public Datum eval(Schema schema, Tuple tuple) {
       return DatumFactory.createBool(true);
     }
 
@@ -169,11 +157,6 @@ public class TestEvalTree extends ExprTestBase{
     }
 
     @Override
-    public EvalContext newContext() {
-      return null;
-    }
-
-    @Override
     public DataType getValueType() {
       return CatalogUtil.newSimpleDataType(BOOLEAN);
     }
@@ -187,12 +170,7 @@ public class TestEvalTree extends ExprTestBase{
     }
 
     @Override
-    public EvalContext newContext() {
-      return null;
-    }
-
-    @Override
-    public Datum terminate(EvalContext ctx) {
+    public Datum eval(Schema schema, Tuple tuple) {
       return DatumFactory.createBool(false);
     }
 
@@ -218,24 +196,16 @@ public class TestEvalTree extends ExprTestBase{
     MockFalseExpr falseExpr = new MockFalseExpr();
 
     BinaryEval andExpr = new BinaryEval(EvalType.AND, trueExpr, trueExpr);
-    EvalContext evalCtx = andExpr.newContext();
-    andExpr.eval(evalCtx, null, null);
-    assertTrue(andExpr.terminate(evalCtx).asBool());
+    assertTrue(andExpr.eval(null, null).asBool());
 
     andExpr = new BinaryEval(EvalType.AND, falseExpr, trueExpr);
-    evalCtx = andExpr.newContext();
-    andExpr.eval(evalCtx, null, null);
-    assertFalse(andExpr.terminate(evalCtx).asBool());
+    assertFalse(andExpr.eval(null, null).asBool());
 
     andExpr = new BinaryEval(EvalType.AND, trueExpr, falseExpr);
-    evalCtx= andExpr.newContext();
-    andExpr.eval(evalCtx, null, null);
-    assertFalse(andExpr.terminate(evalCtx).asBool());
+    assertFalse(andExpr.eval(null, null).asBool());
 
     andExpr = new BinaryEval(EvalType.AND, falseExpr, falseExpr);
-    evalCtx= andExpr.newContext();
-    andExpr.eval(evalCtx, null, null);
-    assertFalse(andExpr.terminate(evalCtx).asBool());
+    assertFalse(andExpr.eval(null, null).asBool());
   }
 
   @Test
@@ -244,24 +214,16 @@ public class TestEvalTree extends ExprTestBase{
     MockFalseExpr falseExpr = new MockFalseExpr();
 
     BinaryEval orExpr = new BinaryEval(EvalType.OR, trueExpr, trueExpr);
-    EvalContext evalCtx= orExpr.newContext();
-    orExpr.eval(evalCtx, null, null);
-    assertTrue(orExpr.terminate(evalCtx).asBool());
+    assertTrue(orExpr.eval(null, null).asBool());
 
     orExpr = new BinaryEval(EvalType.OR, falseExpr, trueExpr);
-    evalCtx= orExpr.newContext();
-    orExpr.eval(evalCtx, null, null);
-    assertTrue(orExpr.terminate(evalCtx).asBool());
+    assertTrue(orExpr.eval(null, null).asBool());
 
     orExpr = new BinaryEval(EvalType.OR, trueExpr, falseExpr);
-    evalCtx= orExpr.newContext();
-    orExpr.eval(evalCtx, null, null);
-    assertTrue(orExpr.terminate(evalCtx).asBool());
+    assertTrue(orExpr.eval(null, null).asBool());
 
     orExpr = new BinaryEval(EvalType.OR, falseExpr, falseExpr);
-    evalCtx = orExpr.newContext();
-    orExpr.eval(evalCtx, null, null);
-    assertFalse(orExpr.terminate(evalCtx).asBool());
+    assertFalse(orExpr.eval(null, null).asBool());
   }
 
   @Test
@@ -274,73 +236,41 @@ public class TestEvalTree extends ExprTestBase{
     e1 = new ConstEval(DatumFactory.createInt4(9));
     e2 = new ConstEval(DatumFactory.createInt4(34));
     expr = new BinaryEval(EvalType.LTH, e1, e2);
-    EvalContext evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.LEQ, e1, e2);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.LTH, e2, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.LEQ, e2, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
 
     expr = new BinaryEval(EvalType.GTH, e2, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.GEQ, e2, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.GTH, e1, e2);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.GEQ, e1, e2);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
 
     BinaryEval plus = new BinaryEval(EvalType.PLUS, e1, e2);
     expr = new BinaryEval(EvalType.LTH, e1, plus);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.LEQ, e1, plus);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.LTH, plus, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.LEQ, plus, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
 
     expr = new BinaryEval(EvalType.GTH, plus, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.GEQ, plus, e1);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.GTH, e1, plus);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
     expr = new BinaryEval(EvalType.GEQ, e1, plus);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertFalse(expr.terminate(evalCtx).asBool());
+    assertFalse(expr.eval(null, null).asBool());
   }
 
   @Test
@@ -353,36 +283,28 @@ public class TestEvalTree extends ExprTestBase{
     e1 = new ConstEval(DatumFactory.createInt4(9));
     e2 = new ConstEval(DatumFactory.createInt4(34));
     BinaryEval expr = new BinaryEval(EvalType.PLUS, e1, e2);
-    EvalContext evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertEquals(expr.terminate(evalCtx).asInt4(), 43);
+    assertEquals(expr.eval(null, null).asInt4(), 43);
     assertCloneEqual(expr);
     
     // MINUS
     e1 = new ConstEval(DatumFactory.createInt4(5));
     e2 = new ConstEval(DatumFactory.createInt4(2));
     expr = new BinaryEval(EvalType.MINUS, e1, e2);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertEquals(expr.terminate(evalCtx).asInt4(), 3);
+    assertEquals(expr.eval(null, null).asInt4(), 3);
     assertCloneEqual(expr);
     
     // MULTIPLY
     e1 = new ConstEval(DatumFactory.createInt4(5));
     e2 = new ConstEval(DatumFactory.createInt4(2));
     expr = new BinaryEval(EvalType.MULTIPLY, e1, e2);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertEquals(expr.terminate(evalCtx).asInt4(), 10);
+    assertEquals(expr.eval(null, null).asInt4(), 10);
     assertCloneEqual(expr);
     
     // DIVIDE
     e1 = new ConstEval(DatumFactory.createInt4(10));
     e2 = new ConstEval(DatumFactory.createInt4(5));
     expr = new BinaryEval(EvalType.DIVIDE, e1, e2);
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertEquals(expr.terminate(evalCtx).asInt4(), 2);
+    assertEquals(expr.eval(null, null).asInt4(), 2);
     assertCloneEqual(expr);
   }
 
@@ -398,9 +320,7 @@ public class TestEvalTree extends ExprTestBase{
     assertEquals(CatalogUtil.newSimpleDataType(INT4), expr.getValueType());
 
     expr = new BinaryEval(EvalType.LTH, e1, e2);
-    EvalContext evalCtx = expr.newContext();
-    expr.eval(evalCtx, null, null);
-    assertTrue(expr.terminate(evalCtx).asBool());
+    assertTrue(expr.eval(null, null).asBool());
     assertEquals(CatalogUtil.newSimpleDataType(BOOLEAN), expr.getValueType());
 
     e1 = new ConstEval(DatumFactory.createFloat8(9.3));

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
index 86c1c01..86d603e 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
@@ -219,19 +219,15 @@ public class TestEvalTreeUtil {
     EvalNode first = cnf[0];
     EvalNode second = cnf[1];
     
-    FieldEval field = (FieldEval) first.getLeftExpr();
+    FieldEval field = first.getLeftExpr();
     assertEquals(col1, field.getColumnRef());
     assertEquals(EvalType.LTH, first.getType());
-    EvalContext firstRCtx = first.getRightExpr().newContext();
-    first.getRightExpr().eval(firstRCtx, null,  null);
-    assertEquals(10, first.getRightExpr().terminate(firstRCtx).asInt4());
+    assertEquals(10, first.getRightExpr().eval(null,  null).asInt4());
     
-    field = (FieldEval) second.getRightExpr();
+    field = second.getRightExpr();
     assertEquals(col1, field.getColumnRef());
     assertEquals(EvalType.LTH, second.getType());
-    EvalContext secondLCtx = second.getLeftExpr().newContext();
-    second.getLeftExpr().eval(secondLCtx, null,  null);
-    assertEquals(4, second.getLeftExpr().terminate(secondLCtx).asInt4());
+    assertEquals(4, second.getLeftExpr().eval(null,  null).asInt4());
   }
   
   @Test
@@ -264,15 +260,11 @@ public class TestEvalTreeUtil {
   public final void testSimplify() throws PlanningException {
     Target [] targets = getRawTargets(QUERIES[0]);
     EvalNode node = AlgebraicUtil.eliminateConstantExprs(targets[0].getEvalTree());
-    EvalContext nodeCtx = node.newContext();
     assertEquals(EvalType.CONST, node.getType());
-    node.eval(nodeCtx, null, null);
-    assertEquals(7, node.terminate(nodeCtx).asInt4());
+    assertEquals(7, node.eval(null, null).asInt4());
     node = AlgebraicUtil.eliminateConstantExprs(targets[1].getEvalTree());
     assertEquals(EvalType.CONST, node.getType());
-    nodeCtx = node.newContext();
-    node.eval(nodeCtx, null, null);
-    assertTrue(7.0d == node.terminate(nodeCtx).asFloat8());
+    assertTrue(7.0d == node.eval(null, null).asFloat8());
 
     Expr expr = analyzer.parse(QUERIES[1]);
     LogicalPlan plan = planner.createPlan(expr);
@@ -300,9 +292,7 @@ public class TestEvalTreeUtil {
     assertEquals(EvalType.GTH, transposed.getType());
     FieldEval field = transposed.getLeftExpr();
     assertEquals(col1, field.getColumnRef());
-    EvalContext evalCtx = transposed.getRightExpr().newContext();
-    transposed.getRightExpr().eval(evalCtx, null, null);
-    assertEquals(1, transposed.getRightExpr().terminate(evalCtx).asInt4());
+    assertEquals(1, transposed.getRightExpr().eval(null, null).asInt4());
 
     node = getRootSelection(QUERIES[4]);
     // we expect that score < 3
@@ -310,9 +300,7 @@ public class TestEvalTreeUtil {
     assertEquals(EvalType.LTH, transposed.getType());
     field = transposed.getLeftExpr();
     assertEquals(col1, field.getColumnRef());
-    evalCtx = transposed.getRightExpr().newContext();
-    transposed.getRightExpr().eval(evalCtx, null, null);
-    assertEquals(2, transposed.getRightExpr().terminate(evalCtx).asInt4());
+    assertEquals(2, transposed.getRightExpr().eval(null, null).asInt4());
   }
 
   @Test
@@ -321,11 +309,11 @@ public class TestEvalTreeUtil {
     Expr expr = analyzer.parse(query);
     LogicalPlan plan = planner.createPlan(expr);
     GroupbyNode groupByNode = plan.getRootBlock().getNode(NodeType.GROUP_BY);
-    Target [] targets = groupByNode.getTargets();
+    EvalNode [] aggEvals = groupByNode.getAggFunctions();
 
     List<AggregationFunctionCallEval> list = new ArrayList<AggregationFunctionCallEval>();
-    for (int i = 0; i < targets.length; i++) {
-      list.addAll(EvalTreeUtil.findDistinctAggFunction(targets[i].getEvalTree()));
+    for (int i = 0; i < aggEvals.length; i++) {
+      list.addAll(EvalTreeUtil.findDistinctAggFunction(aggEvals[i]));
     }
     assertEquals(2, list.size());
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
index 6758189..9eb0276 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
@@ -570,7 +570,7 @@ public class TestLogicalPlanner {
 
   static final String ALIAS [] = {
     "select deptName, sum(score) as total from score group by deptName",
-    "select em.empId as id, sum(score) as total from employee as em inner join score using
(em.deptName)"
+    "select em.empId as id, sum(score) as total from employee as em inner join score using
(em.deptName) group by id"
   };
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestPlannerUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestPlannerUtil.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestPlannerUtil.java
index 85ea4f2..00ce501 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestPlannerUtil.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestPlannerUtil.java
@@ -91,28 +91,6 @@ public class TestPlannerUtil {
   }
 
   @Test
-  public final void testTransformTwoPhase() throws PlanningException {
-    // without 'having clause'
-    Expr expr = analyzer.parse(TestLogicalPlanner.QUERIES[7]);
-    LogicalNode plan = planner.createPlan(expr).getRootBlock().getRoot();
-
-    assertEquals(NodeType.ROOT, plan.getType());
-    LogicalRootNode root = (LogicalRootNode) plan;
-    TestLogicalPlanner.testQuery7(root.getChild());
-    
-    root.postOrder(new TwoPhaseBuilder());
-  }
-  
-  private final class TwoPhaseBuilder implements LogicalNodeVisitor {
-    @Override
-    public void visit(LogicalNode node) {
-      if (node.getType() == NodeType.GROUP_BY) {
-        PlannerUtil.transformGroupbyTo2P((GroupbyNode) node);
-      }
-    }    
-  }
-  
-  @Test
   public final void testFindTopNode() throws CloneNotSupportedException, PlanningException
{
     // two relations
     Expr expr = analyzer.parse(TestLogicalPlanner.QUERIES[1]);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/e23e78cc/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
index 0f3c165..ab27a45 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
@@ -25,7 +25,9 @@ import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
-import org.apache.tajo.*;
+import org.apache.tajo.LocalTajoTestingUtility;
+import org.apache.tajo.QueryUnitAttemptId;
+import org.apache.tajo.TajoTestingCluster;
 import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
@@ -35,14 +37,12 @@ import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.NullDatum;
 import org.apache.tajo.engine.eval.AggregationFunctionCallEval;
-import org.apache.tajo.engine.eval.EvalNode;
-import org.apache.tajo.engine.eval.EvalTreeUtil;
 import org.apache.tajo.engine.parser.SQLAnalyzer;
 import org.apache.tajo.engine.planner.*;
 import org.apache.tajo.engine.planner.enforce.Enforcer;
+import org.apache.tajo.engine.planner.global.DataChannel;
 import org.apache.tajo.engine.planner.global.MasterPlan;
 import org.apache.tajo.engine.planner.logical.*;
-import org.apache.tajo.engine.planner.global.DataChannel;
 import org.apache.tajo.ipc.TajoWorkerProtocol;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.storage.*;
@@ -563,12 +563,8 @@ public class TestPhysicalPlanner {
 
     // Set all aggregation functions to the first phase mode
     GroupbyNode groupbyNode = PlannerUtil.findTopNode(rootNode, NodeType.GROUP_BY);
-    for (Target target : groupbyNode.getTargets()) {
-      for (EvalNode eval : EvalTreeUtil.findDistinctAggFunction(target.getEvalTree())) {
-        if (eval instanceof AggregationFunctionCallEval) {
-          ((AggregationFunctionCallEval) eval).setFirstPhase();
-        }
-      }
+    for (AggregationFunctionCallEval function : groupbyNode.getAggFunctions()) {
+      function.setFirstPhase();
     }
 
     PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf,sm);
@@ -597,12 +593,8 @@ public class TestPhysicalPlanner {
 
     // Set all aggregation functions to the first phase mode
     GroupbyNode groupbyNode = PlannerUtil.findTopNode(rootNode, NodeType.GROUP_BY);
-    for (Target target : groupbyNode.getTargets()) {
-      for (EvalNode eval : EvalTreeUtil.findDistinctAggFunction(target.getEvalTree())) {
-        if (eval instanceof AggregationFunctionCallEval) {
-          ((AggregationFunctionCallEval) eval).setFirstPhase();
-        }
-      }
+    for (AggregationFunctionCallEval function : groupbyNode.getAggFunctions()) {
+      function.setFirstPhase();
     }
 
     PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf,sm);


Mime
View raw message