hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pxi...@apache.org
Subject [2/2] hive git commit: HIVE-15769: Support view creation in CBO (Pengcheng Xiong, reviewed by Ashutosh Chauhan)
Date Sat, 11 Feb 2017 21:15:45 GMT
HIVE-15769: Support view creation in CBO (Pengcheng Xiong, reviewed by Ashutosh Chauhan)


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

Branch: refs/heads/master
Commit: 1c49da87fd68be4c0f012a99fd8531f25bc3658a
Parents: 38ad779
Author: Pengcheng Xiong <pxiong@apache.org>
Authored: Sat Feb 11 13:15:22 2017 -0800
Committer: Pengcheng Xiong <pxiong@apache.org>
Committed: Sat Feb 11 13:15:22 2017 -0800

----------------------------------------------------------------------
 .../calcite/CalciteViewSemanticException.java   |  52 ++
 .../hadoop/hive/ql/parse/CalcitePlanner.java    |  94 ++-
 .../org/apache/hadoop/hive/ql/parse/QB.java     |   4 +
 .../hadoop/hive/ql/parse/SemanticAnalyzer.java  |  25 +-
 ql/src/test/queries/clientpositive/view_cbo.q   |  72 ++
 .../create_or_replace_view4.q.out               |   2 +-
 .../clientnegative/create_view_failure3.q.out   |   2 +-
 .../clientnegative/create_view_failure6.q.out   |   2 +-
 .../clientnegative/create_view_failure7.q.out   |   2 +-
 .../clientnegative/create_view_failure8.q.out   |   2 +-
 .../clientnegative/create_view_failure9.q.out   |   2 +-
 .../selectDistinctStarNeg_1.q.out               |   2 +-
 .../results/clientpositive/create_view.q.out    |  10 +-
 .../clientpositive/create_view_translate.q.out  |   4 +-
 ql/src/test/results/clientpositive/cte_2.q.out  |   4 +-
 ql/src/test/results/clientpositive/cte_4.q.out  |   4 +-
 .../results/clientpositive/explain_ddl.q.out    |   4 +-
 .../clientpositive/explain_dependency.q.out     |   2 +-
 .../clientpositive/explain_logical.q.out        |   2 +-
 .../results/clientpositive/llap/cbo_views.q.out |   2 +-
 .../results/clientpositive/llap/cte_2.q.out     |   4 +-
 .../results/clientpositive/llap/cte_4.q.out     |   4 +-
 .../clientpositive/llap/explainuser_1.q.out     |   4 +-
 .../results/clientpositive/llap/lineage3.q.out  |   2 +-
 .../llap/selectDistinctStar.q.out               |   8 +-
 .../clientpositive/llap/subquery_views.q.out    |   2 +-
 .../clientpositive/llap/union_top_level.q.out   |   4 +-
 .../results/clientpositive/perf/query14.q.out   |   4 +-
 .../clientpositive/spark/union_top_level.q.out  |   4 +-
 .../clientpositive/tez/explainanalyze_3.q.out   |   4 +-
 .../clientpositive/tez/explainuser_3.q.out      |   4 +-
 .../results/clientpositive/view_alias.q.out     |  12 +-
 .../test/results/clientpositive/view_cbo.q.out  | 823 +++++++++++++++++++
 33 files changed, 1090 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/CalciteViewSemanticException.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/CalciteViewSemanticException.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/CalciteViewSemanticException.java
