diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/GenTezUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/GenTezUtils.java index a2512500e37b..f2998fc1e921 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/GenTezUtils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/GenTezUtils.java @@ -401,6 +401,7 @@ public static void removeUnionOperators(GenTezProcContext context, BaseWork work operators.addAll(newRoots); Set> seen = new HashSet>(); + Set> removedParents = new HashSet>(); Set fileStatusesToFetch = null; if(context.parseContext.getFetchTask() != null) { @@ -468,7 +469,12 @@ public static void removeUnionOperators(GenTezProcContext context, BaseWork work // root operator is union (can happen in reducers) replacementMap.put(current, current.getChildOperators().get(0)); } else { - parent.removeChildAndAdoptItsChildren(current); + // For complex queries, there is a UNION with the same parent. + // In that case, the parent UNION that has already been removed will not be removed. + if (!removedParents.contains(parent)) { + parent.removeChildAndAdoptItsChildren(current); + removedParents.add(parent); + } operators.remove(current); } } diff --git a/ql/src/test/results/clientpositive/llap/cte_mat_10.q.out b/ql/src/test/results/clientpositive/llap/cte_mat_10.q.out index 8262ba7c035a..c8f2752e7f46 100644 --- a/ql/src/test/results/clientpositive/llap/cte_mat_10.q.out +++ b/ql/src/test/results/clientpositive/llap/cte_mat_10.q.out @@ -138,14 +138,16 @@ STAGE PLANS: expressions: concat('b2 <- ', id) (type: string) outputColumnNames: _col0 Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE - File Output Operator - compressed: false + Union Statistics: Num rows: 6 Data size: 1005 Basic stats: COMPLETE Column stats: PARTIAL - table: - input format: org.apache.hadoop.mapred.SequenceFileInputFormat - output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat - serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe - Execution mode: vectorized, llap + File Output Operator + compressed: false + Statistics: Num rows: 6 Data size: 1005 Basic stats: COMPLETE Column stats: PARTIAL + table: + input format: org.apache.hadoop.mapred.SequenceFileInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat + serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe + Execution mode: llap LLAP IO: all inputs Map 4 Map Operator Tree: @@ -229,14 +231,16 @@ STAGE PLANS: expressions: concat('b2 <- ', id) (type: string) outputColumnNames: _col0 Statistics: Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE - File Output Operator - compressed: false + Union Statistics: Num rows: 6 Data size: 1005 Basic stats: COMPLETE Column stats: PARTIAL - table: - input format: org.apache.hadoop.mapred.SequenceFileInputFormat - output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat - serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe - Execution mode: vectorized, llap + File Output Operator + compressed: false + Statistics: Num rows: 6 Data size: 1005 Basic stats: COMPLETE Column stats: PARTIAL + table: + input format: org.apache.hadoop.mapred.SequenceFileInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat + serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe + Execution mode: llap LLAP IO: all inputs Union 5 Vertex: Union 5