diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/metainfo/annotation/OpTraitsRulesProcFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/metainfo/annotation/OpTraitsRulesProcFactory.java index 263770e877..89db530f54 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/metainfo/annotation/OpTraitsRulesProcFactory.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/metainfo/annotation/OpTraitsRulesProcFactory.java @@ -308,44 +308,40 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, public static class SelectRule implements NodeProcessor { - boolean processSortCols = false; - // For bucket columns // If all the columns match to the parent, put them in the bucket cols // else, add empty list. // For sort columns // Keep the subset of all the columns as long as order is maintained. public List> getConvertedColNames( - List> parentColNames, SelectOperator selOp) { + List> parentColNames, SelectOperator selOp, boolean processSortCols) { List> listBucketCols = new ArrayList<>(); - if (selOp.getColumnExprMap() != null) { - if (parentColNames != null) { - for (List colNames : parentColNames) { - List bucketColNames = new ArrayList<>(); - boolean found = false; - for (String colName : colNames) { - for (Entry entry : selOp.getColumnExprMap().entrySet()) { - if ((entry.getValue() instanceof ExprNodeColumnDesc) && - (((ExprNodeColumnDesc) (entry.getValue())).getColumn().equals(colName))) { - bucketColNames.add(entry.getKey()); - found = true; - break; - } - } - if (!found) { - // Bail out on first missed column. - break; - } - } - if (!processSortCols && !found) { - // While processing bucket columns, atleast one bucket column - // missed. This results in a different bucketing scheme. - // Add empty list - listBucketCols.add(new ArrayList<>()); - } else { - listBucketCols.add(bucketColNames); + for (List colNames : parentColNames) { + List bucketColNames = new ArrayList<>(); + boolean found = false; + for (String colName : colNames) { + // Reset found + found = false; + for (Entry entry : selOp.getColumnExprMap().entrySet()) { + if ((entry.getValue() instanceof ExprNodeColumnDesc) && + (((ExprNodeColumnDesc) (entry.getValue())).getColumn().equals(colName))) { + bucketColNames.add(entry.getKey()); + found = true; + break; } } + if (!found) { + // Bail out on first missed column. + break; + } + } + if (!processSortCols && !found) { + // While processing bucket columns, atleast one bucket column + // missed. This results in a different bucketing scheme. + // Add empty list + listBucketCols.add(new ArrayList<>()); + } else { + listBucketCols.add(bucketColNames); } } @@ -363,13 +359,12 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, List> listSortCols = null; if (selOp.getColumnExprMap() != null) { if (parentBucketColNames != null) { - listBucketCols = getConvertedColNames(parentBucketColNames, selOp); + listBucketCols = getConvertedColNames(parentBucketColNames, selOp, false); } List> parentSortColNames = selOp.getParentOperators().get(0).getOpTraits().getSortCols(); if (parentSortColNames != null) { - processSortCols = true; - listSortCols = getConvertedColNames(parentSortColNames, selOp); + listSortCols = getConvertedColNames(parentSortColNames, selOp, true); } }