deniskuzZ commented on code in PR #5409: URL: https://github.com/apache/hive/pull/5409#discussion_r1813128753
########## ql/src/java/org/apache/hadoop/hive/ql/optimizer/metainfo/annotation/OpTraitsRulesProcFactory.java: ########## @@ -158,8 +158,57 @@ public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, } } - listBucketCols.add(bucketCols); - OpTraits opTraits = new OpTraits(listBucketCols, numBuckets, + final List<List<String>> listBucketCols = new ArrayList<>(); + final List<CustomBucketFunction> bucketFunctions = new ArrayList<>(); + final int numBuckets; + if (parentOpTraits == null || !parentOpTraits.hasCustomBucketFunction()) { + // No CustomBucketFunctions + listBucketCols.add(bucketCols); + bucketFunctions.add(null); + numBuckets = parentOpTraits == null ? -1 : parentOpTraits.getNumBuckets(); + } else if (parentOpTraits.getCustomBucketFunctions().size() > 1) { + // We don't know how to merge multiple custom bucket functions. Reset bucket attributes + Preconditions.checkState(parentOpTraits.getBucketColNames().size() > 1); + listBucketCols.add(Collections.emptyList()); + bucketFunctions.add(null); + numBuckets = -1; + } else { + Preconditions.checkState(parentOpTraits.getBucketColNames().size() == 1); + Preconditions.checkState(parentOpTraits.getCustomBucketFunctions().size() == 1); + final Map<String, String> inputToOutput = rs + .getColumnExprMap() + .entrySet() + .stream() + .filter(entry -> entry.getValue() instanceof ExprNodeColumnDesc) + .filter(entry -> rs.getConf().getKeyCols().stream().anyMatch(keyDesc -> keyDesc.isSame(entry.getValue()))) + .collect(Collectors.toMap( + entry -> ((ExprNodeColumnDesc) entry.getValue()).getColumn(), + Entry::getKey, + (a, b) -> a) + ); + final List<String> parentBucketColNames = parentOpTraits.getBucketColNames().get(0); + final boolean[] retainedColumns = new boolean[parentBucketColNames.size()]; + final List<String> rsBucketColNames = new ArrayList<>(); + for (int i = 0; i < parentBucketColNames.size(); i++) { + final String rsColumnName = inputToOutput.get(parentBucketColNames.get(i)); + retainedColumns[i] = rsColumnName != null; Review Comment: default is false anyways so we could save on the boolean condition evaluation -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org