npawar commented on a change in pull request #5867:
URL: https://github.com/apache/incubator-pinot/pull/5867#discussion_r472381824
##########
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:
looks like the reordering logic happens within postAggregationHandler,
whether we have post aggregations functions or not? Can we add a comment either
here or inside postAggregationHandler, that reordering is handled as one of the
post aggregation operations?
##########
File path:
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java
##########
@@ -231,6 +231,13 @@ public void testHardcodedSqlQueries()
testSqlQuery(query, Collections.singletonList(query));
query = "SELECT MAX(ArrDelay), Month FROM mytable GROUP BY Month ORDER BY
ABS(Month - 6) + MAX(ArrDelay)";
testSqlQuery(query, Collections.singletonList(query));
+
+ // Post-aggregation in SELECT
Review comment:
how about adding a query with literals
----------------------------------------------------------------
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]