lowka commented on code in PR #1982: URL: https://github.com/apache/ignite-3/pull/1982#discussion_r1177408301
########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/Hints.java: ########## @@ -0,0 +1,132 @@ +/* + * 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.ignite.internal.sql.engine.util; + +import static org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.StringJoiner; +import java.util.stream.Collectors; +import org.apache.calcite.rel.hint.RelHint; + +/** + * Enumeration of supported SQL hints together with help methods. + */ +public enum Hints { + //Only for test purpose!!! No any product use and not available for user + DISABLE_RULE(true), + //Disable commute joins and keeps the join order defined by the user in a query + ENFORCE_JOIN_ORDER, + EXPAND_DISTINCT_AGG; + + private boolean paramSupport; + + /** + * Constructor. + * + * @param paramSupport Flag indicating whether hint options are supported. + */ + Hints(boolean paramSupport) { + this.paramSupport = paramSupport; + } + + /** + * Constructor. Use for hint without parameters support. + */ + Hints() { + this(false); + } + + /** + * Check is passed hint belong to concrete hint type. + * + * @param hint Checking hint. + * @return {@code true} If the given hint belong to concrete type, {@code false} otherwise. + */ + public boolean is(RelHint hint) { + return name().equals(hint.hintName); + } + + /** + * Return {@code true} if the hint presents in provided hint list. + * + * @param hints Hints. + * @return {@code true} If found the hint, {@code false} otherwise. + */ + public boolean present(List<RelHint> hints) { + return hints.stream().anyMatch(this::is); + } + + /** + * Return {@code true} if the the hint presents in provided hint list and options are presents. + * + * @param hints Hints. + * @return {@code true} If found the hint with rules for disabling, {@code false} otherwise. + */ + public boolean presentWithParams(List<RelHint> hints) { Review Comment: I think it would be better to convert Hints to a close hierarchy of classes and have a single method that transforms a collection of RelHint s to Hints supported by ignite. It would allow this would make `present` method redundant and would allow to keep only a single variant of `toHint`. ########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AbstractPlannerTest.java: ########## @@ -1318,4 +1344,49 @@ public Publisher<BinaryRow> lookup(int partId, HybridTimestamp timestamp, Cluste Predicate<SearchBounds> empty() { return Objects::isNull; } + + /** + * Wrapper for RelOptListener with empty realization for each of their methods. Good choice in case you need implement just one or few + * methods for listener. + */ + static class RelOptListenerWrapper implements RelOptListener { + + @Override + public void relEquivalenceFound(RelEquivalenceEvent event) {} + + @Override + public void ruleAttempted(RuleAttemptedEvent event) {} + + @Override + public void ruleProductionSucceeded(RuleProductionEvent event) {} + + @Override + public void relDiscarded(RelDiscardedEvent event) {} + + @Override + public void relChosen(RelChosenEvent event) {} + } + + /** + * Listener which keeps information about attempts of applying optimization rules. + */ + public class RuleAttemptListener extends RelOptListenerWrapper { + Set<String> attemptedRules = new HashSet<>(); + + @Override + public void ruleAttempted(final RuleAttemptedEvent event) { + if (event.isBefore()) { + attemptedRules.add(event.getRuleCall().getRule().toString()); + System.out.println(event.getRuleCall().getRule().toString()); Review Comment: Is this print to stdout necessary? -- 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]
