mayankshriv commented on a change in pull request #4629: Put order-by
expressions in front of selection expreesions in selection DataSchema
URL: https://github.com/apache/incubator-pinot/pull/4629#discussion_r327225380
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/query/reduce/BrokerReduceService.java
##########
@@ -527,4 +524,161 @@ private void setGroupByHavingResults(@Nonnull
BrokerResponseNative brokerRespons
"There should be minimum one aggregation function in the select list
of a Group by query");
}
}
+
+ /**
+ * Following part are temporary code to handle the selection query with
different DataSchema returned from different
+ * servers.
+ * TODO: Remove the code after all servers are migrated to the current
version.
+ */
+
+ private static DataSchema getCorrectDataSchema(Selection selection,
DataSchema dataSchema) {
+ String[] columnNames = dataSchema.getColumnNames();
+ Map<String, Integer> columnToIndexMap =
SelectionOperatorUtils.getColumnToIndexMap(columnNames);
+
+ Set<String> columnSet = new HashSet<>();
+ List<String> correctColumns = new ArrayList<>();
+
+ // Put order-by columns at the front
+ List<SelectionSort> sortSequence = selection.getSelectionSortSequence();
+ if (sortSequence != null) {
+ for (SelectionSort selectionSort : sortSequence) {
+ String column = selectionSort.getColumn();
+ if (columnSet.add(column)) {
+ correctColumns.add(column);
+ }
+ }
+ }
+
+ List<String> selectionColumns = selection.getSelectionColumns();
+ if (selectionColumns.size() == 1 && selectionColumns.get(0).equals("*")) {
+ selectionColumns = new ArrayList<>();
+ for (String column : columnToIndexMap.keySet()) {
+ if
(TransformExpressionTree.compileToExpressionTree(column).getExpressionType()
+ == TransformExpressionTree.ExpressionType.IDENTIFIER) {
+ selectionColumns.add(column);
+ }
+ }
+ selectionColumns.sort(null);
+ }
+ for (String column : selectionColumns) {
+ if (columnSet.add(column)) {
+ correctColumns.add(column);
+ }
+ }
+
+ int numCorrectColumns = correctColumns.size();
+ String[] correctColumnNames = new String[numCorrectColumns];
+ DataSchema.ColumnDataType[] correctColumnDataTypes = new
DataSchema.ColumnDataType[numCorrectColumns];
+ DataSchema.ColumnDataType[] columnDataTypes =
dataSchema.getColumnDataTypes();
+ for (int i = 0; i < numCorrectColumns; i++) {
+ String correctColumn = correctColumns.get(i);
+ correctColumnNames[i] = correctColumn;
+ correctColumnDataTypes[i] =
columnDataTypes[columnToIndexMap.get(correctColumn)];
+ }
+ return new DataSchema(correctColumnNames, correctColumnDataTypes);
+ }
+
+ private static class CorrectDataTable implements DataTable {
Review comment:
`Correct` is probably not the right naming here, may be something like
`canonical`?
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]