tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-538: Groupby queries with constant target lists doesn't work. (hyunsik)
Date Tue, 21 Jan 2014 06:34:56 GMT
Updated Branches:
  refs/heads/master e57cf426d -> 9693b7397


TAJO-538: Groupby queries with constant target lists doesn't work. (hyunsik)


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

Branch: refs/heads/master
Commit: 9693b739745928c67946c22f0f58254344bae88d
Parents: e57cf42
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Tue Jan 21 15:34:38 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Tue Jan 21 15:34:38 2014 +0900

----------------------------------------------------------------------
 .../tajo/engine/planner/LogicalPlanner.java     | 23 +++++++++++++-------
 .../tajo/engine/planner/NamedExprsManager.java  |  4 ++++
 .../tajo/engine/query/TestGroupByQuery.java     |  8 +++++++
 .../queries/TestGroupByQuery/testGroupBy5.sql   |  1 +
 .../TestGroupByQuery/testGroupBy5.result        |  5 +++++
 5 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/9693b739/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index 2ec3d75..49d5ffb 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -852,14 +852,17 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
     ScanNode scanNode = block.getNodeFromExpr(expr);
     updatePhysicalInfo(scanNode.getTableDesc());
 
-    // Add additional expressions required in upper nodes.
-    Set<Expr> newlyEvaluatedExprs = new LinkedHashSet<Expr>();
+    // Add additional expressions required in upper nodes, such as sort key, grouping columns,
+    // column references included in filter condition
+    //
+    // newlyEvaluatedExprsRef keeps
+    Set<String> newlyEvaluatedExprsReferences = new LinkedHashSet<String>();
     for (NamedExpr rawTarget : block.namedExprsMgr.getAllNamedExprs()) {
       try {
         EvalNode evalNode = exprAnnotator.createEvalNode(context.plan, context.queryBlock,
rawTarget.getExpr());
         if (checkIfBeEvaluatedAtRelation(block, evalNode, scanNode)) {
           block.namedExprsMgr.resolveExpr(rawTarget.getAlias(), evalNode);
-          newlyEvaluatedExprs.add(rawTarget.getExpr()); // newly added exr
+          newlyEvaluatedExprsReferences.add(rawTarget.getAlias()); // newly added exr
         }
       } catch (VerifyException ve) {
       }
@@ -872,14 +875,18 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
       if (block.namedExprsMgr.contains(columnRef)) {
         String referenceName = block.namedExprsMgr.getName(columnRef);
         targets.add(new Target(new FieldEval(column), referenceName));
-        newlyEvaluatedExprs.remove(columnRef);
+        newlyEvaluatedExprsReferences.remove(column.getQualifiedName());
       } else {
         targets.add(new Target(new FieldEval(column)));
       }
     }
 
-    for (Expr newAddedExpr : newlyEvaluatedExprs) {
-      targets.add(block.namedExprsMgr.getTarget(newAddedExpr, true));
+    // The fact the some expr is included in newlyEvaluatedExprsReferences means that it
is already resolved.
+    // So, we get a raw expression and then creates a target.
+    for (String reference : newlyEvaluatedExprsReferences) {
+      NamedExpr refrrer = block.namedExprsMgr.getNamedExpr(reference);
+      EvalNode evalNode = exprAnnotator.createEvalNode(context.plan, block, refrrer.getExpr());
+      targets.add(new Target(evalNode, reference));
     }
 
     scanNode.setTargets(targets.toArray(new Target[targets.size()]));
@@ -1049,7 +1056,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
       Schema targetSchema = new Schema();
       if (expr.hasTargetColumns()) {
         // INSERT OVERWRITE INTO TABLE tbl(col1 type, col2 type) SELECT ...
-        String [] targetColumnNames = expr.getTargetColumns();
+        String[] targetColumnNames = expr.getTargetColumns();
         for (int i = 0; i < targetColumnNames.length; i++) {
           Column targetColumn = context.plan.resolveColumn(context.queryBlock,
               new ColumnReferenceExpr(targetColumnNames[i]));
@@ -1315,7 +1322,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
    * @param elements to be transformed
    * @return schema transformed from table definition elements
    */
-  private Schema convertTableElementsSchema(CreateTable.ColumnDefinition [] elements) {
+  private Schema convertTableElementsSchema(CreateTable.ColumnDefinition[] elements) {
     Schema schema = new Schema();
 
     for (CreateTable.ColumnDefinition columnDefinition: elements) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/9693b739/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/NamedExprsManager.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/NamedExprsManager.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/NamedExprsManager.java
index 05ba036..893fbe1 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/NamedExprsManager.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/NamedExprsManager.java
@@ -26,6 +26,7 @@ import org.apache.tajo.algebra.NamedExpr;
 import org.apache.tajo.algebra.OpType;
 import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.engine.eval.EvalNode;
+import org.apache.tajo.engine.eval.EvalType;
 import org.apache.tajo.engine.eval.FieldEval;
 import org.apache.tajo.util.TUtil;
 
@@ -170,6 +171,9 @@ public class NamedExprsManager {
   }
 
   public void resolveExpr(String name, EvalNode evalNode) throws PlanningException {
+    if (evalNode.getType() == EvalType.CONST) {
+      return;
+    }
     String normalized = name.toLowerCase();
     nameToEvalMap.put(normalized, evalNode);
     evalToNameMap.put(evalNode, normalized);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/9693b739/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
index e8995ca..8bb2c28 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
@@ -60,6 +60,14 @@ public class TestGroupByQuery extends QueryTestCaseBase {
   }
 
   @Test
+  public final void testGroupBy5() throws Exception {
+    // select l_orderkey as gkey, '00' as num from lineitem group by lineitem.l_orderkey
order by gkey
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
   public final void testGroupByNested1() throws Exception {
     // select l_orderkey + l_partkey as unique_key from lineitem group by l_orderkey + l_partkey;
     ResultSet res = executeQuery();

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/9693b739/tajo-core/tajo-core-backend/src/test/resources/queries/TestGroupByQuery/testGroupBy5.sql
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/resources/queries/TestGroupByQuery/testGroupBy5.sql
b/tajo-core/tajo-core-backend/src/test/resources/queries/TestGroupByQuery/testGroupBy5.sql
new file mode 100644
index 0000000..96ea13b
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/resources/queries/TestGroupByQuery/testGroupBy5.sql
@@ -0,0 +1 @@
+select l_orderkey as gkey, '00' as const_val from lineitem group by lineitem.l_orderkey order
by gkey;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/9693b739/tajo-core/tajo-core-backend/src/test/resources/results/TestGroupByQuery/testGroupBy5.result
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/resources/results/TestGroupByQuery/testGroupBy5.result
b/tajo-core/tajo-core-backend/src/test/resources/results/TestGroupByQuery/testGroupBy5.result
new file mode 100644
index 0000000..abf0e45
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/resources/results/TestGroupByQuery/testGroupBy5.result
@@ -0,0 +1,5 @@
+gkey,const_val
+-------------------------------
+1,00
+2,00
+3,00
\ No newline at end of file


Mime
View raw message