You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "xiangfu0 (via GitHub)" <gi...@apache.org> on 2023/04/04 07:02:21 UTC

[GitHub] [pinot] xiangfu0 opened a new pull request, #10535: [multi-stage] [phase 1] Support SetOperations(UNION/INTERSECT/MINUS) compilation in query planner

xiangfu0 opened a new pull request, #10535:
URL: https://github.com/apache/pinot/pull/10535

   Support SetOperations: UNION/INTERSECT/MINUS(EXCEPT) for multi-stage query compilation.


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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171886724


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/ShuffleRewriteVisitor.java:
##########
@@ -79,6 +80,16 @@ public Set<Integer> visitWindow(WindowNode node, Void context) {
     throw new UnsupportedOperationException("Window not yet supported!");
   }
 
+  @Override
+  public Set<Integer> visitSetOp(SetOpNode setOpNode, Void context) {
+    StageNode firstInput = setOpNode.getInputs().get(0);
+    if (firstInput instanceof ProjectNode) {
+      Set<Integer> oldPartitionKeys = firstInput.visit(this, context);
+      return deriveNewPartitionKeysFromRexExpressions(((ProjectNode) firstInput).getProjects(), oldPartitionKeys);
+    }

Review Comment:
   Changed the logic to include all the partition keys from inputs.



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1172077644


##########
pinot-query-planner/src/test/resources/queries/SetOpPlans.json:
##########
@@ -0,0 +1,95 @@
+{
+  "set_op_tests": {
+    "queries": [
+      {
+        "description": "UNION ALL from two tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a UNION ALL SELECT col1, col2 FROM b",
+        "output": [
+          "Execution Plan",
+          "\nLogicalUnion(all=[true])",
+          "\n  LogicalProject(col1=[$0], col2=[$1])",
+          "\n    LogicalTableScan(table=[[a]])",
+          "\n  LogicalProject(col1=[$0], col2=[$1])",
+          "\n    LogicalTableScan(table=[[b]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "UNION ALL from three tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a UNION ALL SELECT col1, col2 FROM b UNION ALL SELECT col1, col2 FROM c",
+        "output": [
+          "Execution Plan",
+          "\nLogicalUnion(all=[true])",
+          "\n  LogicalUnion(all=[true])",
+          "\n    LogicalProject(col1=[$0], col2=[$1])",
+          "\n      LogicalTableScan(table=[[a]])",
+          "\n    LogicalProject(col1=[$0], col2=[$1])",
+          "\n      LogicalTableScan(table=[[b]])",
+          "\n  LogicalProject(col1=[$0], col2=[$1])",
+          "\n    LogicalTableScan(table=[[c]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "UNION from three tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a UNION SELECT col1, col2 FROM b UNION SELECT col1, col2 FROM c",
+        "output": [
+          "Execution Plan",
+          "\nLogicalAggregate(group=[{0, 1}])",
+          "\n  LogicalExchange(distribution=[hash[0, 1]])",
+          "\n    LogicalAggregate(group=[{0, 1}])",
+          "\n      LogicalUnion(all=[true])",
+          "\n        LogicalUnion(all=[true])",
+          "\n          LogicalProject(col1=[$0], col2=[$1])",
+          "\n            LogicalTableScan(table=[[a]])",
+          "\n          LogicalProject(col1=[$0], col2=[$1])",
+          "\n            LogicalTableScan(table=[[b]])",
+          "\n        LogicalProject(col1=[$0], col2=[$1])",
+          "\n          LogicalTableScan(table=[[c]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "INTERSECT from three tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a INTERSECT SELECT col1, col2 FROM b INTERSECT SELECT col1, col2 FROM c",

Review Comment:
   That was planned to be added in the next PR:
   
   https://github.com/apache/pinot/pull/10622/files#diff-1216478b200657de2afb3b0c8552bda799e67b68049aa025dbefc037235d9fb0
   



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


[GitHub] [pinot] walterddr commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171610857


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/colocated/GreedyShuffleRewritePreComputeVisitor.java:
##########
@@ -64,4 +65,11 @@ public Integer visitTableScan(TableScanNode stageNode, GreedyShuffleRewriteConte
     context.addLeafNode(stageNode.getStageId(), stageNode);
     return 0;
   }
+
+  @Override
+  public Integer visitSetOp(SetOpNode setOpNode, GreedyShuffleRewriteContext context) {

Review Comment:
   @ankitsultana can you take a look and see if this works with your expectation? even if we do not allow visitSetOp is a valid current limitation IMO



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


[GitHub] [pinot] walterddr commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171609231


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/ShuffleRewriteVisitor.java:
##########
@@ -79,6 +80,16 @@ public Set<Integer> visitWindow(WindowNode node, Void context) {
     throw new UnsupportedOperationException("Window not yet supported!");
   }
 
+  @Override
+  public Set<Integer> visitSetOp(SetOpNode setOpNode, Void context) {
+    StageNode firstInput = setOpNode.getInputs().get(0);
+    if (firstInput instanceof ProjectNode) {
+      Set<Integer> oldPartitionKeys = firstInput.visit(this, context);
+      return deriveNewPartitionKeysFromRexExpressions(((ProjectNode) firstInput).getProjects(), oldPartitionKeys);
+    }

Review Comment:
   what's the rational behind this? and was this tested? i don't think this is being used at all.



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


[GitHub] [pinot] walterddr commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1161866135


##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java:
##########
@@ -184,6 +184,14 @@ public static List<String> extractTableNamesFromNode(SqlNode sqlNode) {
       }
       tableNames.addAll(extractTableNamesFromNode(((SqlWith) sqlNode).body));
       tableNames.removeAll(aliases);
+    } else if (sqlNode instanceof SqlSetOption) {
+      for (SqlNode node : ((SqlSetOption) sqlNode).getOperandList()) {
+        if (node instanceof SqlIdentifier) {
+          tableNames.addAll(((SqlIdentifier) node).names);

Review Comment:
   did we check we will produce identifier here (as table identifier)? or this is a simple copy paste?



##########
pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java:
##########
@@ -3072,6 +3072,16 @@ public void testExtractTableNamesFromNode() {
     Assert.assertEquals(tableNames.get(0), "tbl1");
     Assert.assertEquals(tableNames.get(1), "tbl2");
 
+    // query with UNION clause
+    query = "SELECT * FROM tbl1 UNION ALL SELECT * FROM tbl2 UNION ALL SELECT * FROM tbl3";

Review Comment:
   can we add several more for parsing? for example
   `WITH tmpTable AS (...) SELECT * FROM tbl1 UNION ALL tmpTable`
   ^ here tmpTable should not be part of the check



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/StageMetadataVisitor.java:
##########
@@ -0,0 +1,148 @@
+/**
+ * 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.query.planner.logical;
+
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.util.Pair;
+import org.apache.pinot.query.planner.QueryPlan;
+import org.apache.pinot.query.planner.StageMetadata;
+import org.apache.pinot.query.planner.stage.AggregateNode;
+import org.apache.pinot.query.planner.stage.FilterNode;
+import org.apache.pinot.query.planner.stage.JoinNode;
+import org.apache.pinot.query.planner.stage.MailboxReceiveNode;
+import org.apache.pinot.query.planner.stage.MailboxSendNode;
+import org.apache.pinot.query.planner.stage.ProjectNode;
+import org.apache.pinot.query.planner.stage.SetOpNode;
+import org.apache.pinot.query.planner.stage.SortNode;
+import org.apache.pinot.query.planner.stage.StageNode;
+import org.apache.pinot.query.planner.stage.StageNodeVisitor;
+import org.apache.pinot.query.planner.stage.TableScanNode;
+import org.apache.pinot.query.planner.stage.ValueNode;
+import org.apache.pinot.query.planner.stage.WindowNode;
+
+
+/**
+ * {@code StageMetadataVisitor} computes the {@link StageMetadata} for a {@link StageNode}
+ * tree and attaches it in the form of a {@link QueryPlan}.
+ */
+public class StageMetadataVisitor implements StageNodeVisitor<Void, QueryPlan> {
+
+  public static QueryPlan attachMetadata(List<Pair<Integer, String>> fields, StageNode root) {
+    QueryPlan queryPlan = new QueryPlan(fields, new HashMap<>(), new HashMap<>());
+    root.visit(new StageMetadataVisitor(), queryPlan);
+    return queryPlan;
+  }
+
+  /**
+   * Usage of this class should only come through {@link #attachMetadata(List, StageNode)}.
+   */
+  private StageMetadataVisitor() {
+  }

Review Comment:
   stagemetadatavisitor is gone in #10481 i think this is a rebase issue



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1172076796


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/colocated/GreedyShuffleRewriteVisitor.java:
##########
@@ -251,10 +250,19 @@ public Set<ColocationKey> visitWindow(WindowNode node, GreedyShuffleRewriteConte
     return node.getInputs().get(0).visit(this, context);
   }
 
+  @Override
+  public Set<ColocationKey> visitSetOp(SetOpNode setOpNode, GreedyShuffleRewriteContext context) {
+    Set<ColocationKey> colocationKeys = new HashSet<>();

Review Comment:
   ack



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


[GitHub] [pinot] ankitsultana commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "ankitsultana (via GitHub)" <gi...@apache.org>.
ankitsultana commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171684188


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/ShuffleRewriteVisitor.java:
##########
@@ -79,6 +80,16 @@ public Set<Integer> visitWindow(WindowNode node, Void context) {
     throw new UnsupportedOperationException("Window not yet supported!");
   }
 
+  @Override
+  public Set<Integer> visitSetOp(SetOpNode setOpNode, Void context) {
+    StageNode firstInput = setOpNode.getInputs().get(0);
+    if (firstInput instanceof ProjectNode) {
+      Set<Integer> oldPartitionKeys = firstInput.visit(this, context);
+      return deriveNewPartitionKeysFromRexExpressions(((ProjectNode) firstInput).getProjects(), oldPartitionKeys);
+    }

Review Comment:
   `ShuffleRewriteVisitor` is not used. I think we should remove 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


[GitHub] [pinot] codecov-commenter commented on pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #10535:
URL: https://github.com/apache/pinot/pull/10535#issuecomment-1495842189

   ## [Codecov](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#10535](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c2487f0) into [master](https://codecov.io/gh/apache/pinot/commit/1fc81505e4ca39e2eda9d8912e79a01e686924a6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (1fc8150) will **decrease** coverage by `3.29%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #10535      +/-   ##
   ============================================
   - Coverage     27.80%   24.52%   -3.29%     
   + Complexity       58       49       -9     
   ============================================
     Files          2087     2088       +1     
     Lines        112307   112372      +65     
     Branches      16918    16928      +10     
   ============================================
   - Hits          31226    27554    -3672     
   - Misses        77988    81954    +3966     
   + Partials       3093     2864     -229     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration1 | `24.52% <0.00%> (+0.16%)` | :arrow_up: |
   | integration2 | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...e/pinot/query/planner/ExplainPlanStageVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9FeHBsYWluUGxhblN0YWdlVmlzaXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...not/query/planner/logical/RelToStageConverter.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9sb2dpY2FsL1JlbFRvU3RhZ2VDb252ZXJ0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...t/query/planner/logical/ShuffleRewriteVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9sb2dpY2FsL1NodWZmbGVSZXdyaXRlVmlzaXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ot/query/planner/logical/StageMetadataVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9sb2dpY2FsL1N0YWdlTWV0YWRhdGFWaXNpdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...located/GreedyShuffleRewritePreComputeVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9waHlzaWNhbC9jb2xvY2F0ZWQvR3JlZWR5U2h1ZmZsZVJld3JpdGVQcmVDb21wdXRlVmlzaXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...hysical/colocated/GreedyShuffleRewriteVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9waHlzaWNhbC9jb2xvY2F0ZWQvR3JlZWR5U2h1ZmZsZVJld3JpdGVWaXNpdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...lanner/stage/DefaultPostOrderTraversalVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9zdGFnZS9EZWZhdWx0UG9zdE9yZGVyVHJhdmVyc2FsVmlzaXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...rg/apache/pinot/query/planner/stage/SetOpNode.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9zdGFnZS9TZXRPcE5vZGUuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [.../pinot/query/runtime/plan/PhysicalPlanVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9wbGFuL1BoeXNpY2FsUGxhblZpc2l0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...t/query/runtime/plan/ServerRequestPlanVisitor.java](https://codecov.io/gh/apache/pinot/pull/10535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9wbGFuL1NlcnZlclJlcXVlc3RQbGFuVmlzaXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   
   ... and [283 files with indirect coverage changes](https://codecov.io/gh/apache/pinot/pull/10535/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


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


[GitHub] [pinot] walterddr commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171610102


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/DispatchablePlanVisitor.java:
##########
@@ -82,6 +83,13 @@ public Void visitWindow(WindowNode node, DispatchablePlanContext context) {
     return null;
   }
 
+  @Override
+  public Void visitSetOp(SetOpNode setOpNode, DispatchablePlanContext context) {

Review Comment:
   changing the dispatchable plan visitor requires a Ser/De test added to the QueryDispatcherTest and QueryServerTest to ensure all stagenode related content are ser/de properly 



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1162387205


##########
pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java:
##########
@@ -3072,6 +3072,16 @@ public void testExtractTableNamesFromNode() {
     Assert.assertEquals(tableNames.get(0), "tbl1");
     Assert.assertEquals(tableNames.get(1), "tbl2");
 
+    // query with UNION clause
+    query = "SELECT * FROM tbl1 UNION ALL SELECT * FROM tbl2 UNION ALL SELECT * FROM tbl3";

Review Comment:
   Added the table alias examples.
   Somehow SetOps require an expression instead of a table name, so need to change to
   ```
   WITH tmpTable AS (...) SELECT * FROM tbl1 UNION ALL SELECT * FROM tmpTable
   ```



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


[GitHub] [pinot] ankitsultana commented on pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "ankitsultana (via GitHub)" <gi...@apache.org>.
ankitsultana commented on PR #10535:
URL: https://github.com/apache/pinot/pull/10535#issuecomment-1515146396

   @xiangfu0 : Can you add tests which demonstrate what the plan is going to look like for queries with set-ops?


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


[GitHub] [pinot] ankitsultana commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "ankitsultana (via GitHub)" <gi...@apache.org>.
ankitsultana commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1172058329


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/colocated/GreedyShuffleRewriteVisitor.java:
##########
@@ -251,10 +250,19 @@ public Set<ColocationKey> visitWindow(WindowNode node, GreedyShuffleRewriteConte
     return node.getInputs().get(0).visit(this, context);
   }
 
+  @Override
+  public Set<ColocationKey> visitSetOp(SetOpNode setOpNode, GreedyShuffleRewriteContext context) {
+    Set<ColocationKey> colocationKeys = new HashSet<>();

Review Comment:
   I think we should return an empty set here for now since the logic to auto-compute the colocation key here is a bit tricky.
   
   Example if we do: `select col1, col2 from tbl1 union select col1, col2 from tbl2`, and the left side has a colocation key but the right side doesn't, then the result-set wouldn't have any colocation key.
   
   Either ways we'll rewrite the colocation logic in H1, but best to be correct meanwhile as well.



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1162398624


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/StageMetadataVisitor.java:
##########
@@ -0,0 +1,148 @@
+/**
+ * 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.query.planner.logical;
+
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.util.Pair;
+import org.apache.pinot.query.planner.QueryPlan;
+import org.apache.pinot.query.planner.StageMetadata;
+import org.apache.pinot.query.planner.stage.AggregateNode;
+import org.apache.pinot.query.planner.stage.FilterNode;
+import org.apache.pinot.query.planner.stage.JoinNode;
+import org.apache.pinot.query.planner.stage.MailboxReceiveNode;
+import org.apache.pinot.query.planner.stage.MailboxSendNode;
+import org.apache.pinot.query.planner.stage.ProjectNode;
+import org.apache.pinot.query.planner.stage.SetOpNode;
+import org.apache.pinot.query.planner.stage.SortNode;
+import org.apache.pinot.query.planner.stage.StageNode;
+import org.apache.pinot.query.planner.stage.StageNodeVisitor;
+import org.apache.pinot.query.planner.stage.TableScanNode;
+import org.apache.pinot.query.planner.stage.ValueNode;
+import org.apache.pinot.query.planner.stage.WindowNode;
+
+
+/**
+ * {@code StageMetadataVisitor} computes the {@link StageMetadata} for a {@link StageNode}
+ * tree and attaches it in the form of a {@link QueryPlan}.
+ */
+public class StageMetadataVisitor implements StageNodeVisitor<Void, QueryPlan> {
+
+  public static QueryPlan attachMetadata(List<Pair<Integer, String>> fields, StageNode root) {
+    QueryPlan queryPlan = new QueryPlan(fields, new HashMap<>(), new HashMap<>());
+    root.visit(new StageMetadataVisitor(), queryPlan);
+    return queryPlan;
+  }
+
+  /**
+   * Usage of this class should only come through {@link #attachMetadata(List, StageNode)}.
+   */
+  private StageMetadataVisitor() {
+  }

Review Comment:
   Correct, my rebase doesn't delete this file



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1162387693


##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java:
##########
@@ -184,6 +184,14 @@ public static List<String> extractTableNamesFromNode(SqlNode sqlNode) {
       }
       tableNames.addAll(extractTableNamesFromNode(((SqlWith) sqlNode).body));
       tableNames.removeAll(aliases);
+    } else if (sqlNode instanceof SqlSetOption) {
+      for (SqlNode node : ((SqlSetOption) sqlNode).getOperandList()) {
+        if (node instanceof SqlIdentifier) {
+          tableNames.addAll(((SqlIdentifier) node).names);

Review Comment:
   It's actually won't produce SqlIdentifier.



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171886399


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/DispatchablePlanVisitor.java:
##########
@@ -82,6 +83,13 @@ public Void visitWindow(WindowNode node, DispatchablePlanContext context) {
     return null;
   }
 
+  @Override
+  public Void visitSetOp(SetOpNode setOpNode, DispatchablePlanContext context) {

Review Comment:
   added.



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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1162387693


##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java:
##########
@@ -184,6 +184,14 @@ public static List<String> extractTableNamesFromNode(SqlNode sqlNode) {
       }
       tableNames.addAll(extractTableNamesFromNode(((SqlWith) sqlNode).body));
       tableNames.removeAll(aliases);
+    } else if (sqlNode instanceof SqlSetOption) {
+      for (SqlNode node : ((SqlSetOption) sqlNode).getOperandList()) {
+        if (node instanceof SqlIdentifier) {
+          tableNames.addAll(((SqlIdentifier) node).names);

Review Comment:
   Removed. It's actually won't produce SqlIdentifier.



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


[GitHub] [pinot] ankitsultana commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "ankitsultana (via GitHub)" <gi...@apache.org>.
ankitsultana commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1172056816


##########
pinot-query-planner/src/test/resources/queries/SetOpPlans.json:
##########
@@ -0,0 +1,95 @@
+{
+  "set_op_tests": {
+    "queries": [
+      {
+        "description": "UNION ALL from two tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a UNION ALL SELECT col1, col2 FROM b",
+        "output": [
+          "Execution Plan",
+          "\nLogicalUnion(all=[true])",
+          "\n  LogicalProject(col1=[$0], col2=[$1])",
+          "\n    LogicalTableScan(table=[[a]])",
+          "\n  LogicalProject(col1=[$0], col2=[$1])",
+          "\n    LogicalTableScan(table=[[b]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "UNION ALL from three tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a UNION ALL SELECT col1, col2 FROM b UNION ALL SELECT col1, col2 FROM c",
+        "output": [
+          "Execution Plan",
+          "\nLogicalUnion(all=[true])",
+          "\n  LogicalUnion(all=[true])",
+          "\n    LogicalProject(col1=[$0], col2=[$1])",
+          "\n      LogicalTableScan(table=[[a]])",
+          "\n    LogicalProject(col1=[$0], col2=[$1])",
+          "\n      LogicalTableScan(table=[[b]])",
+          "\n  LogicalProject(col1=[$0], col2=[$1])",
+          "\n    LogicalTableScan(table=[[c]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "UNION from three tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a UNION SELECT col1, col2 FROM b UNION SELECT col1, col2 FROM c",
+        "output": [
+          "Execution Plan",
+          "\nLogicalAggregate(group=[{0, 1}])",
+          "\n  LogicalExchange(distribution=[hash[0, 1]])",
+          "\n    LogicalAggregate(group=[{0, 1}])",
+          "\n      LogicalUnion(all=[true])",
+          "\n        LogicalUnion(all=[true])",
+          "\n          LogicalProject(col1=[$0], col2=[$1])",
+          "\n            LogicalTableScan(table=[[a]])",
+          "\n          LogicalProject(col1=[$0], col2=[$1])",
+          "\n            LogicalTableScan(table=[[b]])",
+          "\n        LogicalProject(col1=[$0], col2=[$1])",
+          "\n          LogicalTableScan(table=[[c]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "INTERSECT from three tables",
+        "sql": "EXPLAIN PLAN FOR SELECT col1, col2 FROM a INTERSECT SELECT col1, col2 FROM b INTERSECT SELECT col1, col2 FROM c",

Review Comment:
   @xiangfu0 : Shouldn't intersect require an exchange?
   
   If the row `col1=10, col2=11` in tables `a` and `b` are on different servers, if we don't shuffle using the intersection key (or broadcast one side) we may end up dropping them from the result-set.



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


[GitHub] [pinot] xiangfu0 merged pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 merged PR #10535:
URL: https://github.com/apache/pinot/pull/10535


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


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #10535:
URL: https://github.com/apache/pinot/pull/10535#discussion_r1171888083


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/colocated/GreedyShuffleRewritePreComputeVisitor.java:
##########
@@ -64,4 +65,11 @@ public Integer visitTableScan(TableScanNode stageNode, GreedyShuffleRewriteConte
     context.addLeafNode(stageNode.getStageId(), stageNode);
     return 0;
   }
+
+  @Override
+  public Integer visitSetOp(SetOpNode setOpNode, GreedyShuffleRewriteContext context) {

Review Comment:
   I added a new field for SetOp. Partitioning is a must to ensure  the correctness.



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


[GitHub] [pinot] xiangfu0 commented on pull request #10535: [multi-stage] Query compilation support for SetOperations: UNION/INTERSECT/MINUS(EXCEPT) in multi-stage engine

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on PR #10535:
URL: https://github.com/apache/pinot/pull/10535#issuecomment-1515464539

   > @xiangfu0 : Can you add tests which demonstrate what the plan is going to look like for queries with set-ops?
   
   Added a SetOpPlans.json file


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