Jackie-Jiang commented on a change in pull request #7184: URL: https://github.com/apache/pinot/pull/7184#discussion_r675899237
########## 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: Hmm, seems in the composite predicate the type can only be `OR` or `PREDICATE`. We should make it clear with some comments -- 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