kgyrtkirk commented on code in PR #17541: URL: https://github.com/apache/druid/pull/17541#discussion_r1886674436
########## sql/src/main/java/org/apache/druid/sql/calcite/planner/JoinHint.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.sql.calcite.planner; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.query.JoinAlgorithm; + +import java.util.Arrays; + +public enum JoinHint Review Comment: doesn't really mattter - I was just thinking something like: ``` public abstract class DruidHint { abstract T as(Class<T> clazz); public static DruidHint fromRelHint(RelHint rh) { // factory method } static abstrat class DruidJoinHint extends DruidHint {} static class SortMerge extends DruidJoinHint { String name() { "sort_merge"; } as() ... { return } } ``` ########## sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java: ########## @@ -502,4 +505,25 @@ void from(CalcitePlanner planner) + " to " + this); } } + + /** + * Define some tool members and methods for hints. + */ + private static class HintTools + { + static final HintStrategyTable HINT_STRATEGY_TABLE = createHintStrategies(); + + /** + * Creates hint strategies. + * + * @return HintStrategyTable instance + */ + private static HintStrategyTable createHintStrategies() + { + return HintStrategyTable.builder() + .hintStrategy(JoinHint.BROADCAST.name(), HintPredicates.JOIN) Review Comment: is the usage of `name()` intended here? because I think that will return `BROADCAST` the "name" of the enum key and not the `id`! ########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/DataSourcePlan.java: ########## @@ -212,18 +212,21 @@ public static DataSourcePlan forDataSource( broadcast ); } else if (dataSource instanceof JoinDataSource) { - final JoinAlgorithm preferredJoinAlgorithm = PlannerContext.getJoinAlgorithm(queryContext); + JoinDataSource joinDataSource = (JoinDataSource) dataSource; + final JoinAlgorithm preferredJoinAlgorithm = joinDataSource.getJoinAlgorithm() != null + ? joinDataSource.getJoinAlgorithm() + : PlannerContext.getJoinAlgorithm(queryContext); Review Comment: this `?:` is not necessary as `joinDataSource.getJoinAlgorithm()` will never return null ########## sql/src/main/java/org/apache/druid/sql/calcite/planner/JoinHint.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.sql.calcite.planner; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.query.JoinAlgorithm; + +import java.util.Arrays; + +public enum JoinHint +{ + SORT_MERGE("sort_merge") { + @Override + public JoinAlgorithm getJoinAlgorithm() + { + return JoinAlgorithm.SORT_MERGE; + } + }, + BROADCAST("broadcast") { + @Override + public JoinAlgorithm getJoinAlgorithm() + { + return JoinAlgorithm.BROADCAST; + } + }; + + private final String id; + + JoinHint(String id) + { + this.id = id; + } + + @JsonCreator + public static JoinHint fromString(final String id) + { Review Comment: I don't think this `JoinHint` should be serialized if its not in use I think it would be better to remove it ########## processing/src/main/java/org/apache/druid/query/JoinDataSource.java: ########## @@ -96,17 +96,32 @@ public class JoinDataSource implements DataSource private final DimFilter leftFilter; @Nullable private final JoinableFactoryWrapper joinableFactoryWrapper; + private final JoinAlgorithm joinAlgorithm; private static final Logger log = new Logger(JoinDataSource.class); private final DataSourceAnalysis analysis; +// private JoinDataSource() Review Comment: nit: comments ########## sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java: ########## @@ -502,4 +505,25 @@ void from(CalcitePlanner planner) + " to " + this); } } + + /** + * Define some tool members and methods for hints. + */ + private static class HintTools + { + static final HintStrategyTable HINT_STRATEGY_TABLE = createHintStrategies(); + + /** + * Creates hint strategies. + * + * @return HintStrategyTable instance + */ + private static HintStrategyTable createHintStrategies() + { + return HintStrategyTable.builder() + .hintStrategy(JoinHint.BROADCAST.name(), HintPredicates.JOIN) Review Comment: note: this method returning `HintStrategyTable` could live inside `DruidHint` if that's created -- 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]
