diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java index 62f9d14..c0481bc 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java @@ -22,7 +22,9 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; +import java.util.LinkedList; import java.util.List; +import java.util.Queue; import org.antlr.runtime.Token; import org.antlr.runtime.tree.CommonTree; @@ -258,6 +260,7 @@ public void addChildren(List kids) { @Override public void setChild(int i, Tree t) { + clearRootNodeForSubTree(getChild(i)); super.setChild(i, t); resetRootInformation(); } @@ -347,4 +350,25 @@ private String toStringTree(ASTNode rootNode) { return rootNode.getMemoizedSubString(startIndx, endIndx); } + private static void clearRootNodeForSubTree(final Tree tree) { + if (tree == null) { + return; + } + + Queue queue = new LinkedList<>(); + queue.add(tree); + while (!queue.isEmpty()) { + Tree node = queue.remove(); + if (node instanceof ASTNode) { + ((ASTNode) node).rootNode = null; + } + for (int i = 0; i < node.getChildCount(); i++) { + Tree child = node.getChild(i); + if (child != null) { + queue.add(child); + } + } + } + } + } diff --git a/ql/src/test/queries/clientpositive/subquery_exists1.q b/ql/src/test/queries/clientpositive/subquery_exists1.q new file mode 100644 index 0000000..50cda34 --- /dev/null +++ b/ql/src/test/queries/clientpositive/subquery_exists1.q @@ -0,0 +1,7 @@ +set hive.cbo.enable=false; + +-- SORT_QUERY_RESULTS + +explain select * from src where exists (select * from src1 where src1.key=src.key and src1.value=src.value) limit 10; + +select * from src where exists (select * from src1 where src1.key=src.key and src1.value=src.value) limit 10; \ No newline at end of file diff --git a/ql/src/test/results/clientpositive/subquery_exists1.q.out b/ql/src/test/results/clientpositive/subquery_exists1.q.out new file mode 100644 index 0000000..4e111cb --- /dev/null +++ b/ql/src/test/results/clientpositive/subquery_exists1.q.out @@ -0,0 +1,93 @@ +PREHOOK: query: -- SORT_QUERY_RESULTS + +explain select * from src where exists (select * from src1 where src1.key=src.key and src1.value=src.value) limit 10 +PREHOOK: type: QUERY +POSTHOOK: query: -- SORT_QUERY_RESULTS + +explain select * from src where exists (select * from src1 where src1.key=src.key and src1.value=src.value) limit 10 +POSTHOOK: type: QUERY +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 depends on stages: Stage-1 + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Map Operator Tree: + TableScan + alias: src + Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE + Filter Operator + predicate: (key is not null and value is not null) (type: boolean) + Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE + Reduce Output Operator + key expressions: key (type: string), value (type: string) + sort order: ++ + Map-reduce partition columns: key (type: string), value (type: string) + Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE + TableScan + alias: src1 + Statistics: Num rows: 25 Data size: 191 Basic stats: COMPLETE Column stats: NONE + Filter Operator + predicate: (key is not null and value is not null) (type: boolean) + Statistics: Num rows: 25 Data size: 191 Basic stats: COMPLETE Column stats: NONE + Select Operator + expressions: key (type: string), value (type: string) + outputColumnNames: _col0, _col1 + Statistics: Num rows: 25 Data size: 191 Basic stats: COMPLETE Column stats: NONE + Group By Operator + keys: _col0 (type: string), _col1 (type: string) + mode: hash + outputColumnNames: _col0, _col1 + Statistics: Num rows: 25 Data size: 191 Basic stats: COMPLETE Column stats: NONE + Reduce Output Operator + key expressions: _col0 (type: string), _col1 (type: string) + sort order: ++ + Map-reduce partition columns: _col0 (type: string), _col1 (type: string) + Statistics: Num rows: 25 Data size: 191 Basic stats: COMPLETE Column stats: NONE + Reduce Operator Tree: + Join Operator + condition map: + Left Semi Join 0 to 1 + keys: + 0 key (type: string), value (type: string) + 1 _col0 (type: string), _col1 (type: string) + outputColumnNames: _col0, _col1 + Statistics: Num rows: 550 Data size: 5843 Basic stats: COMPLETE Column stats: NONE + Limit + Number of rows: 10 + Statistics: Num rows: 10 Data size: 100 Basic stats: COMPLETE Column stats: NONE + File Output Operator + compressed: false + Statistics: Num rows: 10 Data size: 100 Basic stats: COMPLETE Column stats: NONE + 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 + + Stage: Stage-0 + Fetch Operator + limit: 10 + Processor Tree: + ListSink + +PREHOOK: query: select * from src where exists (select * from src1 where src1.key=src.key and src1.value=src.value) limit 10 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Input: default@src1 +#### A masked pattern was here #### +POSTHOOK: query: select * from src where exists (select * from src1 where src1.key=src.key and src1.value=src.value) limit 10 +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +POSTHOOK: Input: default@src1 +#### A masked pattern was here #### +146 val_146 +146 val_146 +150 val_150 +213 val_213 +213 val_213 +238 val_238 +238 val_238 +255 val_255 +255 val_255 +273 val_273