You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/10/13 21:52:57 UTC

[GitHub] [pinot] agavra commented on a diff in pull request #9582: distinct result return

agavra commented on code in PR #9582:
URL: https://github.com/apache/pinot/pull/9582#discussion_r995097420


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/blocks/results/DistinctResultsBlock.java:
##########
@@ -60,23 +61,31 @@ public DataSchema getDataSchema(QueryContext queryContext) {
 
   @Override
   public Collection<Object[]> getRows(QueryContext queryContext) {
-    List<Object[]> rows = new ArrayList<>(_distinctTable.size());
-    for (Record record : _distinctTable.getRecords()) {
-      rows.add(record.getValues());
+    if (queryContext.isServerReturnFinalResult()) {

Review Comment:
   > this _distinctTable inside the DistinctResultBlock can somehow be a non-main-table..
   
   WDYT about making the "Main" table a different class that sublcasses the `DistinctTable`. that could help make this a bit safer going ahead
   
   (2) looks like a bug to me as well



##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByV2EngineRewriter.java:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.sql.parsers.rewriter;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pinot.common.request.Expression;
+import org.apache.pinot.common.request.PinotQuery;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+
+
+public class NonAggregationGroupByV2EngineRewriter implements QueryRewriter {
+  /**
+   * Rewrite non-aggregate group by query to distinct query.
+   * E.g.
+   * ```
+   *   SELECT col1+col2*5 FROM foo GROUP BY col1, col2 => SELECT distinct col1+col2*5 FROM foo
+   *   SELECT col1, col2 FROM foo GROUP BY col1, col2 => SELECT distinct col1, col2 FROM foo
+   * ```
+   * @param pinotQuery
+   */
+  @Override
+  public PinotQuery rewrite(PinotQuery pinotQuery) {
+    boolean hasAggregation = false;
+    for (Expression select : pinotQuery.getSelectList()) {
+      if (CalciteSqlParser.isAggregateExpression(select)) {
+        hasAggregation = true;

Review Comment:
   nit: we can early exit on this (and the one below)



##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByV2EngineRewriter.java:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.sql.parsers.rewriter;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pinot.common.request.Expression;
+import org.apache.pinot.common.request.PinotQuery;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+
+
+public class NonAggregationGroupByV2EngineRewriter implements QueryRewriter {
+  /**
+   * Rewrite non-aggregate group by query to distinct query.

Review Comment:
   this javadoc is a bit misleading, it appears we don't do this here but rather in the v1 rewriter, which we expect to run before this one. we may want to consider subclassing the v1 rewriter and just adding this additional functionality to it



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

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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