siddharthteotia commented on a change in pull request #6285:
URL: https://github.com/apache/incubator-pinot/pull/6285#discussion_r533664885



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/DistinctCombineOperator.java
##########
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.combine;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.blocks.IntermediateResultsBlock;
+import org.apache.pinot.core.query.distinct.DistinctTable;
+import org.apache.pinot.core.query.request.context.QueryContext;
+
+
+/**
+ * Combine operator for distinct queries.
+ */
+@SuppressWarnings("rawtypes")
+public class DistinctCombineOperator extends BaseCombineOperator {
+  private static final String OPERATOR_NAME = "DistinctCombineOperator";
+
+  public DistinctCombineOperator(List<Operator> operators, QueryContext 
queryContext, ExecutorService executorService,
+      long endTimeMs) {
+    super(operators, queryContext, executorService, endTimeMs);
+  }
+
+  @Override
+  public String getOperatorName() {
+    return OPERATOR_NAME;
+  }
+
+  @Override
+  protected boolean isQuerySatisfied(IntermediateResultsBlock resultsBlock) {
+    if (_queryContext.getOrderByExpressions() == null) {
+      List<Object> result = resultsBlock.getAggregationResult();
+      assert result != null && result.size() == 1 && result.get(0) instanceof 
DistinctTable;
+      DistinctTable distinctTable = (DistinctTable) result.get(0);
+      return distinctTable.size() >= _queryContext.getLimit();
+    } else {
+      return false;
+    }
+  }
+
+  @Override
+  protected void mergeResultsBlocks(IntermediateResultsBlock mergedBlock, 
IntermediateResultsBlock blockToMerge) {
+    // TODO: Use a separate way to represent DISTINCT instead of aggregation.
+    List<Object> mergedResults = mergedBlock.getAggregationResult();
+    assert mergedResults != null && mergedResults.size() == 1 && 
mergedResults.get(0) instanceof DistinctTable;

Review comment:
       Why not use Preconditions.checkState()? Are we moving away from them as 
a convention?

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/DistinctCombineOperator.java
##########
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.combine;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.blocks.IntermediateResultsBlock;
+import org.apache.pinot.core.query.distinct.DistinctTable;
+import org.apache.pinot.core.query.request.context.QueryContext;
+
+
+/**
+ * Combine operator for distinct queries.
+ */
+@SuppressWarnings("rawtypes")
+public class DistinctCombineOperator extends BaseCombineOperator {
+  private static final String OPERATOR_NAME = "DistinctCombineOperator";
+
+  public DistinctCombineOperator(List<Operator> operators, QueryContext 
queryContext, ExecutorService executorService,
+      long endTimeMs) {
+    super(operators, queryContext, executorService, endTimeMs);
+  }
+
+  @Override
+  public String getOperatorName() {
+    return OPERATOR_NAME;
+  }
+
+  @Override
+  protected boolean isQuerySatisfied(IntermediateResultsBlock resultsBlock) {
+    if (_queryContext.getOrderByExpressions() == null) {
+      List<Object> result = resultsBlock.getAggregationResult();

Review comment:
       You can probably stash away the order by presence in a boolean instance 
variable and avoid the method call to `getOrderByExpressions()` here since I 
believe it will be called by each combine thread for each segment it is 
processing in a loop. Simply check for the instance variable




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

Reply via email to