siddharthteotia commented on code in PR #9406: URL: https://github.com/apache/pinot/pull/9406#discussion_r972550066
########## pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/SortOperator.java: ########## @@ -129,14 +124,44 @@ private void consumeInputBlocks() { } } - private List<OrderByExpressionContext> toOrderByExpressions(List<RexExpression> collationKeys, - List<RelFieldCollation.Direction> collationDirections) { - List<OrderByExpressionContext> orderByExpressionContextList = new ArrayList<>(collationKeys.size()); - for (int i = 0; i < collationKeys.size(); i++) { - orderByExpressionContextList.add(new OrderByExpressionContext(ExpressionContext.forIdentifier( - _dataSchema.getColumnName(((RexExpression.InputRef) collationKeys.get(i)).getIndex())), - !collationDirections.get(i).isDescending())); + private static class SortComparator implements Comparator<Object[]> { + private final int _size; + private final int[] _valueIndices; + private final int[] _multipliers; + private final boolean[] _useDoubleComparison; + + public SortComparator(List<RexExpression> collationKeys, List<RelFieldCollation.Direction> collationDirections, + DataSchema dataSchema, boolean isNullHandlingEnabled) { + DataSchema.ColumnDataType[] columnDataTypes = dataSchema.getColumnDataTypes(); + _size = collationKeys.size(); + _valueIndices = new int[_size]; + _multipliers = new int[_size]; + _useDoubleComparison = new boolean[_size]; + for (int i = 0; i < _size; i++) { + _valueIndices[i] = ((RexExpression.InputRef) collationKeys.get(i)).getIndex(); + _multipliers[i] = collationDirections.get(i).isDescending() ? 1 : -1; + _useDoubleComparison[i] = columnDataTypes[_valueIndices[i]].isNumber(); + } + } + + @Override + public int compare(Object[] o1, Object[] o2) { + for (int i = 0; i < _size; i++) { + int index = _valueIndices[i]; + Object v1 = o1[index]; + Object v2 = o2[index]; + int result; + if (_useDoubleComparison[i]) { Review Comment: Actually nvm... it may then have to dereference the actual comparator anyway for dynamic dispatch. So probably not worth it -- 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