richardstartin commented on a change in pull request #8138: URL: https://github.com/apache/pinot/pull/8138#discussion_r800106151
########## File path: pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CaseTransformFunction.java ########## @@ -185,21 +188,29 @@ public TransformResultMetadata getResultMetadata() { * index(1 to N) of matched WHEN clause, 0 means nothing matched, so go to ELSE. */ private int[] getSelectedArray(ProjectionBlock projectionBlock) { - if (_selectedResults == null) { - _selectedResults = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL]; + int numDocs = projectionBlock.getNumDocs(); + if (_selectedResults == null || _selectedResults.length < numDocs) { + _selectedResults = new int[numDocs]; } else { - Arrays.fill(_selectedResults, 0); + Arrays.fill(_selectedResults, 0, numDocs, 0); + Arrays.fill(_selections, false); } int numWhenStatements = _whenStatements.size(); - for (int i = 0; i < numWhenStatements; i++) { + for (int i = numWhenStatements - 1; i >= 0; i--) { TransformFunction whenStatement = _whenStatements.get(i); int[] conditions = whenStatement.transformToIntValuesSV(projectionBlock); - for (int j = 0; j < conditions.length; j++) { - if (_selectedResults[j] == 0 && conditions[j] == 1) { - _selectedResults[j] = i + 1; - } + for (int j = 0; j < numDocs & j < conditions.length; j++) { + _selectedResults[j] = Math.max(conditions[j] * (i + 1), _selectedResults[j]); + _selections[_selectedResults[j]] = true; } } + int numSelections = 0; + for (boolean selection : _selections) { + if (selection) { + numSelections++; + } + } + _numSelections = numSelections; Review comment: Assuming you have fewer than 64 cases (a large case statement) all updates to the bitmap would be to the same word, which creates a data dependency in the loop, which slows the loop down. -- 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