Index: ql/src/test/results/clientpositive/cbo_correctness.q.out =================================================================== --- ql/src/test/results/clientpositive/cbo_correctness.q.out (revision 1615993) +++ ql/src/test/results/clientpositive/cbo_correctness.q.out (working copy) @@ -15946,3 +15946,94 @@ 1.0 1 1.0 1 2 1.0 2.0 1.0 2.0 1 2 NULL NULL NULL NULL 0 NULL 0.0 NULL NULL NULL NULL NULL NULL NULL NULL 0 NULL 0.0 NULL NULL NULL NULL +PREHOOK: query: create view v1 as select c_int, value, c_boolean from t1 +PREHOOK: type: CREATEVIEW +PREHOOK: Input: default@t1 +POSTHOOK: query: create view v1 as select c_int, value, c_boolean from t1 +POSTHOOK: type: CREATEVIEW +POSTHOOK: Input: default@t1 +POSTHOOK: Output: default@v1 +PREHOOK: query: create view v2 as select c_int, value from t2 +PREHOOK: type: CREATEVIEW +PREHOOK: Input: default@t2 +POSTHOOK: query: create view v2 as select c_int, value from t2 +POSTHOOK: type: CREATEVIEW +POSTHOOK: Input: default@t2 +POSTHOOK: Output: default@v2 +PREHOOK: query: select value from v1 where c_boolean=false +PREHOOK: type: QUERY +PREHOOK: Input: default@t1 +PREHOOK: Input: default@v1 +#### A masked pattern was here #### +POSTHOOK: query: select value from v1 where c_boolean=false +POSTHOOK: type: QUERY +POSTHOOK: Input: default@t1 +POSTHOOK: Input: default@v1 +#### A masked pattern was here #### +1 +1 +PREHOOK: query: select max(c_int) from v1 group by (c_boolean) +PREHOOK: type: QUERY +PREHOOK: Input: default@t1 +PREHOOK: Input: default@v1 +#### A masked pattern was here #### +POSTHOOK: query: select max(c_int) from v1 group by (c_boolean) +POSTHOOK: type: QUERY +POSTHOOK: Input: default@t1 +POSTHOOK: Input: default@v1 +#### A masked pattern was here #### +NULL +1 +1 +PREHOOK: query: select count(v1.c_int) from v1 join t2 on v1.c_int = t2.c_int +PREHOOK: type: QUERY +PREHOOK: Input: default@t1 +PREHOOK: Input: default@t2 +PREHOOK: Input: default@v1 +#### A masked pattern was here #### +POSTHOOK: query: select count(v1.c_int) from v1 join t2 on v1.c_int = t2.c_int +POSTHOOK: type: QUERY +POSTHOOK: Input: default@t1 +POSTHOOK: Input: default@t2 +POSTHOOK: Input: default@v1 +#### A masked pattern was here #### +234 +PREHOOK: query: select count(v1.c_int) from v1 join v2 on v1.c_int = v2.c_int +PREHOOK: type: QUERY +PREHOOK: Input: default@t1 +PREHOOK: Input: default@t2 +PREHOOK: Input: default@v1 +PREHOOK: Input: default@v2 +#### A masked pattern was here #### +POSTHOOK: query: select count(v1.c_int) from v1 join v2 on v1.c_int = v2.c_int +POSTHOOK: type: QUERY +POSTHOOK: Input: default@t1 +POSTHOOK: Input: default@t2 +POSTHOOK: Input: default@v1 +POSTHOOK: Input: default@v2 +#### A masked pattern was here #### +234 +PREHOOK: query: create view v3 as select v1.value from v1 join t1 on v1.c_boolean = t1.c_boolean +PREHOOK: type: CREATEVIEW +PREHOOK: Input: default@t1 +PREHOOK: Input: default@v1 +POSTHOOK: query: create view v3 as select v1.value from v1 join t1 on v1.c_boolean = t1.c_boolean +POSTHOOK: type: CREATEVIEW +POSTHOOK: Input: default@t1 +POSTHOOK: Input: default@v1 +POSTHOOK: Output: default@v3 +PREHOOK: query: select * from v3 limit 3 +PREHOOK: type: QUERY +PREHOOK: Input: default@t1 +PREHOOK: Input: default@v1 +PREHOOK: Input: default@v3 +#### A masked pattern was here #### +POSTHOOK: query: select * from v3 limit 3 +POSTHOOK: type: QUERY +POSTHOOK: Input: default@t1 +POSTHOOK: Input: default@v1 +POSTHOOK: Input: default@v3 +#### A masked pattern was here #### +1 +1 +1 Index: ql/src/test/queries/clientpositive/cbo_correctness.q =================================================================== --- ql/src/test/queries/clientpositive/cbo_correctness.q (revision 1615993) +++ ql/src/test/queries/clientpositive/cbo_correctness.q (working copy) @@ -180,5 +180,16 @@ select * from (select max(c_int) over (partition by key order by value Rows UNBOUNDED PRECEDING), min(c_int) over (partition by key order by value rows current row), count(c_int) over(partition by key order by value ROWS 1 PRECEDING), avg(value) over (partition by key order by value Rows between unbounded preceding and unbounded following), sum(value) over (partition by key order by value rows between unbounded preceding and current row), avg(c_float) over (partition by key order by value Rows between 1 preceding and unbounded following), sum(c_float) over (partition by key order by value rows between 1 preceding and current row), max(c_float) over (partition by key order by value rows between 1 preceding and unbounded following), min(c_float) over (partition by key order by value rows between 1 preceding and 1 following) from t1) t1; select i, a, h, b, c, d, e, f, g, a as x, a +1 as y from (select max(c_int) over (partition by key order by value range UNBOUNDED PRECEDING) a, min(c_int) over (partition by key order by value range current row) b, count(c_int) over(partition by key order by value range 1 PRECEDING) c, avg(value) over (partition by key order by value range between unbounded preceding and unbounded following) d, sum(value) over (partition by key order by value range between unbounded preceding and current row) e, avg(c_float) over (partition by key order by value range between 1 preceding and unbounded following) f, sum(c_float) over (partition by key order by value range between 1 preceding and current row) g, max(c_float) over (partition by key order by value range between 1 preceding and unbounded following) h, min(c_float) over (partition by key order by value range between 1 preceding and 1 following) i from t1) t1; +create view v1 as select c_int, value, c_boolean from t1; +create view v2 as select c_int, value from t2; +select value from v1 where c_boolean=false; +select max(c_int) from v1 group by (c_boolean); +select count(v1.c_int) from v1 join t2 on v1.c_int = t2.c_int; +select count(v1.c_int) from v1 join v2 on v1.c_int = v2.c_int; + +create view v3 as select v1.value from v1 join t1 on v1.c_boolean = t1.c_boolean; +select * from v3 limit 3; + + Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1615993) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -9545,7 +9545,7 @@ if (runCBO) { boolean tokenTypeIsQuery = ast.getToken().getType() == HiveParser.TOK_QUERY || ast.getToken().getType() == HiveParser.TOK_EXPLAIN; - if (!tokenTypeIsQuery || createVwDesc != null + if (!tokenTypeIsQuery || !HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_CBO_ENABLED) || !canHandleQuery()) { runCBO = false; @@ -12525,7 +12525,7 @@ obASTExpr = (ASTNode) obASTExprLst.get(i); Map astToExprNDescMap = TypeCheckProcFactory .genExprNode(obASTExpr, new TypeCheckCtx(inputRR)); - ExprNodeDesc obExprNDesc = astToExprNDescMap.get((ASTNode) obASTExpr + ExprNodeDesc obExprNDesc = astToExprNDescMap.get(obASTExpr .getChild(0)); if (obExprNDesc == null) throw new SemanticException("Invalid order by expression: " @@ -12561,6 +12561,7 @@ if (!newVCLst.isEmpty()) { List originalInputRefs = Lists.transform(srcRel.getRowType() .getFieldList(), new Function() { + @Override public RexNode apply(RelDataTypeField input) { return new RexInputRef(input.getIndex(), input.getType()); } @@ -12589,6 +12590,7 @@ List obParentRelProjs = Lists.transform(srcRel .getRowType().getFieldList(), new Function() { + @Override public RexNode apply(RelDataTypeField input) { return new RexInputRef(input.getIndex(), input.getType()); } @@ -13019,6 +13021,7 @@ */ List oFieldNames = Lists.transform(columnNames, new Function() { + @Override public String apply(String hName) { return "_o_" + hName; }