Jackie-Jiang commented on code in PR #16308:
URL: https://github.com/apache/pinot/pull/16308#discussion_r2208513907


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/GroupByCombineOperator.java:
##########
@@ -99,11 +113,83 @@ public String toExplainString() {
     return EXPLAIN_NAME;
   }
 
+  ///  merge sorted segment results
+  private void processSafeTrim() {

Review Comment:
   We can probably also compare sequential merge performance given the merge 
should be very cheap with low `limit`



##########
pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java:
##########
@@ -541,6 +545,20 @@ public boolean isUnsafeTrim() {
     return _isUnsafeTrim;
   }
 
+  public boolean shouldSortAggregate() {
+    return !isUnsafeTrim() && _limit < 
Server.DEFAULT_SORT_AGGREGATE_LIMIT_THRESHOLD;
+  }
+
+  public Comparator<Key> getGroupKeyComparator() {

Review Comment:
   Is this used?



##########
pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java:
##########
@@ -541,6 +545,20 @@ public boolean isUnsafeTrim() {
     return _isUnsafeTrim;
   }
 
+  public boolean shouldSortAggregate() {
+    return !isUnsafeTrim() && _limit < 
Server.DEFAULT_SORT_AGGREGATE_LIMIT_THRESHOLD;

Review Comment:
   Let's make this threshold configurable, similar to other group-by thresholds



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/GroupByCombineOperator.java:
##########
@@ -80,11 +88,17 @@ public GroupByCombineOperator(List<Operator> operators, 
QueryContext queryContex
     _numGroupByExpressions = _queryContext.getGroupByExpressions().size();
     _numColumns = _numGroupByExpressions + _numAggregationFunctions;
     _operatorLatch = new CountDownLatch(_numTasks);
+    if (_queryContext.shouldSortAggregate()) {

Review Comment:
   Consider adding a new combine operator for this new logic. Mixing 2 logic in 
1 combine operator is not very readable



##########
pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java:
##########
@@ -182,8 +187,7 @@ private boolean isSameOrderAndGroupByColumns(QueryContext 
context) {
   }
 
   /**
-   * Returns the table name.
-   * NOTE: on the broker side, table name might be {@code null} when subquery 
is available.
+   * Returns the table name. NOTE: on the broker side, table name might be 
{@code null} when subquery is available.

Review Comment:
   Seems there are several unrelated reformat. Suggest reverting them



##########
pinot-core/src/main/java/org/apache/pinot/core/data/table/LinkedHashMapIndexedTable.java:
##########
@@ -0,0 +1,226 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.data.table;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.operator.blocks.results.GroupByResultsBlock;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.core.util.GroupByUtils;
+
+
+public class LinkedHashMapIndexedTable extends IndexedTable {

Review Comment:
   (optional) Do you see value extending `IndexedTable`? Given the new 
algorithm is very different from the existing one, will it have better 
performance by making a completely new data structure?



##########
pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java:
##########
@@ -541,6 +545,20 @@ public boolean isUnsafeTrim() {
     return _isUnsafeTrim;
   }
 
+  public boolean shouldSortAggregate() {

Review Comment:
   Suggest moving this into `GroupByUtils` because it is specific to the 
group-by combine algorithm. We should also pick a name more specific



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to