Index: ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java (revision 1643530) +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java (working copy) @@ -889,15 +889,22 @@ rsDesc.setKeyCols(newKeyEpxrs); // partition columns - ArrayList newPartExprs = new ArrayList(); - for (ExprNodeDesc desc : rsDesc.getPartitionCols()) { - ExprNodeDesc expr = foldExpr(desc, constants, cppCtx, op, 0, false); - if (expr instanceof ExprNodeConstantDesc || expr instanceof ExprNodeNullDesc) { - continue; + if (!rsDesc.getPartitionCols().isEmpty()) { + ArrayList newPartExprs = new ArrayList(); + for (ExprNodeDesc desc : rsDesc.getPartitionCols()) { + ExprNodeDesc expr = foldExpr(desc, constants, cppCtx, op, 0, false); + if (expr instanceof ExprNodeConstantDesc || expr instanceof ExprNodeNullDesc) { + continue; + } + newPartExprs.add(expr); } - newPartExprs.add(expr); + if (newPartExprs.isEmpty()) { + // If all partition columns are removed because of constant, insert an extra column to avoid + // random partitioning. + newPartExprs.add(new ExprNodeConstantDesc("")); + } + rsDesc.setPartitionCols(newPartExprs); } - rsDesc.setPartitionCols(newPartExprs); // value columns ArrayList newValExprs = new ArrayList(); Index: ql/src/test/results/clientpositive/cluster.q.out =================================================================== --- ql/src/test/results/clientpositive/cluster.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/cluster.q.out (working copy) @@ -25,6 +25,7 @@ Reduce Output Operator key expressions: '10' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -82,6 +83,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -139,6 +141,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -196,6 +199,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -253,6 +257,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -310,6 +315,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -424,6 +430,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -478,6 +485,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -489,6 +497,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator @@ -567,6 +576,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -578,6 +588,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) Reduce Operator Tree: @@ -662,6 +673,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -673,6 +685,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) Reduce Operator Tree: @@ -702,6 +715,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 275 Data size: 2921 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string), _col3 (type: string) Reduce Operator Tree: @@ -756,6 +770,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -767,6 +782,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator @@ -795,6 +811,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 275 Data size: 2921 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string), _col2 (type: string) Reduce Operator Tree: Index: ql/src/test/results/clientpositive/constprog2.q.out =================================================================== --- ql/src/test/results/clientpositive/constprog2.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/constprog2.q.out (working copy) @@ -23,6 +23,7 @@ Reduce Output Operator key expressions: '86' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE TableScan alias: src2 @@ -33,6 +34,7 @@ Reduce Output Operator key expressions: '86' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) Reduce Operator Tree: @@ -98,6 +100,7 @@ Reduce Output Operator key expressions: '86' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE TableScan alias: src2 @@ -108,6 +111,7 @@ Reduce Output Operator key expressions: '86' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) Reduce Operator Tree: Index: ql/src/test/results/clientpositive/join_nullsafe.q.out =================================================================== --- ql/src/test/results/clientpositive/join_nullsafe.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/join_nullsafe.q.out (working copy) @@ -1525,6 +1525,7 @@ Reduce Output Operator key expressions: null (type: void) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: int) TableScan @@ -1536,6 +1537,7 @@ Reduce Output Operator key expressions: null (type: void) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE value expressions: key (type: int) Reduce Operator Tree: Index: ql/src/test/results/clientpositive/ppd2.q.out =================================================================== --- ql/src/test/results/clientpositive/ppd2.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/ppd2.q.out (working copy) @@ -351,6 +351,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -362,6 +363,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator Index: ql/src/test/results/clientpositive/ppd_clusterby.q.out =================================================================== --- ql/src/test/results/clientpositive/ppd_clusterby.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/ppd_clusterby.q.out (working copy) @@ -25,6 +25,7 @@ Reduce Output Operator key expressions: '10' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -79,6 +80,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -90,6 +92,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator @@ -171,6 +174,7 @@ Reduce Output Operator key expressions: '10' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: @@ -225,6 +229,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE value expressions: value (type: string) TableScan @@ -236,6 +241,7 @@ Reduce Output Operator key expressions: '20' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator Index: ql/src/test/results/clientpositive/ppd_join4.q.out =================================================================== --- ql/src/test/results/clientpositive/ppd_join4.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/ppd_join4.q.out (working copy) @@ -69,6 +69,7 @@ Reduce Output Operator key expressions: 'a' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE Stage: Stage-2 @@ -78,6 +79,7 @@ Reduce Output Operator key expressions: 'a' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE TableScan alias: t3 @@ -88,6 +90,7 @@ Reduce Output Operator key expressions: 'a' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE Reduce Operator Tree: Join Operator Index: ql/src/test/results/clientpositive/ppd_outer_join5.q.out =================================================================== --- ql/src/test/results/clientpositive/ppd_outer_join5.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/ppd_outer_join5.q.out (working copy) @@ -75,6 +75,7 @@ Reduce Output Operator key expressions: 20 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: key (type: string), value (type: string) Reduce Operator Tree: @@ -127,6 +128,7 @@ Reduce Output Operator key expressions: 20 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: key (type: string), value (type: string) TableScan @@ -138,6 +140,7 @@ Reduce Output Operator key expressions: 20 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: key (type: string), value (type: string) TableScan @@ -202,6 +205,7 @@ Reduce Output Operator key expressions: 20 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: key (type: string), value (type: string) TableScan @@ -213,6 +217,7 @@ Reduce Output Operator key expressions: 20 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: key (type: string), value (type: string) TableScan Index: ql/src/test/results/clientpositive/quotedid_basic.q.out =================================================================== --- ql/src/test/results/clientpositive/quotedid_basic.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/quotedid_basic.q.out (working copy) @@ -193,6 +193,7 @@ Reduce Output Operator key expressions: '1' (type: string), _col1 (type: string) sort order: ++ + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: _col0 (type: string), _col1 (type: string), '1' (type: string) Reduce Operator Tree: @@ -275,6 +276,7 @@ Reduce Output Operator key expressions: '1' (type: string), _col1 (type: string) sort order: ++ + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 0 Data size: 0 Basic stats: NONE Column stats: NONE value expressions: _col0 (type: string), _col1 (type: string), '1' (type: string) Reduce Operator Tree: Index: ql/src/test/results/clientpositive/smb_mapjoin_25.q.out =================================================================== --- ql/src/test/results/clientpositive/smb_mapjoin_25.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/smb_mapjoin_25.q.out (working copy) @@ -71,6 +71,7 @@ Reduce Output Operator key expressions: 5 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 26 Data size: 104 Basic stats: COMPLETE Column stats: NONE TableScan alias: b @@ -81,6 +82,7 @@ Reduce Output Operator key expressions: 5 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 25 Data size: 100 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator @@ -152,6 +154,7 @@ Reduce Output Operator key expressions: 5 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 25 Data size: 100 Basic stats: COMPLETE Column stats: NONE TableScan alias: d @@ -162,6 +165,7 @@ Reduce Output Operator key expressions: 5 (type: int) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 27 Data size: 108 Basic stats: COMPLETE Column stats: NONE Reduce Operator Tree: Join Operator Index: ql/src/test/results/clientpositive/union27.q.out =================================================================== --- ql/src/test/results/clientpositive/union27.q.out (revision 1643530) +++ ql/src/test/results/clientpositive/union27.q.out (working copy) @@ -51,6 +51,7 @@ Reduce Output Operator key expressions: '97' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 250 Data size: 2656 Basic stats: COMPLETE Column stats: NONE TableScan alias: jackson_sev_add @@ -67,6 +68,7 @@ Reduce Output Operator key expressions: '97' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) TableScan @@ -84,6 +86,7 @@ Reduce Output Operator key expressions: '97' (type: string) sort order: + + Map-reduce partition columns: '' (type: string) Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: NONE value expressions: _col1 (type: string) Reduce Operator Tree: