Jackie-Jiang commented on a change in pull request #7184: URL: https://github.com/apache/pinot/pull/7184#discussion_r675895785
########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/StarTreeUtils.java ########## @@ -179,4 +184,96 @@ public static boolean isFitForStarTree(StarTreeV2Metadata starTreeV2Metadata, // Check predicate columns return starTreeDimensions.containsAll(predicateColumns); } + + /** + * Evaluates a given filter to ascertain if the OR clause is valid for StarTree processing. + * + * StarTree supports OR predicates on a single dimension only (d1 < 10 OR d1 > 50). + * + * @return Pair of the result and the single literal on which the predicate is based. If the + * predicate is not valid for execution on StarTree, literal value will be null + */ + private static Pair<Boolean, String> isOrClauseValidForStarTree(FilterContext filterContext) { + assert filterContext != null; + + Set<String> seenLiterals = new HashSet<>(); + + if (!isOrClauseValidForStarTreeInternal(filterContext, seenLiterals)) { + return Pair.of(false, null); + } + + boolean result = seenLiterals.size() == 1; + + return Pair.of(result, result ? seenLiterals.iterator().next() : null); + } + + /** Internal processor for the above evaluator */ + private static boolean isOrClauseValidForStarTreeInternal(FilterContext filterContext, Set<String> seenLiterals) { + assert filterContext != null; + + if (filterContext.getType() == FilterContext.Type.OR) { + List<FilterContext> childFilterContexts = filterContext.getChildren(); + + for (FilterContext childFilterContext : childFilterContexts) { + isOrClauseValidForStarTreeInternal(childFilterContext, seenLiterals); Review comment: Return `false` if this method returns `false` ########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/StarTreeUtils.java ########## @@ -179,4 +184,96 @@ public static boolean isFitForStarTree(StarTreeV2Metadata starTreeV2Metadata, // Check predicate columns return starTreeDimensions.containsAll(predicateColumns); } + + /** + * Evaluates a given filter to ascertain if the OR clause is valid for StarTree processing. + * + * StarTree supports OR predicates on a single dimension only (d1 < 10 OR d1 > 50). + * + * @return Pair of the result and the single literal on which the predicate is based. If the + * predicate is not valid for execution on StarTree, literal value will be null + */ + private static Pair<Boolean, String> isOrClauseValidForStarTree(FilterContext filterContext) { + assert filterContext != null; + + Set<String> seenLiterals = new HashSet<>(); + + if (!isOrClauseValidForStarTreeInternal(filterContext, seenLiterals)) { + return Pair.of(false, null); + } + + boolean result = seenLiterals.size() == 1; + + return Pair.of(result, result ? seenLiterals.iterator().next() : null); + } + + /** Internal processor for the above evaluator */ + private static boolean isOrClauseValidForStarTreeInternal(FilterContext filterContext, Set<String> seenLiterals) { + assert filterContext != null; + + if (filterContext.getType() == FilterContext.Type.OR) { + List<FilterContext> childFilterContexts = filterContext.getChildren(); + + for (FilterContext childFilterContext : childFilterContexts) { + isOrClauseValidForStarTreeInternal(childFilterContext, seenLiterals); + } + } else if (filterContext.getType() == FilterContext.Type.PREDICATE) { + String literalValue = validateExpressionAndExtractIdentifier(filterContext.getPredicate()); + + if (literalValue != null) { + seenLiterals.add(literalValue); + } else { + return false; + } + } + + return true; Review comment: We need to return `false` if `OR` has nested `AND` as child ########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/StarTreeUtils.java ########## @@ -179,4 +184,96 @@ public static boolean isFitForStarTree(StarTreeV2Metadata starTreeV2Metadata, // Check predicate columns return starTreeDimensions.containsAll(predicateColumns); } + + /** + * Evaluates a given filter to ascertain if the OR clause is valid for StarTree processing. + * + * StarTree supports OR predicates on a single dimension only (d1 < 10 OR d1 > 50). + * + * @return Pair of the result and the single literal on which the predicate is based. If the + * predicate is not valid for execution on StarTree, literal value will be null + */ + private static Pair<Boolean, String> isOrClauseValidForStarTree(FilterContext filterContext) { Review comment: We can use `null` to represent invalid or clause, no need to return a pair. ########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/StarTreeUtils.java ########## @@ -179,4 +184,96 @@ public static boolean isFitForStarTree(StarTreeV2Metadata starTreeV2Metadata, // Check predicate columns return starTreeDimensions.containsAll(predicateColumns); } + + /** + * Evaluates a given filter to ascertain if the OR clause is valid for StarTree processing. + * + * StarTree supports OR predicates on a single dimension only (d1 < 10 OR d1 > 50). + * + * @return Pair of the result and the single literal on which the predicate is based. If the + * predicate is not valid for execution on StarTree, literal value will be null + */ + private static Pair<Boolean, String> isOrClauseValidForStarTree(FilterContext filterContext) { + assert filterContext != null; + + Set<String> seenLiterals = new HashSet<>(); Review comment: Rename to `seenIdentifiers` ########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/CompositePredicate.java ########## @@ -0,0 +1,57 @@ +/** + * 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.pinot.core.startree; + +import java.util.ArrayList; +import java.util.List; +import org.apache.pinot.common.request.context.FilterContext; +import org.apache.pinot.core.operator.filter.predicate.PredicateEvaluator; + + +/** + * Represents a composite predicate. + * + * A composite predicate represents a set of predicates conjoined by a given relation. + * Consider the given predicate: (d1 > 10 OR d1 < 50). A composite predicate will represent + * two predicates -- d1 > 10 and d1 < 50 and represent that they are related by the operator OR. + */ +public class CompositePredicate { Review comment: Suggest renaming it to `CompositePredicateEvaluator` to be more precise ########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/operator/StarTreeFilterOperator.java ########## @@ -183,10 +186,12 @@ private BaseFilterOperator getFilterOperator() { // Add remaining predicates for (String remainingPredicateColumn : starTreeResult._remainingPredicateColumns) { - List<PredicateEvaluator> predicateEvaluators = _predicateEvaluatorsMap.get(remainingPredicateColumn); + List<CompositePredicate> predicateEvaluators = _predicateEvaluatorsMap.get(remainingPredicateColumn); DataSource dataSource = _starTreeV2.getDataSource(remainingPredicateColumn); - for (PredicateEvaluator predicateEvaluator : predicateEvaluators) { - childFilterOperators.add(FilterOperatorUtils.getLeafFilterOperator(predicateEvaluator, dataSource, numDocs)); + for (CompositePredicate compositePredicate : predicateEvaluators) { + for (PredicateEvaluator predicateEvaluator : compositePredicate.getPredicateEvaluators()) { Review comment: We need to check the filter type to build the child filter operator. Current code assume the type is `AND` which is not always the case ########## File path: pinot-core/src/main/java/org/apache/pinot/core/startree/StarTreeUtils.java ########## @@ -179,4 +184,96 @@ public static boolean isFitForStarTree(StarTreeV2Metadata starTreeV2Metadata, // Check predicate columns return starTreeDimensions.containsAll(predicateColumns); } + + /** + * Evaluates a given filter to ascertain if the OR clause is valid for StarTree processing. + * + * StarTree supports OR predicates on a single dimension only (d1 < 10 OR d1 > 50). + * + * @return Pair of the result and the single literal on which the predicate is based. If the + * predicate is not valid for execution on StarTree, literal value will be null + */ + private static Pair<Boolean, String> isOrClauseValidForStarTree(FilterContext filterContext) { + assert filterContext != null; + + Set<String> seenLiterals = new HashSet<>(); + + if (!isOrClauseValidForStarTreeInternal(filterContext, seenLiterals)) { + return Pair.of(false, null); + } + + boolean result = seenLiterals.size() == 1; + + return Pair.of(result, result ? seenLiterals.iterator().next() : null); + } + + /** Internal processor for the above evaluator */ + private static boolean isOrClauseValidForStarTreeInternal(FilterContext filterContext, Set<String> seenLiterals) { + assert filterContext != null; + + if (filterContext.getType() == FilterContext.Type.OR) { + List<FilterContext> childFilterContexts = filterContext.getChildren(); + + for (FilterContext childFilterContext : childFilterContexts) { + isOrClauseValidForStarTreeInternal(childFilterContext, seenLiterals); + } Review comment: Return `true` here -- 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...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org