mayankshriv commented on a change in pull request #4535: Implement DISTINCT 
clause
URL: https://github.com/apache/incubator-pinot/pull/4535#discussion_r315322506
 
 

 ##########
 File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/DefaultAggregationExecutor.java
 ##########
 @@ -36,18 +40,40 @@
   protected final AggregationFunction[] _functions;
   protected final AggregationResultHolder[] _resultHolders;
   protected final TransformExpressionTree[] _expressions;
+  private boolean _distinct = false;
+  private int _recordLimit; // used for DISTINCT queries
 
   public DefaultAggregationExecutor(@Nonnull AggregationFunctionContext[] 
functionContexts) {
     _numFunctions = functionContexts.length;
     _functions = new AggregationFunction[_numFunctions];
     _resultHolders = new AggregationResultHolder[_numFunctions];
-    _expressions = new TransformExpressionTree[_numFunctions];
-    for (int i = 0; i < _numFunctions; i++) {
-      AggregationFunction function = 
functionContexts[i].getAggregationFunction();
-      _functions[i] = function;
-      _resultHolders[i] = _functions[i].createAggregationResultHolder();
-      if (function.getType() != AggregationFunctionType.COUNT) {
-        _expressions[i] = 
TransformExpressionTree.compileToExpressionTree(functionContexts[i].getColumn());
+    if (AggregationFunctionUtils.isDistinct(functionContexts)) {
+      _distinct = true;
+      _functions[0] = functionContexts[0].getAggregationFunction();
+      _resultHolders[0] = _functions[0].createAggregationResultHolder();
+      final String multiColumnExpression = functionContexts[0].getColumn();
+      final String[] distinctColumnExpressions = 
multiColumnExpression.split(FunctionCallAstNode.DISTINCT_MULTI_COLUMN_SEPARATOR);
+      _expressions = new 
TransformExpressionTree[distinctColumnExpressions.length];
+      for (int i = 0; i < distinctColumnExpressions.length; i++) {
+        _expressions[i] = 
TransformExpressionTree.compileToExpressionTree(distinctColumnExpressions[i]);
+      }
+    } else {
+      _expressions = new TransformExpressionTree[_numFunctions];
+      for (int i = 0; i < _numFunctions; i++) {
+        AggregationFunction function = 
functionContexts[i].getAggregationFunction();
+        // parser should have already enforce the constraint of not allowing 
queries
 
 Review comment:
   I'd rather make it a unit test.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to