Index: ql/src/test/results/clientpositive/ppd_repeated_alias1.q.out =================================================================== --- ql/src/test/results/clientpositive/ppd_repeated_alias1.q.out (revision 0) +++ ql/src/test/results/clientpositive/ppd_repeated_alias1.q.out (revision 0) @@ -0,0 +1,333 @@ +PREHOOK: query: -- see HIVE-1342 + +drop table pokes +PREHOOK: type: DROPTABLE +POSTHOOK: query: -- see HIVE-1342 + +drop table pokes +POSTHOOK: type: DROPTABLE +PREHOOK: query: drop table pokes2 +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table pokes2 +POSTHOOK: type: DROPTABLE +PREHOOK: query: create table pokes (foo int, bar int) +PREHOOK: type: CREATETABLE +POSTHOOK: query: create table pokes (foo int, bar int) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@pokes +PREHOOK: query: create table pokes2 (foo int, bar int) +PREHOOK: type: CREATETABLE +POSTHOOK: query: create table pokes2 (foo int, bar int) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@pokes2 +PREHOOK: query: -- Q1: predicate should not be pushed on the right side of a left outer join +explain +SELECT a.foo as foo1, b.foo as foo2, b.bar +FROM pokes a LEFT OUTER JOIN pokes2 b +ON a.foo=b.foo +WHERE b.bar=3 +PREHOOK: type: QUERY +POSTHOOK: query: -- Q1: predicate should not be pushed on the right side of a left outer join +explain +SELECT a.foo as foo1, b.foo as foo2, b.bar +FROM pokes a LEFT OUTER JOIN pokes2 b +ON a.foo=b.foo +WHERE b.bar=3 +POSTHOOK: type: QUERY +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_LEFTOUTERJOIN (TOK_TABREF (TOK_TABNAME pokes) a) (TOK_TABREF (TOK_TABNAME pokes2) b) (= (. (TOK_TABLE_OR_COL a) foo) (. (TOK_TABLE_OR_COL b) foo)))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (. (TOK_TABLE_OR_COL a) foo) foo1) (TOK_SELEXPR (. (TOK_TABLE_OR_COL b) foo) foo2) (TOK_SELEXPR (. (TOK_TABLE_OR_COL b) bar))) (TOK_WHERE (= (. (TOK_TABLE_OR_COL b) bar) 3)))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + a + TableScan + alias: a + Reduce Output Operator + key expressions: + expr: foo + type: int + sort order: + + Map-reduce partition columns: + expr: foo + type: int + tag: 0 + value expressions: + expr: foo + type: int + b + TableScan + alias: b + Reduce Output Operator + key expressions: + expr: foo + type: int + sort order: + + Map-reduce partition columns: + expr: foo + type: int + tag: 1 + value expressions: + expr: foo + type: int + expr: bar + type: int + Reduce Operator Tree: + Join Operator + condition map: + Left Outer Join0 to 1 + condition expressions: + 0 {VALUE._col0} + 1 {VALUE._col0} {VALUE._col1} + handleSkewJoin: false + outputColumnNames: _col0, _col4, _col5 + Filter Operator + predicate: + expr: (_col5 = 3) + type: boolean + Select Operator + expressions: + expr: _col0 + type: int + expr: _col4 + type: int + expr: _col5 + type: int + outputColumnNames: _col0, _col1, _col2 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: -1 + + +PREHOOK: query: -- Q2: predicate should not be pushed on the right side of a left outer join +explain +SELECT * FROM + (SELECT a.foo as foo1, b.foo as foo2, b.bar + FROM pokes a LEFT OUTER JOIN pokes2 b + ON a.foo=b.foo) a +WHERE a.bar=3 +PREHOOK: type: QUERY +POSTHOOK: query: -- Q2: predicate should not be pushed on the right side of a left outer join +explain +SELECT * FROM + (SELECT a.foo as foo1, b.foo as foo2, b.bar + FROM pokes a LEFT OUTER JOIN pokes2 b + ON a.foo=b.foo) a +WHERE a.bar=3 +POSTHOOK: type: QUERY +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_LEFTOUTERJOIN (TOK_TABREF (TOK_TABNAME pokes) a) (TOK_TABREF (TOK_TABNAME pokes2) b) (= (. (TOK_TABLE_OR_COL a) foo) (. (TOK_TABLE_OR_COL b) foo)))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (. (TOK_TABLE_OR_COL a) foo) foo1) (TOK_SELEXPR (. (TOK_TABLE_OR_COL b) foo) foo2) (TOK_SELEXPR (. (TOK_TABLE_OR_COL b) bar))))) a)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR TOK_ALLCOLREF)) (TOK_WHERE (= (. (TOK_TABLE_OR_COL a) bar) 3)))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + a:a + TableScan + alias: a + Reduce Output Operator + key expressions: + expr: foo + type: int + sort order: + + Map-reduce partition columns: + expr: foo + type: int + tag: 0 + value expressions: + expr: foo + type: int + a:b + TableScan + alias: b + Reduce Output Operator + key expressions: + expr: foo + type: int + sort order: + + Map-reduce partition columns: + expr: foo + type: int + tag: 1 + value expressions: + expr: foo + type: int + expr: bar + type: int + Reduce Operator Tree: + Join Operator + condition map: + Left Outer Join0 to 1 + condition expressions: + 0 {VALUE._col0} + 1 {VALUE._col0} {VALUE._col1} + handleSkewJoin: false + outputColumnNames: _col0, _col4, _col5 + Select Operator + expressions: + expr: _col0 + type: int + expr: _col4 + type: int + expr: _col5 + type: int + outputColumnNames: _col0, _col1, _col2 + Filter Operator + predicate: + expr: (_col2 = 3) + type: boolean + Select Operator + expressions: + expr: _col0 + type: int + expr: _col1 + type: int + expr: _col2 + type: int + outputColumnNames: _col0, _col1, _col2 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: -1 + + +PREHOOK: query: -- Q3: predicate should be pushed +explain +SELECT * FROM + (SELECT a.foo as foo1, b.foo as foo2, a.bar + FROM pokes a JOIN pokes2 b + ON a.foo=b.foo) a +WHERE a.bar=3 +PREHOOK: type: QUERY +POSTHOOK: query: -- Q3: predicate should be pushed +explain +SELECT * FROM + (SELECT a.foo as foo1, b.foo as foo2, a.bar + FROM pokes a JOIN pokes2 b + ON a.foo=b.foo) a +WHERE a.bar=3 +POSTHOOK: type: QUERY +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_JOIN (TOK_TABREF (TOK_TABNAME pokes) a) (TOK_TABREF (TOK_TABNAME pokes2) b) (= (. (TOK_TABLE_OR_COL a) foo) (. (TOK_TABLE_OR_COL b) foo)))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (. (TOK_TABLE_OR_COL a) foo) foo1) (TOK_SELEXPR (. (TOK_TABLE_OR_COL b) foo) foo2) (TOK_SELEXPR (. (TOK_TABLE_OR_COL a) bar))))) a)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR TOK_ALLCOLREF)) (TOK_WHERE (= (. (TOK_TABLE_OR_COL a) bar) 3)))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + a:a + TableScan + alias: a + Filter Operator + predicate: + expr: (bar = 3) + type: boolean + Reduce Output Operator + key expressions: + expr: foo + type: int + sort order: + + Map-reduce partition columns: + expr: foo + type: int + tag: 0 + value expressions: + expr: foo + type: int + expr: bar + type: int + a:b + TableScan + alias: b + Reduce Output Operator + key expressions: + expr: foo + type: int + sort order: + + Map-reduce partition columns: + expr: foo + type: int + tag: 1 + value expressions: + expr: foo + type: int + Reduce Operator Tree: + Join Operator + condition map: + Inner Join 0 to 1 + condition expressions: + 0 {VALUE._col0} {VALUE._col1} + 1 {VALUE._col0} + handleSkewJoin: false + outputColumnNames: _col0, _col1, _col4 + Select Operator + expressions: + expr: _col0 + type: int + expr: _col4 + type: int + expr: _col1 + type: int + outputColumnNames: _col0, _col1, _col2 + Select Operator + expressions: + expr: _col0 + type: int + expr: _col1 + type: int + expr: _col2 + type: int + outputColumnNames: _col0, _col1, _col2 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: -1 + + +PREHOOK: query: drop table pokes +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@pokes +PREHOOK: Output: default@pokes +POSTHOOK: query: drop table pokes +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@pokes +POSTHOOK: Output: default@pokes +PREHOOK: query: drop table pokes2 +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@pokes2 +PREHOOK: Output: default@pokes2 +POSTHOOK: query: drop table pokes2 +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@pokes2 +POSTHOOK: Output: default@pokes2 Index: ql/src/test/results/clientpositive/ppd_repeated_alias2.q.out =================================================================== --- ql/src/test/results/clientpositive/ppd_repeated_alias2.q.out (revision 0) +++ ql/src/test/results/clientpositive/ppd_repeated_alias2.q.out (revision 0) @@ -0,0 +1,354 @@ +PREHOOK: query: -- see HIVE-1342 + +create table if not exists dm_fact_buyer_prd_info_d ( +category_id string +,gmv_trade_num int +,user_id int +) +PARTITIONED BY (ds int) +PREHOOK: type: CREATETABLE +POSTHOOK: query: -- see HIVE-1342 + +create table if not exists dm_fact_buyer_prd_info_d ( +category_id string +,gmv_trade_num int +,user_id int +) +PARTITIONED BY (ds int) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@dm_fact_buyer_prd_info_d +PREHOOK: query: explain select category_id1,category_id2,assoc_idx +from ( +select +category_id1 +, category_id2 +, count(distinct user_id) as assoc_idx +from ( +select +t1.category_id as category_id1 +, t2.category_id as category_id2 +, t1.user_id +from ( +select category_id, user_id +from dm_fact_buyer_prd_info_d +group by category_id, user_id ) t1 +join ( +select category_id, user_id +from dm_fact_buyer_prd_info_d +group by category_id, user_id ) t2 on t1.user_id=t2.user_id +) t11 +group by category_id1, category_id2 ) t_o +where category_id1 <> category_id2 +and assoc_idx > 2 +PREHOOK: type: QUERY +POSTHOOK: query: explain select category_id1,category_id2,assoc_idx +from ( +select +category_id1 +, category_id2 +, count(distinct user_id) as assoc_idx +from ( +select +t1.category_id as category_id1 +, t2.category_id as category_id2 +, t1.user_id +from ( +select category_id, user_id +from dm_fact_buyer_prd_info_d +group by category_id, user_id ) t1 +join ( +select category_id, user_id +from dm_fact_buyer_prd_info_d +group by category_id, user_id ) t2 on t1.user_id=t2.user_id +) t11 +group by category_id1, category_id2 ) t_o +where category_id1 <> category_id2 +and assoc_idx > 2 +POSTHOOK: type: QUERY +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_JOIN (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME dm_fact_buyer_prd_info_d))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL category_id)) (TOK_SELEXPR (TOK_TABLE_OR_COL user_id))) (TOK_GROUPBY (TOK_TABLE_OR_COL category_id) (TOK_TABLE_OR_COL user_id)))) t1) (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME dm_fact_buyer_prd_info_d))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL category_id)) (TOK_SELEXPR (TOK_TABLE_OR_COL user_id))) (TOK_GROUPBY (TOK_TABLE_OR_COL category_id) (TOK_TABLE_OR_COL user_id)))) t2) (= (. (TOK_TABLE_OR_COL t1) user_id) (. (TOK_TABLE_OR_COL t2) user_id)))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (. (TOK_TABLE_OR_COL t1) category_id) category_id1) (TOK_SELEXPR (. (TOK_TABLE_OR_COL t2) category_id) category_id2) (TOK_SELEXPR (. (TOK_TABLE_OR_COL t1) user_id))))) t11)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL category_id1)) (TOK_SELEXPR (TOK_TABLE_OR_COL category_id2)) (TOK_SELEXPR (TOK_FUNCTIONDI count (TOK_TABLE_OR_COL user_id)) assoc_idx)) (TOK_GROUPBY (TOK_TABLE_OR_COL category_id1) (TOK_TABLE_OR_COL category_id2)))) t_o)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL category_id1)) (TOK_SELEXPR (TOK_TABLE_OR_COL category_id2)) (TOK_SELEXPR (TOK_TABLE_OR_COL assoc_idx))) (TOK_WHERE (and (<> (TOK_TABLE_OR_COL category_id1) (TOK_TABLE_OR_COL category_id2)) (> (TOK_TABLE_OR_COL assoc_idx) 2))))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-2 depends on stages: Stage-1, Stage-4 + Stage-3 depends on stages: Stage-2 + Stage-4 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + t_o:t11:t2:dm_fact_buyer_prd_info_d + TableScan + alias: dm_fact_buyer_prd_info_d + Select Operator + expressions: + expr: category_id + type: string + expr: user_id + type: int + outputColumnNames: category_id, user_id + Group By Operator + bucketGroup: false + keys: + expr: category_id + type: string + expr: user_id + type: int + mode: hash + outputColumnNames: _col0, _col1 + Reduce Output Operator + key expressions: + expr: _col0 + type: string + expr: _col1 + type: int + sort order: ++ + Map-reduce partition columns: + expr: _col0 + type: string + expr: _col1 + type: int + tag: -1 + Reduce Operator Tree: + Group By Operator + bucketGroup: false + keys: + expr: KEY._col0 + type: string + expr: KEY._col1 + type: int + mode: mergepartial + outputColumnNames: _col0, _col1 + Select Operator + expressions: + expr: _col0 + type: string + expr: _col1 + type: int + outputColumnNames: _col0, _col1 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.SequenceFileInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat + + Stage: Stage-2 + Map Reduce + Alias -> Map Operator Tree: + $INTNAME + Reduce Output Operator + key expressions: + expr: _col1 + type: int + sort order: + + Map-reduce partition columns: + expr: _col1 + type: int + tag: 1 + value expressions: + expr: _col0 + type: string + $INTNAME1 + Reduce Output Operator + key expressions: + expr: _col1 + type: int + sort order: + + Map-reduce partition columns: + expr: _col1 + type: int + tag: 0 + value expressions: + expr: _col0 + type: string + expr: _col1 + type: int + Reduce Operator Tree: + Join Operator + condition map: + Inner Join 0 to 1 + condition expressions: + 0 {VALUE._col0} {VALUE._col1} + 1 {VALUE._col0} + handleSkewJoin: false + outputColumnNames: _col0, _col1, _col2 + Filter Operator + predicate: + expr: (_col0 <> _col2) + type: boolean + Select Operator + expressions: + expr: _col0 + type: string + expr: _col2 + type: string + expr: _col1 + type: int + outputColumnNames: _col0, _col1, _col2 + Select Operator + expressions: + expr: _col0 + type: string + expr: _col1 + type: string + expr: _col2 + type: int + outputColumnNames: _col0, _col1, _col2 + Group By Operator + aggregations: + expr: count(DISTINCT _col2) + bucketGroup: false + keys: + expr: _col0 + type: string + expr: _col1 + type: string + expr: _col2 + type: int + mode: hash + outputColumnNames: _col0, _col1, _col2, _col3 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.SequenceFileInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat + + Stage: Stage-3 + Map Reduce + Alias -> Map Operator Tree: + file:/var/folders/nt/ng21tg0n1jl4547lw0k8lg6hq_nw87/T/charleschen/hive_2011-08-15_15-28-10_495_2284605120901603682/-mr-10003 + Reduce Output Operator + key expressions: + expr: _col0 + type: string + expr: _col1 + type: string + expr: _col2 + type: int + sort order: +++ + Map-reduce partition columns: + expr: _col0 + type: string + expr: _col1 + type: string + tag: -1 + value expressions: + expr: _col3 + type: bigint + Reduce Operator Tree: + Group By Operator + aggregations: + expr: count(DISTINCT KEY._col2:0._col0) + bucketGroup: false + keys: + expr: KEY._col0 + type: string + expr: KEY._col1 + type: string + mode: mergepartial + outputColumnNames: _col0, _col1, _col2 + Filter Operator + predicate: + expr: ((_col0 <> _col1) and (_col2 > 2)) + type: boolean + Select Operator + expressions: + expr: _col0 + type: string + expr: _col1 + type: string + expr: _col2 + type: bigint + outputColumnNames: _col0, _col1, _col2 + Select Operator + expressions: + expr: _col0 + type: string + expr: _col1 + type: string + expr: _col2 + type: bigint + outputColumnNames: _col0, _col1, _col2 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-4 + Map Reduce + Alias -> Map Operator Tree: + t_o:t11:t1:dm_fact_buyer_prd_info_d + TableScan + alias: dm_fact_buyer_prd_info_d + Select Operator + expressions: + expr: category_id + type: string + expr: user_id + type: int + outputColumnNames: category_id, user_id + Group By Operator + bucketGroup: false + keys: + expr: category_id + type: string + expr: user_id + type: int + mode: hash + outputColumnNames: _col0, _col1 + Reduce Output Operator + key expressions: + expr: _col0 + type: string + expr: _col1 + type: int + sort order: ++ + Map-reduce partition columns: + expr: _col0 + type: string + expr: _col1 + type: int + tag: -1 + Reduce Operator Tree: + Group By Operator + bucketGroup: false + keys: + expr: KEY._col0 + type: string + expr: KEY._col1 + type: int + mode: mergepartial + outputColumnNames: _col0, _col1 + Select Operator + expressions: + expr: _col0 + type: string + expr: _col1 + type: int + outputColumnNames: _col0, _col1 + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.SequenceFileInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: -1 + + +PREHOOK: query: drop table dm_fact_buyer_prd_info_d +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@dm_fact_buyer_prd_info_d +PREHOOK: Output: default@dm_fact_buyer_prd_info_d +POSTHOOK: query: drop table dm_fact_buyer_prd_info_d +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@dm_fact_buyer_prd_info_d +POSTHOOK: Output: default@dm_fact_buyer_prd_info_d Index: ql/src/test/queries/clientpositive/ppd_repeated_alias1.q =================================================================== --- ql/src/test/queries/clientpositive/ppd_repeated_alias1.q (revision 0) +++ ql/src/test/queries/clientpositive/ppd_repeated_alias1.q (revision 0) @@ -0,0 +1,32 @@ +-- see HIVE-1342 + +drop table pokes; +drop table pokes2; +create table pokes (foo int, bar int); +create table pokes2 (foo int, bar int); + +-- Q1: predicate should not be pushed on the right side of a left outer join +explain +SELECT a.foo as foo1, b.foo as foo2, b.bar +FROM pokes a LEFT OUTER JOIN pokes2 b +ON a.foo=b.foo +WHERE b.bar=3; + +-- Q2: predicate should not be pushed on the right side of a left outer join +explain +SELECT * FROM + (SELECT a.foo as foo1, b.foo as foo2, b.bar + FROM pokes a LEFT OUTER JOIN pokes2 b + ON a.foo=b.foo) a +WHERE a.bar=3; + +-- Q3: predicate should be pushed +explain +SELECT * FROM + (SELECT a.foo as foo1, b.foo as foo2, a.bar + FROM pokes a JOIN pokes2 b + ON a.foo=b.foo) a +WHERE a.bar=3; + +drop table pokes; +drop table pokes2; \ No newline at end of file Index: ql/src/test/queries/clientpositive/ppd_repeated_alias2.q =================================================================== --- ql/src/test/queries/clientpositive/ppd_repeated_alias2.q (revision 0) +++ ql/src/test/queries/clientpositive/ppd_repeated_alias2.q (revision 0) @@ -0,0 +1,37 @@ +-- see HIVE-1342 + +create table if not exists dm_fact_buyer_prd_info_d ( +category_id string +,gmv_trade_num int +,user_id int +) +PARTITIONED BY (ds int); + +set hive.optimize.ppd=true; +set hive.map.aggr=true; + +explain select category_id1,category_id2,assoc_idx +from ( +select +category_id1 +, category_id2 +, count(distinct user_id) as assoc_idx +from ( +select +t1.category_id as category_id1 +, t2.category_id as category_id2 +, t1.user_id +from ( +select category_id, user_id +from dm_fact_buyer_prd_info_d +group by category_id, user_id ) t1 +join ( +select category_id, user_id +from dm_fact_buyer_prd_info_d +group by category_id, user_id ) t2 on t1.user_id=t2.user_id +) t11 +group by category_id1, category_id2 ) t_o +where category_id1 <> category_id2 +and assoc_idx > 2; + +drop table dm_fact_buyer_prd_info_d; \ No newline at end of file Index: ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java (revision 1157999) +++ ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java (working copy) @@ -23,9 +23,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.Stack; -import java.util.Map.Entry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,7 +43,6 @@ import org.apache.hadoop.hive.ql.lib.NodeProcessorCtx; import org.apache.hadoop.hive.ql.metadata.HiveStorageHandler; import org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler; -import org.apache.hadoop.hive.ql.metadata.HiveUtils; import org.apache.hadoop.hive.ql.metadata.Table; import org.apache.hadoop.hive.ql.parse.OpParseContext; import org.apache.hadoop.hive.ql.parse.RowResolver; @@ -222,7 +221,19 @@ OpWalkerInfo owi = (OpWalkerInfo) procCtx; Set aliases = getQualifiedAliases((JoinOperator) nd, owi .getRowResolver(nd)); - boolean hasUnpushedPredicates = mergeWithChildrenPred(nd, owi, null, aliases, false); + // we pass null for aliases here because mergeWithChildrenPred filters + // aliases in the children node context and we need to filter them in + // the current JoinOperator's context + boolean hasUnpushedPredicates = mergeWithChildrenPred(nd, owi, null, null, false); + ExprWalkerInfo prunePreds = + owi.getPrunedPreds((Operator) nd); + if (prunePreds != null) { + for (String key : prunePreds.getFinalCandidates().keySet()) { + if (!aliases.contains(key)) { + prunePreds.getFinalCandidates().remove(key); + } + } + } if (HiveConf.getBoolVar(owi.getParseContext().getConf(), HiveConf.ConfVars.HIVEPPDREMOVEDUPLICATEFILTERS)) { if (hasUnpushedPredicates) { Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1157999) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -5380,16 +5380,21 @@ ArrayList columns = inputRR.getColumnInfos(); ArrayList colList = new ArrayList(); ArrayList columnNames = new ArrayList(); + Map columnExprMap = + new HashMap(); for (int i = 0; i < columns.size(); i++) { ColumnInfo col = columns.get(i); colList.add(new ExprNodeColumnDesc(col.getType(), col.getInternalName(), col.getTabAlias(), col.getIsVirtualCol())); columnNames.add(col.getInternalName()); + columnExprMap.put(col.getInternalName(), + new ExprNodeColumnDesc(col.getType(), col.getInternalName(), + col.getTabAlias(), col.getIsVirtualCol())); } Operator output = putOpInsertMap(OperatorFactory.getAndMakeChild( new SelectDesc(colList, columnNames, true), new RowSchema(inputRR .getColumnInfos()), input), inputRR); - output.setColumnExprMap(input.getColumnExprMap()); + output.setColumnExprMap(columnExprMap); return output; }