siddharthteotia commented on a change in pull request #4877: Results in 
ResultTable if responseFormat=sql
URL: https://github.com/apache/incubator-pinot/pull/4877#discussion_r353420479
 
 

 ##########
 File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/reduce/DistinctDataTableReducer.java
 ##########
 @@ -115,18 +140,31 @@ public void reduceAndSetResults(String tableName, 
DataSchema dataSchema, Map<Ser
       }
       resultSet.add(distinctRow);
     }
+    return new SelectionResults(Arrays.asList(columnNames), resultSet);
+  }
 
-    // Up until now, we have treated DISTINCT similar to another aggregation 
function even in terms
-    // of the result from function and merging results.
-    // However, the DISTINCT query is just another SELECTION style query from 
the user's point
-    // of view and will return one or records in the result table for the 
column(s) selected and so
-    // for that reason, response from broker should be a selection query 
result.
-    brokerResponseNative.setSelectionResults((new 
SelectionResults(Arrays.asList(columnNames), resultSet)));
+  private ResultTable reduceToResultTable(DistinctTable distinctTable) {
+    List<Object[]> resultSet = new ArrayList<>(distinctTable.size());
+    Iterator<Record> iterator = distinctTable.iterator();
+    while (iterator.hasNext()) {
+      Record record = iterator.next();
+      resultSet.add(record.getValues());
+    }
+    DataSchema finalDataSchema = getResultTableDataSchema();
+    return new ResultTable(finalDataSchema, resultSet);
   }
 
   private String[] getDistinctColumns() {
     return _brokerRequest.getAggregationsInfo().get(0).getAggregationParams()
         .get(FunctionCallAstNode.COLUMN_KEY_IN_AGGREGATION_INFO)
         .split(FunctionCallAstNode.DISTINCT_MULTI_COLUMN_SEPARATOR);
   }
+
+  private DataSchema getResultTableDataSchema() {
+    String[] columns = getDistinctColumns();
+    DataSchema.ColumnDataType[] columnDataTypes = new 
DataSchema.ColumnDataType[columns.length];
+    // TODO: there's no way currently to get the data types of the distinct 
columns
 
 Review comment:
   You can do distinctTable.getDataSchema() and that should have both column 
names and types. 

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

Reply via email to