Jackie-Jiang commented on a change in pull request #5605:
URL: https://github.com/apache/incubator-pinot/pull/5605#discussion_r445180740



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/reduce/GroupByDataTableReducer.java
##########
@@ -171,106 +160,81 @@ public void reduceAndSetResults(String tableName, 
DataSchema dataSchema,
    */
   private void setSQLGroupByInResultTable(BrokerResponseNative 
brokerResponseNative, DataSchema dataSchema,
       Collection<DataTable> dataTables) {
-
+    DataSchema resultTableSchema = getSQLResultTableSchema(dataSchema);
     IndexedTable indexedTable = getIndexedTable(dataSchema, dataTables);
-
-    int[] finalSchemaMapIdx = null;
-    if (_sqlSelectionList != null) {
-      finalSchemaMapIdx = getFinalSchemaMapIdx();
-    }
-    List<Object[]> rows = new ArrayList<>();
     Iterator<Record> sortedIterator = indexedTable.iterator();
-    int numRows = 0;
-    while (numRows < _groupBy.getTopN() && sortedIterator.hasNext()) {
-      Record nextRecord = sortedIterator.next();
-      Object[] values = nextRecord.getValues();
-
-      int index = _numGroupBy;
-      int aggNum = 0;
-      while (index < _numColumns) {
-        values[index] = AggregationFunctionUtils
-            
.getSerializableValue(_aggregationFunctions[aggNum++].extractFinalResult(values[index]));
-        index++;
+    int limit = _queryContext.getLimit();
+    List<Object[]> rows = new ArrayList<>(limit);
+
+    if (_sqlQuery) {

Review comment:
       `getFinalSchemaMapIdx` is renamed to `getSelectExpressionIndexMap` for 
readability.
   
   The existing logic keeps the sql query check inside the loop, which is not 
efficient and not as readable IMO. The change makes the sql query check at the 
top level, and once we move to SQL completely, we can simply remove the `else` 
part.




----------------------------------------------------------------
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.

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