gianm commented on code in PR #13506: URL: https://github.com/apache/druid/pull/13506#discussion_r1127468735
########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/kernel/HashShuffleSpec.java: ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.msq.kernel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.druid.frame.key.ClusterBy; +import org.apache.druid.frame.key.ClusterByPartitions; +import org.apache.druid.java.util.common.Either; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.msq.statistics.ClusterByStatisticsCollector; + +import javax.annotation.Nullable; + +public class HashShuffleSpec implements ShuffleSpec +{ + public static final String TYPE = "hash"; + + private final ClusterBy clusterBy; + private final int numPartitions; + + @JsonCreator + public HashShuffleSpec( + @JsonProperty("clusterBy") final ClusterBy clusterBy, + @JsonProperty("partitions") final int numPartitions + ) + { + this.clusterBy = clusterBy; + this.numPartitions = numPartitions; + + if (clusterBy.getBucketByCount() > 0) { + // Only GlobalSortTargetSizeShuffleSpec supports bucket-by. + throw new IAE("Cannot bucket with %s partitioning", TYPE); + } + } + + @Override + public ShuffleKind kind() + { + return clusterBy.sortable() && !clusterBy.isEmpty() ? ShuffleKind.HASH_LOCAL_SORT : ShuffleKind.HASH; + } + + @Override + @JsonProperty + public ClusterBy clusterBy() + { + return clusterBy; + } + + @Override + public boolean doesAggregate() + { + return false; + } + + @Override + public boolean needsStatistics() + { + return false; + } + + @Override + public Either<Long, ClusterByPartitions> generatePartitionsForGlobalSort( + @Nullable ClusterByStatisticsCollector collector, + int maxNumPartitions + ) + { + throw new IllegalStateException("Not a global sort"); + } Review Comment: Hmm. Yes. I think it would need some kind of `.class` or casting stuff. I rejiggered things to have a specialized GlobalSortShuffleSpec interface that only the global-sort stuff implements. Calling code knows to check for this interface if the kind is `GLOBAL_SORT`. I think it's a bit cleaner. Thanks for the suggestion. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
