diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveGBOpConvUtil.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveGBOpConvUtil.java index bc87b36..55f1247 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveGBOpConvUtil.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/HiveGBOpConvUtil.java @@ -42,6 +42,7 @@ import org.apache.hadoop.hive.ql.exec.Utilities; import org.apache.hadoop.hive.ql.io.AcidUtils; import org.apache.hadoop.hive.ql.metadata.VirtualColumn; +import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException; import org.apache.hadoop.hive.ql.optimizer.calcite.HiveCalciteUtil; import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAggregate; import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveGroupingID; @@ -83,29 +84,29 @@ private boolean isDistinctUDAF; private String udafName; private GenericUDAFEvaluator udafEvaluator; - private ArrayList udafParams = new ArrayList(); + private final ArrayList udafParams = new ArrayList(); private List udafParamsIndxInGBInfoDistExprs = new ArrayList(); }; private static class GBInfo { - private List outputColNames = new ArrayList(); + private final List outputColNames = new ArrayList(); - private List gbKeyColNamesInInput = new ArrayList(); - private List gbKeyTypes = new ArrayList(); - private List gbKeys = new ArrayList(); + private final List gbKeyColNamesInInput = new ArrayList(); + private final List gbKeyTypes = new ArrayList(); + private final List gbKeys = new ArrayList(); - private List grpSets = new ArrayList(); + private final List grpSets = new ArrayList(); private boolean grpSetRqrAdditionalMRJob; private boolean grpIdFunctionNeeded; - private List distExprNames = new ArrayList(); - private List distExprTypes = new ArrayList(); - private List distExprNodes = new ArrayList(); - private List> distColIndices = new ArrayList>(); + private final List distExprNames = new ArrayList(); + private final List distExprTypes = new ArrayList(); + private final List distExprNodes = new ArrayList(); + private final List> distColIndices = new ArrayList>(); - private List deDupedNonDistIrefs = new ArrayList(); + private final List deDupedNonDistIrefs = new ArrayList(); - private List udafAttrs = new ArrayList(); + private final List udafAttrs = new ArrayList(); private boolean containsDistinctAggr = false; float groupByMemoryUsage; @@ -144,7 +145,7 @@ private static HIVEGBPHYSICALMODE getAggOPMode(HiveConf hc, GBInfo gbInfo) { // For each of the GB op in the logical GB this should be called seperately; // otherwise GBevaluator and expr nodes may get shared among multiple GB ops - private static GBInfo getGBInfo(HiveAggregate aggRel, OpAttr inputOpAf, HiveConf hc) { + private static GBInfo getGBInfo(HiveAggregate aggRel, OpAttr inputOpAf, HiveConf hc) throws SemanticException { GBInfo gbInfo = new GBInfo(); // 0. Collect AggRel output col Names @@ -157,7 +158,7 @@ private static GBInfo getGBInfo(HiveAggregate aggRel, OpAttr inputOpAf, HiveConf ExprNodeDesc tmpExprNodeDesc; for (int i : aggRel.getGroupSet()) { - RexInputRef iRef = new RexInputRef(i, (RelDataType) aggInputRel.getRowType().getFieldList() + RexInputRef iRef = new RexInputRef(i, aggInputRel.getRowType().getFieldList() .get(i).getType()); tmpExprNodeDesc = iRef.accept(exprConv); gbInfo.gbKeys.add(tmpExprNodeDesc); @@ -250,13 +251,12 @@ private static GBInfo getGBInfo(HiveAggregate aggRel, OpAttr inputOpAf, HiveConf udafAttrs.udafParamsIndxInGBInfoDistExprs = distUDAFParamsIndxInDistExprs; gbInfo.distColIndices.add(distColIndicesOfUDAF); } - try { + + // special handling for count, similar to PlanModifierForASTConv::replaceEmptyGroupAggr() udafAttrs.udafEvaluator = SemanticAnalyzer.getGenericUDAFEvaluator(udafAttrs.udafName, new ArrayList(udafAttrs.udafParams), new ASTNode(), - udafAttrs.isDistinctUDAF, false); - } catch (SemanticException e) { - throw new RuntimeException(e); - } + udafAttrs.isDistinctUDAF, udafAttrs.udafParams.size() == 0 && + "count".equalsIgnoreCase(udafAttrs.udafName) ? true : false); gbInfo.udafAttrs.add(udafAttrs); } @@ -301,10 +301,10 @@ static OpAttr translateGB(OpAttr inputOpAf, HiveAggregate aggRel, HiveConf hc) /** * GB-RS-GB1 - * + * * Construct GB-RS-GB Pipe line. User has enabled Map Side GB, specified no * skew and Grp Set is below the threshold. - * + * * @param inputOpAf * @param aggRel * @param gbInfo @@ -361,7 +361,7 @@ private static OpAttr genGBRSGBRSGBOpPipeLine(OpAttr inputOpAf, HiveAggregate ag /** * GB-RS-GB1-RS-GB2 - * + * * @param inputOpAf * @param aggRel * @param gbInfo @@ -384,7 +384,7 @@ private static OpAttr genMapSideGBNoSkewAddMRJob(OpAttr inputOpAf, HiveAggregate /** * GB-RS-GB1-RS-GB2 - * + * * @param inputOpAf * @param aggRel * @param gbInfo @@ -407,7 +407,7 @@ private static OpAttr genMapSideGBSkewGBKeysOrDistUDAFPresent(OpAttr inputOpAf, /** * GB-RS-GB2 - * + * * @param inputOpAf * @param aggRel * @param gbInfo @@ -442,7 +442,7 @@ private static OpAttr genMapSideGBSkewGBKeysAndDistUDAFNotPresent(OpAttr inputOp /** * RS-Gb1 - * + * * @param inputOpAf * @param aggRel * @param gbInfo @@ -465,7 +465,7 @@ private static OpAttr genNoMapSideGBNoSkew(OpAttr inputOpAf, HiveAggregate aggRe /** * RS-GB1-RS-GB2 - * + * * @param inputOpAf * @param aggRel * @param gbInfo @@ -940,7 +940,7 @@ private static OpAttr genReduceSideGB1(OpAttr inputOpAf, GBInfo gbInfo, boolean /** * RS-GB0 - * + * * @param inputOpAf * @param gbInfo * @param gbMode @@ -1141,7 +1141,7 @@ private static void addGrpSetCol(boolean createConstantExpr, String grpSetIDExpr /** * Get Reduce Keys for RS following MapSide GB - * + * * @param reduceKeys * assumed to be deduped list of exprs * @param outputKeyColumnNames @@ -1181,7 +1181,7 @@ private static void addGrpSetCol(boolean createConstantExpr, String grpSetIDExpr /** * Get Value Keys for RS following MapSide GB - * + * * @param GroupByOperator * MapSide GB * @param outputKeyColumnNames