You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/09/16 02:09:48 UTC

[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9406: [multistage] Initial commit to support h2 testing

siddharthteotia commented on code in PR #9406:
URL: https://github.com/apache/pinot/pull/9406#discussion_r972549589


##########
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:
   (nit) can avoid this if check by creating comparators upfront in the constructor



-- 
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-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org