From e5041e019ef6976a08f402bc3a7a10fd26a952a7 Mon Sep 17 00:00:00 2001 From: Ashutosh Chauhan Date: Thu, 8 Feb 2018 18:25:32 -0800 Subject: [PATCH] HIVE-18660 : PCR doesn't distinguish between partition and virtual columns --- .../hive/ql/optimizer/pcr/PcrExprProcFactory.java | 12 +++++- .../queries/clientpositive/partition_boolexpr.q | 3 +- .../clientpositive/partition_boolexpr.q.out | 49 ++++++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java index ea042bf144..ee776c762d 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PcrExprProcFactory.java @@ -213,13 +213,23 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, Object... nodeOutputs) throws SemanticException { ExprNodeColumnDesc cd = (ExprNodeColumnDesc) nd; PcrExprProcCtx epc = (PcrExprProcCtx) procCtx; + List vcs = epc.getVirtualColumns(); if (cd.getTabAlias().equalsIgnoreCase(epc.getTabAlias()) - && cd.getIsPartitionColOrVirtualCol()) { + && cd.getIsPartitionColOrVirtualCol() && !isVC(vcs, cd.getColumn())) { return new NodeInfoWrapper(WalkState.PART_COL, null, cd); } else { return new NodeInfoWrapper(WalkState.UNKNOWN, null, cd); } } + + private boolean isVC(List vcs, String colName) { + for (VirtualColumn vc : vcs) { + if (vc.getName().equalsIgnoreCase(colName)) { + return true; + } + } + return false; + } } public static ExprNodeGenericFuncDesc getOutExpr( index e18f095447..6178aabddc 100644 --- a/ql/src/test/queries/clientpositive/partition_boolexpr.q +++ b/ql/src/test/queries/clientpositive/partition_boolexpr.q @@ -10,4 +10,5 @@ explain select count(1) from srcpart where false; explain select count(1) from srcpart where true and hr='11'; explain select count(1) from srcpart where true or hr='11'; explain select count(1) from srcpart where false or hr='11'; -explain select count(1) from srcpart where false and hr='11'; \ No newline at end of file +explain select count(1) from srcpart where false and hr='11'; +explain select count(1) from srcpart where INPUT__FILE__NAME is not null; diff --git a/ql/src/test/results/clientpositive/partition_boolexpr.q.out b/ql/src/test/results/clientpositive/partition_boolexpr.q.out index b605260c3f..3276a304ba 100644 --- a/ql/src/test/results/clientpositive/partition_boolexpr.q.out +++ b/ql/src/test/results/clientpositive/partition_boolexpr.q.out @@ -177,3 +177,52 @@ STAGE PLANS: Processor Tree: ListSink +PREHOOK: query: explain select count(1) from srcpart where INPUT__FILE__NAME is not null +PREHOOK: type: QUERY +POSTHOOK: query: explain select count(1) from srcpart where INPUT__FILE__NAME is not null +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: srcpart + Statistics: Num rows: 2000 Data size: 21248 Basic stats: COMPLETE Column stats: NONE + Filter Operator + predicate: INPUT__FILE__NAME is not null (type: boolean) + Statistics: Num rows: 2000 Data size: 21248 Basic stats: COMPLETE Column stats: NONE + Select Operator + Statistics: Num rows: 2000 Data size: 21248 Basic stats: COMPLETE Column stats: NONE + Group By Operator + aggregations: count() + mode: hash + outputColumnNames: _col0 + Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE + Reduce Output Operator + sort order: + Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE + value expressions: _col0 (type: bigint) + Reduce Operator Tree: + Group By Operator + aggregations: count(VALUE._col0) + mode: mergepartial + outputColumnNames: _col0 + Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE + File Output Operator + compressed: false + Statistics: Num rows: 1 Data size: 8 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: -1 + Processor Tree: + ListSink + -- 2.14.3 (Apple Git-98)