yujun777 commented on code in PR #46468: URL: https://github.com/apache/doris/pull/46468#discussion_r1906527773
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OrToIn.java: ########## @@ -33,60 +30,112 @@ import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.util.ExpressionUtils; -import org.apache.doris.nereids.util.MutableState; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** - * dependends on SimplifyRange rule + * Do NOT use this rule in ExpressionOptimization + * apply this rule on filter expressions in extract mode, + * on other expressions in replace mode * */ -public class OrToIn implements ExpressionPatternRuleFactory { +public class OrToIn { + /** + * case 1: from (a=1 and b=1) or (a=2), "a in (1, 2)" is inferred, + * inferred expr is not equivalent to the original expr + * - replaceMode: output origin expr + * - extractMode: output a in (1, 2) and (a=1 and b=1) or (a=2) + * + * case 2: from (a=1) or (a=2), "a in (1,2)" is inferred, the inferred expr is equivalent to the original expr + * - replaceMode/extractMode: output a in (1, 2) + * + * extractMode only used for filter, the inferred In-predicate could be pushed down. + */ + public enum Mode { + replaceMode, + extractMode + } - public static final OrToIn INSTANCE = new OrToIn(); + public static final OrToIn EXTRACT_MODE_INSTANCE = new OrToIn(Mode.extractMode); + public static final OrToIn REPLACE_MODE_INSTANCE = new OrToIn(Mode.replaceMode); public static final int REWRITE_OR_TO_IN_PREDICATE_THRESHOLD = 2; - @Override - public List<ExpressionPatternMatcher<? extends Expression>> buildRules() { - return ImmutableList.of( - matchesTopType(Or.class).then(OrToIn.INSTANCE::rewrite) - .toRule(ExpressionRuleType.OR_TO_IN) Review Comment: remove OR_TO_IN in enum ExpressionRuleType -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org