Jackie-Jiang commented on code in PR #11307: URL: https://github.com/apache/pinot/pull/11307#discussion_r1290573005
########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java: ########## @@ -1075,6 +1107,48 @@ private static void handleDistinctCountBitmapOverride(PinotQuery pinotQuery) { } } + /** + * Rewrites selected 'Distinct' prefixed function to 'Distinct----MV' function for the field of multivalued type. + */ + @VisibleForTesting + static void handleDistinctMultiValuedOverride(PinotQuery pinotQuery, Set<String> multiValuedDimColumns) { + for (Expression expression : pinotQuery.getSelectList()) { + handleDistinctMultiValuedOverride(expression, multiValuedDimColumns); + } + List<Expression> orderByExpressions = pinotQuery.getOrderByList(); + if (orderByExpressions != null) { + for (Expression expression : orderByExpressions) { + // NOTE: Order-by is always a Function with the ordering of the Expression + handleDistinctMultiValuedOverride(expression.getFunctionCall().getOperands().get(0), multiValuedDimColumns); + } + } + Expression havingExpression = pinotQuery.getHavingExpression(); + if (havingExpression != null) { + handleDistinctMultiValuedOverride(havingExpression, multiValuedDimColumns); + } + } + + /** + * Rewrites selected 'Distinct' prefixed function to 'Distinct----MV' function for the field of multivalued type. + */ + private static void handleDistinctMultiValuedOverride(Expression expression, Set<String> multiValuedDimColumns) { + Function function = expression.getFunctionCall(); + if (function == null) { + return; + } + if (function.getOperator() != null && DISTINCT_MV_COL_FUNCTION_OVERRIDE_MAP.containsKey(function.getOperator())) { Review Comment: (minor) We can save one map lookup by directly call `get()` and check if the result is `null` ########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java: ########## @@ -942,6 +950,30 @@ private static Set<String> getSegmentPartitionedColumns(@Nullable TableConfig ta return segmentPartitionedColumns; } + /** + * Retrieve multivalued columns for a table. + * From the table Schema , we get the multi valued columns of dimension fields. + * + * @param tableCache + * @param tableName + * @return multivalued columns of the table . + */ + private static Set<String> getMultiValuedColumns(TableCache tableCache, String tableName) { Review Comment: This is not efficient. We can just look up on demand for each column in the aggregation -- 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