siddharthteotia commented on a change in pull request #5605: URL: https://github.com/apache/incubator-pinot/pull/5605#discussion_r445221833
########## 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) { + // NOTE: For SQL query, need to reorder the columns in the data table based on the select expressions. + + int[] selectExpressionIndexMap = getSelectExpressionIndexMap(); Review comment: Should add a comment here that this is for SQL query compiled by calcite compiler, parser and having both the options (groupByModeSql and responseFormatSqL to true). Eventually we just want this path (SQL only) after PQL is completely deleted. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org