Jackie-Jiang commented on a change in pull request #5867: URL: https://github.com/apache/incubator-pinot/pull/5867#discussion_r472409505
########## File path: pinot-core/src/main/java/org/apache/pinot/core/query/reduce/GroupByDataTableReducer.java ########## @@ -160,103 +160,49 @@ 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); Iterator<Record> sortedIterator = indexedTable.iterator(); + DataSchema prePostAggregationDataSchema = getPrePostAggregationDataSchema(dataSchema); int limit = _queryContext.getLimit(); List<Object[]> rows = new ArrayList<>(limit); + for (int i = 0; i < limit && sortedIterator.hasNext(); i++) { + Object[] row = sortedIterator.next().getValues(); + for (int j = 0; j < _numAggregationFunctions; j++) { + int valueIndex = j + _numGroupByExpressions; + row[valueIndex] = + AggregationFunctionUtils.getSerializableValue(_aggregationFunctions[j].extractFinalResult(row[valueIndex])); + } + rows.add(row); + } if (_sqlQuery) { // SQL query with SQL group-by mode and response format - // NOTE: For SQL query, need to reorder the columns in the data table based on the select expressions. - - int[] selectExpressionIndexMap = getSelectExpressionIndexMap(); - int numSelectExpressions = selectExpressionIndexMap.length; - String[] columnNames = resultTableSchema.getColumnNames(); - DataSchema.ColumnDataType[] columnDataTypes = resultTableSchema.getColumnDataTypes(); - String[] reorderedColumnNames = new String[numSelectExpressions]; - DataSchema.ColumnDataType[] reorderedColumnDataTypes = new DataSchema.ColumnDataType[numSelectExpressions]; - resultTableSchema = new DataSchema(reorderedColumnNames, reorderedColumnDataTypes); - for (int i = 0; i < numSelectExpressions; i++) { - reorderedColumnNames[i] = columnNames[selectExpressionIndexMap[i]]; - reorderedColumnDataTypes[i] = columnDataTypes[selectExpressionIndexMap[i]]; - } - while (rows.size() < limit && sortedIterator.hasNext()) { - Record nextRecord = sortedIterator.next(); - Object[] values = nextRecord.getValues(); - for (int i = 0; i < _numAggregationFunctions; i++) { - int valueIndex = i + _numGroupByExpressions; - values[valueIndex] = AggregationFunctionUtils - .getSerializableValue(_aggregationFunctions[i].extractFinalResult(values[valueIndex])); - } - Object[] reorderedValues = new Object[numSelectExpressions]; Review comment: Good point. Added comment inside `PostAggregationHandler` stating that the column re-ordering is handled inside. ---------------------------------------------------------------- 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