You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2017/03/08 11:19:02 UTC

lens git commit: LENS-1399: Union Query rewrite incorrect in case of select expressions containing dimensions

Repository: lens
Updated Branches:
  refs/heads/lens-1381 2aaf6e0a0 -> de464faa8


LENS-1399: Union Query rewrite incorrect in case of select expressions containing dimensions


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

Branch: refs/heads/lens-1381
Commit: de464faa810f31ae7b2733566ee4d9ff1286a0df
Parents: 2aaf6e0
Author: Rajitha R <ra...@gmail.com>
Authored: Wed Mar 8 16:48:19 2017 +0530
Committer: Rajat Khandelwal <ra...@gmail.com>
Committed: Wed Mar 8 16:48:19 2017 +0530

----------------------------------------------------------------------
 .../org/apache/lens/cube/parse/UnionQueryWriter.java | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/de464faa/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java
index 4f1f808..2ca1181 100644
--- a/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java
+++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java
@@ -188,7 +188,7 @@ public class UnionQueryWriter {
       ASTNode outerOrderby = new ASTNode(child);
       ASTNode tokNullsChild = (ASTNode) child.getChild(0);
       ASTNode outerTokNullsChild = new ASTNode(tokNullsChild);
-      outerTokNullsChild.addChild(getOuterAST((ASTNode) tokNullsChild.getChild(0), null, aliasDecider, null, true));
+      outerTokNullsChild.addChild(getOuterAST((ASTNode) tokNullsChild.getChild(0), null, aliasDecider, null, true, cubeql.getBaseCube().getDimAttributeNames()));
       outerOrderby.addChild(outerTokNullsChild);
       outerExpression.addChild(outerOrderby);
     }
@@ -489,7 +489,7 @@ public class UnionQueryWriter {
       ASTNode child = (ASTNode) selectAST.getChild(i);
       ASTNode outerSelect = new ASTNode(child);
       ASTNode selectExprAST = (ASTNode) child.getChild(0);
-      ASTNode outerAST = getOuterAST(selectExprAST, innerSelectAST, aliasDecider, sc, true);
+      ASTNode outerAST = getOuterAST(selectExprAST, innerSelectAST, aliasDecider, sc, true, cubeql.getBaseCube().getDimAttributeNames());
       outerSelect.addChild(outerAST);
       // has an alias? add it
       if (child.getChildCount() > 1) {
@@ -524,12 +524,13 @@ public class UnionQueryWriter {
    5. If given ast is memorized as mentioned in the above cases, return the mapping.
  */
   private ASTNode getOuterAST(ASTNode astNode, ASTNode innerSelectAST,
-      AliasDecider aliasDecider, StorageCandidate sc, boolean isSelectAst) throws LensException {
+      AliasDecider aliasDecider, StorageCandidate sc, boolean isSelectAst, Set<String> dimensionSet) throws LensException {
     if (astNode == null) {
       return null;
     }
     Set<String> msrCols = new HashSet<>();
     getAllColumnsOfNode(astNode, msrCols);
+    msrCols.removeAll(dimensionSet);
     if (isAggregateAST(astNode) && sc.getColumns().containsAll(msrCols)) {
       return processAggregate(astNode, innerSelectAST, aliasDecider, isSelectAst);
     } else if (isAggregateAST(astNode) && !sc.getColumns().containsAll(msrCols)) {
@@ -537,7 +538,7 @@ public class UnionQueryWriter {
       ASTNode exprCopy = MetastoreUtil.copyAST(astNode);
       setDefaultValueInExprForAggregateNodes(exprCopy, sc);
       outerAST.addChild(getOuterAST(getSelectExpr(exprCopy, null, true),
-          innerSelectAST, aliasDecider, sc, isSelectAst));
+          innerSelectAST, aliasDecider, sc, isSelectAst, dimensionSet));
       return outerAST;
     } else {
       if (hasAggregate(astNode)) {
@@ -545,10 +546,10 @@ public class UnionQueryWriter {
         for (Node child : astNode.getChildren()) {
           ASTNode childAST = (ASTNode) child;
           if (hasAggregate(childAST) && sc.getColumns().containsAll(msrCols)) {
-            outerAST.addChild(getOuterAST(childAST, innerSelectAST, aliasDecider, sc, isSelectAst));
+            outerAST.addChild(getOuterAST(childAST, innerSelectAST, aliasDecider, sc, isSelectAst, dimensionSet));
           } else if (hasAggregate(childAST) && !sc.getColumns().containsAll(msrCols)) {
             childAST.replaceChildren(1, 1,  getSelectExpr(null, null, true));
-            outerAST.addChild(getOuterAST(childAST, innerSelectAST, aliasDecider, sc, isSelectAst));
+            outerAST.addChild(getOuterAST(childAST, innerSelectAST, aliasDecider, sc, isSelectAst, dimensionSet));
           } else {
             outerAST.addChild(childAST);
           }
@@ -638,7 +639,7 @@ public class UnionQueryWriter {
     // iterate over all children of the ast and get outer ast corresponding to it.
     for (ASTNode child : havingAggASTs) {
       if (!innerToOuterSelectASTs.containsKey(new HQLParser.HashableASTNode(child))) {
-        getOuterAST(child, innerSelectAst, aliasDecider, sc, false);
+        getOuterAST(child, innerSelectAst, aliasDecider, sc, false, cubeql.getBaseCube().getDimAttributeNames());
       }
     }
   }