new file mode 100644
index 0000000..3d27bec
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/CalciteViewSemanticException.java
@@ -0,0 +1,52 @@
+/**
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.optimizer.calcite;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Exception from SemanticAnalyzer.
+ */
+
+public class CalciteViewSemanticException extends SemanticException {
+
+  private static final long serialVersionUID = 1L;
+
+  public CalciteViewSemanticException() {
+    super();
+  }
+
+  public CalciteViewSemanticException(String message) {
+    super(message);
+  }
+
+  public CalciteViewSemanticException(Throwable cause) {
+    super(cause);
+  }
+
+  public CalciteViewSemanticException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public CalciteViewSemanticException(ErrorMsg errorMsg, String... msgArgs) {
+    super(errorMsg, msgArgs);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
index 96ff5df..e7687be 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
@@ -139,6 +139,7 @@ import org.apache.hadoop.hive.ql.metadata.VirtualColumn;
 import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException;
 import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException;
 import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException.UnsupportedFeature;
+import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException;
 import org.apache.hadoop.hive.ql.optimizer.calcite.HiveCalciteUtil;
 import org.apache.hadoop.hive.ql.optimizer.calcite.HiveDefaultRelMetadataProvider;
 import org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext;
@@ -300,7 +301,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
       return null;
     }
     ASTNode queryForCbo = ast;
-    if (cboCtx.type == PreCboCtx.Type.CTAS_OR_MV) {
+    if (cboCtx.type == PreCboCtx.Type.CTAS || cboCtx.type == PreCboCtx.Type.VIEW) {
       queryForCbo = cboCtx.nodeOfInterest; // nodeOfInterest is the query
     }
     runCBO = canCBOHandleAst(queryForCbo, getQB(), cboCtx);
@@ -331,7 +332,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
       // table, destination), so if the query is otherwise ok, it is as if we
       // did remove those and gave CBO the proper AST. That is kinda hacky.
       ASTNode queryForCbo = ast;
-      if (cboCtx.type == PreCboCtx.Type.CTAS_OR_MV) {
+      if (cboCtx.type == PreCboCtx.Type.CTAS || cboCtx.type == PreCboCtx.Type.VIEW) {
         queryForCbo = cboCtx.nodeOfInterest; // nodeOfInterest is the query
       }
       runCBO = canCBOHandleAst(queryForCbo, getQB(), cboCtx);
@@ -348,6 +349,9 @@ public class CalcitePlanner extends SemanticAnalyzer {
 
         try {
           if (this.conf.getBoolVar(HiveConf.ConfVars.HIVE_CBO_RETPATH_HIVEOP)) {
+            if (cboCtx.type == PreCboCtx.Type.VIEW && !materializedView) {
+              throw new SemanticException("Create view is not supported in cbo return path.");
+            }
             sinkOp = getOptimizedHiveOPDag();
             LOG.info("CBO Succeeded; optimized logical plan.");
             this.ctx.setCboInfo("Plan optimized by CBO.");
@@ -360,13 +364,20 @@ public class CalcitePlanner extends SemanticAnalyzer {
             newAST = fixUpAfterCbo(ast, newAST, cboCtx);
 
             // 2. Regen OP plan from optimized AST
-            init(false);
-            if (cboCtx.type == PreCboCtx.Type.CTAS_OR_MV) {
-              // Redo create-table/view analysis, because it's not part of doPhase1.
-              if (materializedView) {
+            if (cboCtx.type == PreCboCtx.Type.VIEW && !materializedView) {
+              try {
+                handleCreateViewDDL(newAST);
+              } catch (SemanticException e) {
+                throw new CalciteViewSemanticException(e.getMessage());
+              }
+            } else {
+              init(false);
+              if (cboCtx.type == PreCboCtx.Type.VIEW && materializedView) {
+                // Redo create-table/view analysis, because it's not part of
+                // doPhase1.
                 // Use the REWRITTEN AST
                 setAST(newAST);
-                newAST = reAnalyzeMaterializedViewAfterCbo(newAST);
+                newAST = reAnalyzeViewAfterCbo(newAST);
                 // Store text of the ORIGINAL QUERY
                 String originalText = ctx.getTokenRewriteStream().toString(
                     cboCtx.nodeOfInterest.getTokenStartIndex(),
@@ -375,7 +386,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
                 viewSelect = newAST;
                 viewsExpanded = new ArrayList<>();
                 viewsExpanded.add(createVwDesc.getViewName());
-              } else {
+              } else if (cboCtx.type == PreCboCtx.Type.CTAS) {
                 // CTAS
                 setAST(newAST);
                 newAST = reAnalyzeCTASAfterCbo(newAST);
@@ -427,6 +438,11 @@ public class CalcitePlanner extends SemanticAnalyzer {
             // so avoid executing subqueries on non-cbo
             throw new SemanticException(e);
           }
+          else if( e instanceof CalciteViewSemanticException) {
+            // non-cbo path retries to execute create view and 
+            // we believe it will throw the same error message
+            throw new SemanticException(e);
+          }
           else if (!conf.getBoolVar(ConfVars.HIVE_IN_TEST) || isMissingStats
               || e instanceof CalciteSemanticException ) {
               reAnalyzeAST = true;
@@ -465,6 +481,21 @@ public class CalcitePlanner extends SemanticAnalyzer {
     return sinkOp;
   }
 
+  private void handleCreateViewDDL(ASTNode newAST) throws SemanticException {
+    saveViewDefinition();
+    String originalText = createVwDesc.getViewOriginalText();
+    String expandedText = createVwDesc.getViewExpandedText();
+    List<FieldSchema> schema = createVwDesc.getSchema();
+    List<FieldSchema> partitionColumns = createVwDesc.getPartCols();
+    init(false);
+    setAST(newAST);
+    newAST = reAnalyzeViewAfterCbo(newAST);
+    createVwDesc.setViewOriginalText(originalText);
+    createVwDesc.setViewExpandedText(expandedText);
+    createVwDesc.setSchema(schema);
+    createVwDesc.setPartCols(partitionColumns);
+  }
+
   /*
    * Tries to optimize FROM clause of multi-insert. No attempt to optimize insert clauses of the query.
    * Returns true if rewriting is successful, false otherwise.
@@ -651,9 +682,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
         || qb.isCTAS() || qb.isMaterializedView() || cboCtx.type == PreCboCtx.Type.INSERT
         || cboCtx.type == PreCboCtx.Type.MULTI_INSERT;
     boolean noBadTokens = HiveCalciteUtil.validateASTForUnsupportedTokens(ast);
-    boolean result = isSupportedRoot && isSupportedType
-        && (getCreateViewDesc() == null || getCreateViewDesc().isMaterialized())
-        && noBadTokens;
+    boolean result = isSupportedRoot && isSupportedType && noBadTokens;
 
     if (!result) {
       if (needToLogMessage) {
@@ -665,9 +694,6 @@ public class CalcitePlanner extends SemanticAnalyzer {
           msg += "is not a query with at least one source table "
                   + " or there is a subquery without a source table, or CTAS, or insert; ";
         }
-        if (getCreateViewDesc() != null && !getCreateViewDesc().isMaterialized()) {
-          msg += "has create view; ";
-        }
         if (!noBadTokens) {
           msg += "has unsupported tokens; ";
         }
@@ -835,7 +861,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
    */
   static class PreCboCtx extends PlannerContext {
     enum Type {
-      NONE, INSERT, MULTI_INSERT, CTAS_OR_MV, UNEXPECTED
+      NONE, INSERT, MULTI_INSERT, CTAS, VIEW, UNEXPECTED
     }
 
     private ASTNode nodeOfInterest;
@@ -853,8 +879,13 @@ public class CalcitePlanner extends SemanticAnalyzer {
     }
 
     @Override
-    void setCTASOrMVToken(ASTNode child) {
-      set(PreCboCtx.Type.CTAS_OR_MV, child);
+    void setCTASToken(ASTNode child) {
+      set(PreCboCtx.Type.CTAS, child);
+    }
+
+    @Override
+    void setViewToken(ASTNode child) {
+      set(PreCboCtx.Type.VIEW, child);
     }
 
     @Override
@@ -884,7 +915,8 @@ public class CalcitePlanner extends SemanticAnalyzer {
       // nothing to do
       return newAst;
 
-    case CTAS_OR_MV: {
+    case CTAS:
+    case VIEW: {
       // Patch the optimized query back into original CTAS AST, replacing the
       // original query.
       replaceASTChild(cboCtx.nodeOfInterest, newAst);
@@ -927,7 +959,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
     return newAst;
   }
 
-  ASTNode reAnalyzeMaterializedViewAfterCbo(ASTNode newAst) throws SemanticException {
+  ASTNode reAnalyzeViewAfterCbo(ASTNode newAst) throws SemanticException {
     // analyzeCreateView uses this.ast, but doPhase1 doesn't, so only reset it
     // here.
     newAst = analyzeCreateView(newAst, getQB(), null);
@@ -1245,9 +1277,11 @@ public class CalcitePlanner extends SemanticAnalyzer {
       perfLogger.PerfLogBegin(this.getClass().getName(), PerfLogger.OPTIMIZER);
       try {
         calciteGenPlan = genLogicalPlan(getQB(), true, null, null);
+        // if it is to create view, we do not use table alias
         resultSchema = SemanticAnalyzer.convertRowSchemaToResultSetSchema(
             relToHiveRR.get(calciteGenPlan),
-            HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES));
+            getQB().isView() ? false : HiveConf.getBoolVar(conf,
+                HiveConf.ConfVars.HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES));
       } catch (SemanticException e) {
         semanticException = e;
         throw new RuntimeException(e);
@@ -1848,6 +1882,10 @@ public class CalcitePlanner extends SemanticAnalyzer {
       RexNode calciteJoinCond = null;
       if (joinCond != null) {
         JoinTypeCheckCtx jCtx = new JoinTypeCheckCtx(leftRR, rightRR, hiveJoinType);
+        RowResolver input = RowResolver.getCombinedRR(leftRR, rightRR);
+        if (unparseTranslator != null && unparseTranslator.isEnabled()) {
+          genAllExprNodeDesc(joinCond, input, jCtx);
+        }
         Map<ASTNode, ExprNodeDesc> exprNodes = JoinCondTypeCheckProcFactory.genExprNode(joinCond,
             jCtx);
         if (jCtx.getError() != null) {
@@ -2809,8 +2847,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
           // 4. Construct GB Keys (ExprNode)
           for (int i = 0; i < grpByAstExprs.size(); ++i) {
             ASTNode grpbyExpr = grpByAstExprs.get(i);
-            Map<ASTNode, ExprNodeDesc> astToExprNDescMap = TypeCheckProcFactory.genExprNode(
-                grpbyExpr, new TypeCheckCtx(groupByInputRowResolver));
+            Map<ASTNode, ExprNodeDesc> astToExprNDescMap = genAllExprNodeDesc(grpbyExpr, groupByInputRowResolver);
             ExprNodeDesc grpbyExprNDesc = astToExprNDescMap.get(grpbyExpr);
             if (grpbyExprNDesc == null)
               throw new CalciteSemanticException("Invalid Column Reference: " + grpbyExpr.dump(),
@@ -2959,8 +2996,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
           obASTExpr = (ASTNode) obASTExprLst.get(i);
           nullObASTExpr = (ASTNode) obASTExpr.getChild(0);
           ASTNode ref = (ASTNode) nullObASTExpr.getChild(0);
-          Map<ASTNode, ExprNodeDesc> astToExprNDescMap = TypeCheckProcFactory.genExprNode(
-              obASTExpr, new TypeCheckCtx(inputRR));
+          Map<ASTNode, ExprNodeDesc> astToExprNDescMap = genAllExprNodeDesc(ref, inputRR);
           ExprNodeDesc obExprNDesc = astToExprNDescMap.get(ref);
           if (obExprNDesc == null)
             throw new SemanticException("Invalid order by expression: " + obASTExpr.toString());
@@ -3442,6 +3478,9 @@ public class CalcitePlanner extends SemanticAnalyzer {
           LOG.debug("Find UDTF " + funcName);
           genericUDTF = fi.getGenericUDTF();
           genericUDTFName = funcName;
+          if (!fi.isNative()) {
+            unparseTranslator.addIdentifierTranslation((ASTNode) expr.getChild(0));
+          }
           if (genericUDTF != null && (selectStar = exprType == HiveParser.TOK_FUNCTIONSTAR)) {
             genColListRegex(".*", null, (ASTNode) expr.getChild(0),
                 col_list, null, inputRR, starRR, pos, out_rwsch, qb.getAliases(), false);
@@ -3467,12 +3506,15 @@ public class CalcitePlanner extends SemanticAnalyzer {
           switch (selExprChild.getType()) {
           case HiveParser.Identifier:
             udtfColAliases.add(unescapeIdentifier(selExprChild.getText().toLowerCase()));
+            unparseTranslator.addIdentifierTranslation(selExprChild);
             break;
           case HiveParser.TOK_TABALIAS:
             assert (selExprChild.getChildCount() == 1);
             udtfTableAlias = unescapeIdentifier(selExprChild.getChild(0)
                 .getText());
             qb.addAlias(udtfTableAlias);
+            unparseTranslator.addIdentifierTranslation((ASTNode) selExprChild
+                .getChild(0));
             break;
           default:
             throw new SemanticException("Find invalid token type " + selExprChild.getType()
@@ -3521,6 +3563,10 @@ public class CalcitePlanner extends SemanticAnalyzer {
               inputRR, autogenColAliasPrfxIncludeFuncName(), i);
           tabAlias = colRef[0];
           colAlias = colRef[1];
+          if (hasAsClause) {
+            unparseTranslator.addIdentifierTranslation((ASTNode) child
+                .getChild(1));
+          }
         }
 
         // 6.4 Build ExprNode corresponding to colums

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java
index 59d537f..bfe2ab5 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java
@@ -420,6 +420,10 @@ public class QB {
     return viewDesc != null && viewDesc.isMaterialized();
   }
 
+  public boolean isView() {
+    return viewDesc != null && !viewDesc.isMaterialized();
+  }
+
   void addEncryptedTargetTablePath(Path p) {
     if(encryptedTargetTablePaths == null) {
       encryptedTargetTablePaths = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
index dceb4a5..03ab0c1 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
@@ -10720,7 +10720,10 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
       this.ctx_1 = ctx_1;
     }
 
-    void setCTASOrMVToken(ASTNode child) {
+    void setCTASToken(ASTNode child) {
+    }
+    
+    void setViewToken(ASTNode child) {
     }
 
     void setInsertToken(ASTNode ast, boolean isTmpFileDest) {
@@ -11033,7 +11036,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
     }
 
     // 3. Deduce Resultset Schema
-    if (createVwDesc != null) {
+    if (createVwDesc != null && !this.ctx.isCboSucceeded()) {
       resultSchema = convertRowSchemaToViewSchema(opParseCtx.get(sinkOp).getRowResolver());
     } else {
       // resultSchema will be null if
@@ -11064,7 +11067,10 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
       if (ctx.getExplainAnalyze() == AnalyzeState.RUNNING) {
         return;
       }
-      saveViewDefinition();
+      
+      if (!ctx.isCboSucceeded()) {
+        saveViewDefinition();
+      }
 
       // validate the create view statement at this point, the createVwDesc gets
       // all the information for semanticcheck
@@ -11232,7 +11238,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
     return resultSchema;
   }
 
-  private void saveViewDefinition() throws SemanticException {
+  protected void saveViewDefinition() throws SemanticException {
     // Make a copy of the statement's result schema, since we may
     // modify it below as part of imposing view column names.
     List<FieldSchema> derivedSchema =
@@ -11524,6 +11530,11 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
         continue;
       }
       String[] tmp = input.reverseLookup(columnDesc.getColumn());
+      // in subquery case, tmp may be from outside.
+      if (tmp[0] != null && columnDesc.getTabAlias() != null
+          && !tmp[0].equals(columnDesc.getTabAlias()) && tcCtx.getOuterRR() != null) {
+        tmp = tcCtx.getOuterRR().reverseLookup(columnDesc.getColumn());
+      }
       StringBuilder replacementText = new StringBuilder();
       replacementText.append(HiveUtils.unparseIdentifier(tmp[0], conf));
       replacementText.append(".");
@@ -11807,7 +11818,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
         }
         command_type = CTAS;
         if (plannerCtx != null) {
-          plannerCtx.setCTASOrMVToken(child);
+          plannerCtx.setCTASToken(child);
         }
         selectStmt = child;
         break;
@@ -12084,7 +12095,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
       case HiveParser.TOK_QUERY:
         // For CBO
         if (plannerCtx != null) {
-          plannerCtx.setCTASOrMVToken(child);
+          plannerCtx.setViewToken(child);
         }
         selectStmt = child;
         break;
@@ -12144,7 +12155,6 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
           storageFormat.getSerdeProps());
       addDbAndTabToOutputs(qualTabName, TableType.MATERIALIZED_VIEW);
       queryState.setCommandType(HiveOperation.CREATE_MATERIALIZED_VIEW);
-      qb.setViewDesc(createVwDesc);
     } else {
       createVwDesc = new CreateViewDesc(
           dbDotTable, cols, comment, tblProps, partColNames,
@@ -12155,6 +12165,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
       addDbAndTabToOutputs(qualTabName, TableType.VIRTUAL_VIEW);
       queryState.setCommandType(HiveOperation.CREATEVIEW);
     }
+    qb.setViewDesc(createVwDesc);
 
     return selectStmt;
   }

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/queries/clientpositive/view_cbo.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/view_cbo.q b/ql/src/test/queries/clientpositive/view_cbo.q
new file mode 100644
index 0000000..4172678
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/view_cbo.q
@@ -0,0 +1,72 @@
+set hive.mapred.mode=nonstrict;
+-- SORT_QUERY_RESULTS
+
+explain
+select key, value, avg(key + 1) from src
+group by value, key with rollup
+order by key, value limit 20;
+
+drop view v;
+create view v as
+with q1 as ( select key from src where key = '5')
+select * from q1;
+desc formatted v;
+
+drop view v;
+create view v as
+select b.key, count(*) as c
+from src b
+group by b.key
+having exists
+  (select a.key
+  from src a
+  where a.key = b.key and a.value > 'val_9'
+  )
+;
+desc formatted v;
+
+drop view v;
+create view v as
+select *
+from src b
+where not exists
+  (select distinct a.key
+  from src a
+  where b.value = a.value and a.value > 'val_2'
+  )
+;
+desc formatted v;
+
+drop view v;
+create view v as select a.key from src a join src b on a.key=b.key;
+desc formatted v;
+
+CREATE VIEW view15 AS
+SELECT key,COUNT(value) AS value_count
+FROM src
+GROUP BY key;
+desc formatted view15;
+
+CREATE VIEW view16 AS
+SELECT DISTINCT value
+FROM src;
+
+desc formatted view16;
+
+drop view v;
+create view v as select key from src;
+desc formatted v;
+
+drop view v;
+create view v as select * from src;
+desc formatted v;
+
+drop view v;
+create view v as select * from src intersect select * from src;
+desc formatted v;
+
+drop view v;
+create view v as select * from src except select * from src;
+desc formatted v;
+
+explain select * from v;

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/create_or_replace_view4.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_or_replace_view4.q.out b/ql/src/test/results/clientnegative/create_or_replace_view4.q.out
index b83939f..767cc77 100644
--- a/ql/src/test/results/clientnegative/create_or_replace_view4.q.out
+++ b/ql/src/test/results/clientnegative/create_or_replace_view4.q.out
@@ -14,4 +14,4 @@ POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v
 POSTHOOK: Lineage: v.key SIMPLE [(srcpart)srcpart.FieldSchema(name:key, type:string, comment:default), ]
 POSTHOOK: Lineage: v.value SIMPLE [(srcpart)srcpart.FieldSchema(name:value, type:string, comment:default), ]
-FAILED: SemanticException [Error 10092]: At least one non-partitioning column must be present in view
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: At least one non-partitioning column must be present in view

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/create_view_failure3.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_view_failure3.q.out b/ql/src/test/results/clientnegative/create_view_failure3.q.out
index 5ddbdb6..8b79272 100644
--- a/ql/src/test/results/clientnegative/create_view_failure3.q.out
+++ b/ql/src/test/results/clientnegative/create_view_failure3.q.out
@@ -2,4 +2,4 @@ PREHOOK: query: DROP VIEW xxx13
 PREHOOK: type: DROPVIEW
 POSTHOOK: query: DROP VIEW xxx13
 POSTHOOK: type: DROPVIEW
-FAILED: SemanticException 5:16 The number of columns produced by the SELECT clause does not match the number of column names specified by CREATE VIEW. Error encountered near token 'key'
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: 5:16 The number of columns produced by the SELECT clause does not match the number of column names specified by CREATE VIEW. Error encountered near token 'key'

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/create_view_failure6.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_view_failure6.q.out b/ql/src/test/results/clientnegative/create_view_failure6.q.out
index 25c1c7f..6d9fb64 100644
--- a/ql/src/test/results/clientnegative/create_view_failure6.q.out
+++ b/ql/src/test/results/clientnegative/create_view_failure6.q.out
@@ -2,4 +2,4 @@ PREHOOK: query: DROP VIEW xxx15
 PREHOOK: type: DROPVIEW
 POSTHOOK: query: DROP VIEW xxx15
 POSTHOOK: type: DROPVIEW
-FAILED: SemanticException [Error 10093]: Rightmost columns in view output do not match PARTITIONED ON clause
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: Rightmost columns in view output do not match PARTITIONED ON clause

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/create_view_failure7.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_view_failure7.q.out b/ql/src/test/results/clientnegative/create_view_failure7.q.out
index f13ab63..337dbe8 100644
--- a/ql/src/test/results/clientnegative/create_view_failure7.q.out
+++ b/ql/src/test/results/clientnegative/create_view_failure7.q.out
@@ -2,4 +2,4 @@ PREHOOK: query: DROP VIEW xxx16
 PREHOOK: type: DROPVIEW
 POSTHOOK: query: DROP VIEW xxx16
 POSTHOOK: type: DROPVIEW
-FAILED: SemanticException [Error 10092]: At least one non-partitioning column must be present in view
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: At least one non-partitioning column must be present in view

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/create_view_failure8.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_view_failure8.q.out b/ql/src/test/results/clientnegative/create_view_failure8.q.out
index 158fed1..cccb7e4 100644
--- a/ql/src/test/results/clientnegative/create_view_failure8.q.out
+++ b/ql/src/test/results/clientnegative/create_view_failure8.q.out
@@ -2,4 +2,4 @@ PREHOOK: query: DROP VIEW xxx17
 PREHOOK: type: DROPVIEW
 POSTHOOK: query: DROP VIEW xxx17
 POSTHOOK: type: DROPVIEW
-FAILED: SemanticException [Error 10093]: Rightmost columns in view output do not match PARTITIONED ON clause
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: Rightmost columns in view output do not match PARTITIONED ON clause

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/create_view_failure9.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_view_failure9.q.out b/ql/src/test/results/clientnegative/create_view_failure9.q.out
index e6ad388..eac8cb4 100644
--- a/ql/src/test/results/clientnegative/create_view_failure9.q.out
+++ b/ql/src/test/results/clientnegative/create_view_failure9.q.out
@@ -2,4 +2,4 @@ PREHOOK: query: DROP VIEW xxx18
 PREHOOK: type: DROPVIEW
 POSTHOOK: query: DROP VIEW xxx18
 POSTHOOK: type: DROPVIEW
-FAILED: SemanticException [Error 10093]: Rightmost columns in view output do not match PARTITIONED ON clause
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: Rightmost columns in view output do not match PARTITIONED ON clause

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientnegative/selectDistinctStarNeg_1.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/selectDistinctStarNeg_1.q.out b/ql/src/test/results/clientnegative/selectDistinctStarNeg_1.q.out
index 2d97755..9496e52 100644
--- a/ql/src/test/results/clientnegative/selectDistinctStarNeg_1.q.out
+++ b/ql/src/test/results/clientnegative/selectDistinctStarNeg_1.q.out
@@ -2,4 +2,4 @@ PREHOOK: query: drop view if exists v
 PREHOOK: type: DROPVIEW
 POSTHOOK: query: drop view if exists v
 POSTHOOK: type: DROPVIEW
-FAILED: SemanticException [Error 10036]: Duplicate column name: key
+FAILED: SemanticException org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException: Duplicate column name: key

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/create_view.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/create_view.q.out b/ql/src/test/results/clientpositive/create_view.q.out
index 7deac3e..d3b858a 100644
--- a/ql/src/test/results/clientpositive/create_view.q.out
+++ b/ql/src/test/results/clientpositive/create_view.q.out
@@ -162,10 +162,10 @@ POSTHOOK: query: EXPLAIN
 CREATE VIEW view0(valoo) AS SELECT upper(value) FROM src WHERE key=86
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false
@@ -720,7 +720,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@table1
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@view8
-POSTHOOK: Lineage: view8.c EXPRESSION []
+POSTHOOK: Lineage: view8.c SIMPLE []
 PREHOOK: query: DESCRIBE EXTENDED view8
 PREHOOK: type: DESCTABLE
 PREHOOK: Input: default@view8
@@ -1279,8 +1279,8 @@ POSTHOOK: Output: database:default
 POSTHOOK: Output: default@view14
 POSTHOOK: Lineage: view14.k1 EXPRESSION [(src)s2.FieldSchema(name:key, type:string, comment:default), ]
 POSTHOOK: Lineage: view14.k2 EXPRESSION [(src)s4.FieldSchema(name:key, type:string, comment:default), ]
-POSTHOOK: Lineage: view14.v1 EXPRESSION [(src)s1.null, (src)s2.FieldSchema(name:value, type:string, comment:default), ]
-POSTHOOK: Lineage: view14.v2 EXPRESSION [(src)s3.null, (src)s4.FieldSchema(name:value, type:string, comment:default), ]
+POSTHOOK: Lineage: view14.v1 EXPRESSION [(src)s2.FieldSchema(name:value, type:string, comment:default), ]
+POSTHOOK: Lineage: view14.v2 EXPRESSION [(src)s4.FieldSchema(name:value, type:string, comment:default), ]
 PREHOOK: query: DESCRIBE EXTENDED view14
 PREHOOK: type: DESCTABLE
 PREHOOK: Input: default@view14

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/create_view_translate.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/create_view_translate.q.out b/ql/src/test/results/clientpositive/create_view_translate.q.out
index 78614f7..db9fd78 100644
--- a/ql/src/test/results/clientpositive/create_view_translate.q.out
+++ b/ql/src/test/results/clientpositive/create_view_translate.q.out
@@ -131,10 +131,10 @@ POSTHOOK: query: explain
 CREATE VIEW priceview AS SELECT items.id, items.info['price'] FROM items
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/cte_2.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/cte_2.q.out b/ql/src/test/results/clientpositive/cte_2.q.out
index c2bc565..4c9af87 100644
--- a/ql/src/test/results/clientpositive/cte_2.q.out
+++ b/ql/src/test/results/clientpositive/cte_2.q.out
@@ -118,7 +118,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: select * from v1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
@@ -154,7 +154,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: with q1 as ( select key from src where key = '4')
 select * from v1
 PREHOOK: type: QUERY

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/cte_4.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/cte_4.q.out b/ql/src/test/results/clientpositive/cte_4.q.out
index ce92dca..dbe4140 100644
--- a/ql/src/test/results/clientpositive/cte_4.q.out
+++ b/ql/src/test/results/clientpositive/cte_4.q.out
@@ -148,7 +148,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: select * from v1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
@@ -184,7 +184,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: with q1 as ( select key from src where key = '4')
 select * from v1
 PREHOOK: type: QUERY

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/explain_ddl.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/explain_ddl.q.out b/ql/src/test/results/clientpositive/explain_ddl.q.out
index ee2a60a..e108e22 100644
--- a/ql/src/test/results/clientpositive/explain_ddl.q.out
+++ b/ql/src/test/results/clientpositive/explain_ddl.q.out
@@ -417,10 +417,10 @@ PREHOOK: type: CREATEVIEW
 POSTHOOK: query: EXPLAIN CREATE VIEW V1 AS select * from M1
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/explain_dependency.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/explain_dependency.q.out b/ql/src/test/results/clientpositive/explain_dependency.q.out
index 6ab41c7..070da56 100644
--- a/ql/src/test/results/clientpositive/explain_dependency.q.out
+++ b/ql/src/test/results/clientpositive/explain_dependency.q.out
@@ -128,7 +128,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@srcpart
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@V5
-POSTHOOK: Lineage: V5.ds SIMPLE [(srcpart)srcpart.FieldSchema(name:ds, type:string, comment:null), ]
+POSTHOOK: Lineage: V5.ds SIMPLE []
 POSTHOOK: Lineage: V5.hr SIMPLE [(srcpart)srcpart.FieldSchema(name:hr, type:string, comment:null), ]
 POSTHOOK: Lineage: V5.key SIMPLE [(srcpart)srcpart.FieldSchema(name:key, type:string, comment:default), ]
 POSTHOOK: Lineage: V5.value SIMPLE [(srcpart)srcpart.FieldSchema(name:value, type:string, comment:default), ]

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/explain_logical.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/explain_logical.q.out b/ql/src/test/results/clientpositive/explain_logical.q.out
index d1176c1..fb91a3b 100644
--- a/ql/src/test/results/clientpositive/explain_logical.q.out
+++ b/ql/src/test/results/clientpositive/explain_logical.q.out
@@ -472,7 +472,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@srcpart
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@V5
-POSTHOOK: Lineage: V5.ds SIMPLE [(srcpart)srcpart.FieldSchema(name:ds, type:string, comment:null), ]
+POSTHOOK: Lineage: V5.ds SIMPLE []
 POSTHOOK: Lineage: V5.hr SIMPLE [(srcpart)srcpart.FieldSchema(name:hr, type:string, comment:null), ]
 POSTHOOK: Lineage: V5.key SIMPLE [(srcpart)srcpart.FieldSchema(name:key, type:string, comment:default), ]
 POSTHOOK: Lineage: V5.value SIMPLE [(srcpart)srcpart.FieldSchema(name:value, type:string, comment:default), ]

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/cbo_views.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/cbo_views.q.out b/ql/src/test/results/clientpositive/llap/cbo_views.q.out
index 2ac2d3a..44e5501 100644
--- a/ql/src/test/results/clientpositive/llap/cbo_views.q.out
+++ b/ql/src/test/results/clientpositive/llap/cbo_views.q.out
@@ -173,7 +173,7 @@ POSTHOOK: Input: default@cbo_t1
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v4
 POSTHOOK: Lineage: v4.c_int SIMPLE [(cbo_t1)cbo_t1.FieldSchema(name:c_int, type:int, comment:null), ]
-POSTHOOK: Lineage: v4.key SIMPLE [(cbo_t1)cbo_t1.FieldSchema(name:key, type:string, comment:null), ]
+POSTHOOK: Lineage: v4.key SIMPLE []
 PREHOOK: query: with q1 as ( select c_int from q2 where c_boolean = false),
 q2 as ( select c_int,c_boolean from v1  where value = '1')
 select sum(c_int) from (select c_int from q1) a

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/cte_2.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/cte_2.q.out b/ql/src/test/results/clientpositive/llap/cte_2.q.out
index ef66c40..16906c1 100644
--- a/ql/src/test/results/clientpositive/llap/cte_2.q.out
+++ b/ql/src/test/results/clientpositive/llap/cte_2.q.out
@@ -118,7 +118,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: select * from v1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
@@ -154,7 +154,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: with q1 as ( select key from src where key = '4')
 select * from v1
 PREHOOK: type: QUERY

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/cte_4.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/cte_4.q.out b/ql/src/test/results/clientpositive/llap/cte_4.q.out
index ce92dca..dbe4140 100644
--- a/ql/src/test/results/clientpositive/llap/cte_4.q.out
+++ b/ql/src/test/results/clientpositive/llap/cte_4.q.out
@@ -148,7 +148,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: select * from v1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
@@ -184,7 +184,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v1
-POSTHOOK: Lineage: v1.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: v1.key SIMPLE []
 PREHOOK: query: with q1 as ( select key from src where key = '4')
 select * from v1
 PREHOOK: type: QUERY

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/explainuser_1.q.out b/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
index 621f337..21fd10c 100644
--- a/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
+++ b/ql/src/test/results/clientpositive/llap/explainuser_1.q.out
@@ -5178,9 +5178,9 @@ sum(p_retailprice) as s
 from part 
 group by p_mfgr, p_brand
 POSTHOOK: type: CREATEVIEW
-Plan not optimized by CBO.
+Plan optimized by CBO.
 
-Stage-0
+Stage-1
   Create View Operator:
     name:default.mfgr_price_view,original text:select p_mfgr, p_brand, 
 sum(p_retailprice) as s 

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/lineage3.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/lineage3.q.out b/ql/src/test/results/clientpositive/llap/lineage3.q.out
index 495ad09..2f53e60 100644
--- a/ql/src/test/results/clientpositive/llap/lineage3.q.out
+++ b/ql/src/test/results/clientpositive/llap/lineage3.q.out
@@ -297,7 +297,7 @@ PREHOOK: type: CREATEVIEW
 PREHOOK: Input: default@alltypesorc
 PREHOOK: Output: database:default
 PREHOOK: Output: default@dest_v3
-{"version":"1.0","engine":"tez","database":"default","hash":"a0c2481ce1c24895a43a950f93a10da7","queryText":"create view dest_v3 (a1, a2, a3, a4, a5, a6, a7) as\n  select x.csmallint, x.cbigint bint1, x.ctinyint, c.cbigint bint2, x.cint, x.cfloat, c.cstring1\n  from alltypesorc c\n  join (\n     select a.csmallint csmallint, a.ctinyint ctinyint, a.cstring2 cstring2,\n           a.cint cint, a.cstring1 ctring1, b.cfloat cfloat, b.cbigint cbigint\n     from ( select * from alltypesorc a where cboolean1=true ) a\n     join alltypesorc b on (a.csmallint = b.cint)\n   ) x on (x.ctinyint = c.cbigint)\n  where x.csmallint=11\n  and x.cint > 899\n  and x.cfloat > 4.5\n  and c.cstring1 < '7'\n  and x.cint + x.cfloat + length(c.cstring1) < 1000","edges":[{"sources":[7],"targets":[0],"edgeType":"PROJECTION"},{"sources":[8],"targets":[1,2],"edgeType":"PROJECTION"},{"sources":[9],"targets":[3],"edgeType":"PROJECTION"},{"sources":[10],"targets":[4],"edgeType":"PROJECTION"},{"sources":[11],"targets
 ":[5],"edgeType":"PROJECTION"},{"sources":[12],"targets":[6],"edgeType":"PROJECTION"},{"sources":[8,9],"targets":[0,1,3,2,4,5,6],"expression":"(c.cbigint = UDFToLong(x._col1))","edgeType":"PREDICATE"},{"sources":[13],"targets":[0,1,3,2,4,5,6],"expression":"(a.cboolean1 = true)","edgeType":"PREDICATE"},{"sources":[7,10],"targets":[0,1,3,2,4,5,6],"expression":"(UDFToInteger(a._col1) = b.cint)","edgeType":"PREDICATE"},{"sources":[7,10,11,12],"targets":[0,1,3,2,4,5,6],"expression":"((x.csmallint = 11) and (x.cint > 899) and (x.cfloat > 4.5) and (c.cstring1 < '7') and (((x.cint + x.cfloat) + length(c.cstring1)) < 1000))","edgeType":"PREDICATE"}],"vertices":[{"id":0,"vertexType":"COLUMN","vertexId":"default.dest_v3.csmallint"},{"id":1,"vertexType":"COLUMN","vertexId":"default.dest_v3.bint1"},{"id":2,"vertexType":"COLUMN","vertexId":"default.dest_v3.bint2"},{"id":3,"vertexType":"COLUMN","vertexId":"default.dest_v3.ctinyint"},{"id":4,"vertexType":"COLUMN","vertexId":"default.dest_v3.cint"},
 {"id":5,"vertexType":"COLUMN","vertexId":"default.dest_v3.cfloat"},{"id":6,"vertexType":"COLUMN","vertexId":"default.dest_v3.cstring1"},{"id":7,"vertexType":"COLUMN","vertexId":"default.alltypesorc.csmallint"},{"id":8,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cbigint"},{"id":9,"vertexType":"COLUMN","vertexId":"default.alltypesorc.ctinyint"},{"id":10,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cint"},{"id":11,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cfloat"},{"id":12,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cstring1"},{"id":13,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cboolean1"}]}
+{"version":"1.0","engine":"tez","database":"default","hash":"a0c2481ce1c24895a43a950f93a10da7","queryText":"create view dest_v3 (a1, a2, a3, a4, a5, a6, a7) as\n  select x.csmallint, x.cbigint bint1, x.ctinyint, c.cbigint bint2, x.cint, x.cfloat, c.cstring1\n  from alltypesorc c\n  join (\n     select a.csmallint csmallint, a.ctinyint ctinyint, a.cstring2 cstring2,\n           a.cint cint, a.cstring1 ctring1, b.cfloat cfloat, b.cbigint cbigint\n     from ( select * from alltypesorc a where cboolean1=true ) a\n     join alltypesorc b on (a.csmallint = b.cint)\n   ) x on (x.ctinyint = c.cbigint)\n  where x.csmallint=11\n  and x.cint > 899\n  and x.cfloat > 4.5\n  and c.cstring1 < '7'\n  and x.cint + x.cfloat + length(c.cstring1) < 1000","edges":[{"sources":[],"targets":[0],"expression":"11","edgeType":"PROJECTION"},{"sources":[7],"targets":[1,2],"edgeType":"PROJECTION"},{"sources":[8],"targets":[3],"edgeType":"PROJECTION"},{"sources":[9],"targets":[4],"edgeType":"PROJECTION"},{"source
 s":[10],"targets":[5],"edgeType":"PROJECTION"},{"sources":[11],"targets":[6],"edgeType":"PROJECTION"},{"sources":[11,7],"targets":[0,1,3,2,4,5,6],"expression":"((c.cstring1 < '7') and c.cbigint is not null)","edgeType":"PREDICATE"},{"sources":[7,8],"targets":[0,1,3,2,4,5,6],"expression":"(c.cbigint = UDFToLong(a.ctinyint))","edgeType":"PREDICATE"},{"sources":[10,9],"targets":[0,1,3,2,4,5,6],"expression":"((b.cfloat > 4.5) and (11 = b.cint))","edgeType":"PREDICATE"},{"sources":[12,13,9,8],"targets":[0,1,3,2,4,5,6],"expression":"(a.cboolean1 and (a.csmallint = 11) and (a.cint > 899) and a.ctinyint is not null)","edgeType":"PREDICATE"},{"sources":[9,10,11],"targets":[0,1,3,2,4,5,6],"expression":"(((UDFToFloat(a.cint) + b.cfloat) + UDFToFloat(length(c.cstring1))) < 1000.0)","edgeType":"PREDICATE"}],"vertices":[{"id":0,"vertexType":"COLUMN","vertexId":"default.dest_v3.csmallint"},{"id":1,"vertexType":"COLUMN","vertexId":"default.dest_v3.bint1"},{"id":2,"vertexType":"COLUMN","vertexId":"d
 efault.dest_v3.bint2"},{"id":3,"vertexType":"COLUMN","vertexId":"default.dest_v3.ctinyint"},{"id":4,"vertexType":"COLUMN","vertexId":"default.dest_v3.cint"},{"id":5,"vertexType":"COLUMN","vertexId":"default.dest_v3.cfloat"},{"id":6,"vertexType":"COLUMN","vertexId":"default.dest_v3.cstring1"},{"id":7,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cbigint"},{"id":8,"vertexType":"COLUMN","vertexId":"default.alltypesorc.ctinyint"},{"id":9,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cint"},{"id":10,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cfloat"},{"id":11,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cstring1"},{"id":12,"vertexType":"COLUMN","vertexId":"default.alltypesorc.cboolean1"},{"id":13,"vertexType":"COLUMN","vertexId":"default.alltypesorc.csmallint"}]}
 PREHOOK: query: alter view dest_v3 as
   select * from (
     select sum(a.ctinyint) over (partition by a.csmallint order by a.csmallint) a,

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/selectDistinctStar.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/selectDistinctStar.q.out b/ql/src/test/results/clientpositive/llap/selectDistinctStar.q.out
index afb9c4f..c5ca782 100644
--- a/ql/src/test/results/clientpositive/llap/selectDistinctStar.q.out
+++ b/ql/src/test/results/clientpositive/llap/selectDistinctStar.q.out
@@ -1343,10 +1343,10 @@ PREHOOK: type: CREATEVIEW
 POSTHOOK: query: explain create view sdi as select distinct * from src order by key limit 2
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false
@@ -3807,10 +3807,10 @@ PREHOOK: type: CREATEVIEW
 POSTHOOK: query: explain create view sdi as select distinct * from src order by key limit 2
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/subquery_views.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/subquery_views.q.out b/ql/src/test/results/clientpositive/llap/subquery_views.q.out
index 185f08e..d3fdec0 100644
--- a/ql/src/test/results/clientpositive/llap/subquery_views.q.out
+++ b/ql/src/test/results/clientpositive/llap/subquery_views.q.out
@@ -807,7 +807,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@cv3
-POSTHOOK: Lineage: cv3._c2 EXPRESSION [(src)b.null, ]
+POSTHOOK: Lineage: cv3._c2 EXPRESSION [(src)b.null, (src)src.null, ]
 POSTHOOK: Lineage: cv3.key SIMPLE [(src)b.FieldSchema(name:key, type:string, comment:default), ]
 POSTHOOK: Lineage: cv3.value SIMPLE [(src)b.FieldSchema(name:value, type:string, comment:default), ]
 PREHOOK: query: describe extended cv3

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/llap/union_top_level.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/llap/union_top_level.q.out b/ql/src/test/results/clientpositive/llap/union_top_level.q.out
index de23f48..52926b6 100644
--- a/ql/src/test/results/clientpositive/llap/union_top_level.q.out
+++ b/ql/src/test/results/clientpositive/llap/union_top_level.q.out
@@ -1100,10 +1100,10 @@ union all
 select * from (select key, 2 as value from src where key % 3 == 2 limit 3)c
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/perf/query14.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query14.q.out b/ql/src/test/results/clientpositive/perf/query14.q.out
index 55a2e5b..332d43a 100644
--- a/ql/src/test/results/clientpositive/perf/query14.q.out
+++ b/ql/src/test/results/clientpositive/perf/query14.q.out
@@ -1,9 +1,9 @@
-Warning: Shuffle Join MERGEJOIN[914][tables = [$hdt$_1, $hdt$_2]] in Stage 'Reducer 61' is a cross product
-Warning: Shuffle Join MERGEJOIN[915][tables = [$hdt$_1, $hdt$_2, $hdt$_0]] in Stage 'Reducer 62' is a cross product
 Warning: Shuffle Join MERGEJOIN[912][tables = [$hdt$_1, $hdt$_2]] in Stage 'Reducer 5' is a cross product
 Warning: Shuffle Join MERGEJOIN[913][tables = [$hdt$_1, $hdt$_2, $hdt$_0]] in Stage 'Reducer 6' is a cross product
 Warning: Shuffle Join MERGEJOIN[916][tables = [$hdt$_1, $hdt$_2]] in Stage 'Reducer 114' is a cross product
 Warning: Shuffle Join MERGEJOIN[917][tables = [$hdt$_1, $hdt$_2, $hdt$_0]] in Stage 'Reducer 115' is a cross product
+Warning: Shuffle Join MERGEJOIN[914][tables = [$hdt$_1, $hdt$_2]] in Stage 'Reducer 61' is a cross product
+Warning: Shuffle Join MERGEJOIN[915][tables = [$hdt$_1, $hdt$_2, $hdt$_0]] in Stage 'Reducer 62' is a cross product
 PREHOOK: query: explain
 with  cross_items as
  (select i_item_sk ss_item_sk

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/spark/union_top_level.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_top_level.q.out b/ql/src/test/results/clientpositive/spark/union_top_level.q.out
index 74719bb..6adf6c4 100644
--- a/ql/src/test/results/clientpositive/spark/union_top_level.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_top_level.q.out
@@ -969,10 +969,10 @@ union all
 select * from (select key, 2 as value from src where key % 3 == 2 limit 3)c
 POSTHOOK: type: CREATEVIEW
 STAGE DEPENDENCIES:
-  Stage-0 is a root stage
+  Stage-1 is a root stage
 
 STAGE PLANS:
-  Stage: Stage-0
+  Stage: Stage-1
       Create View Operator:
         Create View
           or replace: false

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/tez/explainanalyze_3.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/tez/explainanalyze_3.q.out b/ql/src/test/results/clientpositive/tez/explainanalyze_3.q.out
index 9f1a401..dd8849d 100644
--- a/ql/src/test/results/clientpositive/tez/explainanalyze_3.q.out
+++ b/ql/src/test/results/clientpositive/tez/explainanalyze_3.q.out
@@ -573,9 +573,9 @@ PREHOOK: type: CREATEVIEW
 POSTHOOK: query: explain analyze create view v as with cte as (select * from src  order by key limit 5)
 select * from cte
 POSTHOOK: type: CREATEVIEW
-Plan not optimized by CBO.
+Plan optimized by CBO.
 
-Stage-0
+Stage-1
   Create View Operator:
     name:default.v,original text:with cte as (select * from src  order by key limit 5)
 select * from cte

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/tez/explainuser_3.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/tez/explainuser_3.q.out b/ql/src/test/results/clientpositive/tez/explainuser_3.q.out
index 17c9ec3..ef71d73 100644
--- a/ql/src/test/results/clientpositive/tez/explainuser_3.q.out
+++ b/ql/src/test/results/clientpositive/tez/explainuser_3.q.out
@@ -435,9 +435,9 @@ PREHOOK: type: CREATEVIEW
 POSTHOOK: query: explain create view v as with cte as (select * from src  order by key limit 5)
 select * from cte
 POSTHOOK: type: CREATEVIEW
-Plan not optimized by CBO.
+Plan optimized by CBO.
 
-Stage-0
+Stage-1
   Create View Operator:
     name:default.v,original text:with cte as (select * from src  order by key limit 5)
 select * from cte

http://git-wip-us.apache.org/repos/asf/hive/blob/1c49da87/ql/src/test/results/clientpositive/view_alias.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/view_alias.q.out b/ql/src/test/results/clientpositive/view_alias.q.out
index 0d7e72f..90bf28d 100644
--- a/ql/src/test/results/clientpositive/view_alias.q.out
+++ b/ql/src/test/results/clientpositive/view_alias.q.out
@@ -146,7 +146,7 @@ POSTHOOK: type: CREATEVIEW
 POSTHOOK: Input: default@src
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v
-POSTHOOK: Lineage: v._c2 SIMPLE []
+POSTHOOK: Lineage: v._c1 SIMPLE []
 POSTHOOK: Lineage: v.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
 POSTHOOK: Lineage: v.value SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
 PREHOOK: query: desc formatted v
@@ -159,7 +159,7 @@ POSTHOOK: Input: default@v
 	 	 
 key                 	string              	                    
 value               	string              	                    
-_c2                 	string              	                    
+_c1                 	string              	                    
 	 	 
 # Detailed Table Information	 	 
 Database:           	default             	 
@@ -390,8 +390,8 @@ POSTHOOK: Input: default@b
 POSTHOOK: Output: database:default
 POSTHOOK: Output: default@v
 POSTHOOK: Lineage: v._c0 SIMPLE []
-POSTHOOK: Lineage: v._c3 SIMPLE []
-POSTHOOK: Lineage: v._c6 SIMPLE []
+POSTHOOK: Lineage: v._c2 SIMPLE []
+POSTHOOK: Lineage: v._c4 SIMPLE []
 POSTHOOK: Lineage: v.ca SIMPLE [(a)a.FieldSchema(name:ca, type:string, comment:null), ]
 POSTHOOK: Lineage: v.caa SIMPLE [(a)a.FieldSchema(name:caa, type:string, comment:null), ]
 POSTHOOK: Lineage: v.cb SIMPLE [(b)b.FieldSchema(name:cb, type:string, comment:null), ]
@@ -407,10 +407,10 @@ POSTHOOK: Input: default@v
 _c0                 	string              	                    
 ca                  	string              	                    
 caa                 	string              	                    
-_c3                 	int                 	                    
+_c2                 	int                 	                    
 cb                  	string              	                    
 cbb                 	string              	                    
-_c6                 	int                 	                    
+_c4                 	int                 	                    
 	 	 
 # Detailed Table Information	 	 
 Database:           	default             	 


Mime
View raw message