-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[multistage] Replace LogicalTableScan with PinotLogicalTableScan #15225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ery-planner/src/main/java/org/apache/pinot/calcite/rel/logical/PinotLogicalTableScan.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * 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.calcite.rel.logical; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.calcite.plan.RelOptCluster; | ||
| import org.apache.calcite.plan.RelOptTable; | ||
| import org.apache.calcite.plan.RelTraitSet; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.core.TableScan; | ||
| import org.apache.calcite.rel.hint.RelHint; | ||
| import org.apache.calcite.rel.logical.LogicalTableScan; | ||
|
|
||
|
|
||
| /** | ||
| * Same as {@link org.apache.calcite.rel.logical.LogicalTableScan}, except that it doesn't drop provided traits | ||
| * in the {@link #copy} method. | ||
| */ | ||
| public class PinotLogicalTableScan extends TableScan { | ||
| protected PinotLogicalTableScan(RelOptCluster cluster, RelTraitSet traitSet, List<RelHint> hints, RelOptTable table) { | ||
| super(cluster, traitSet, hints, table); | ||
| } | ||
|
|
||
| @Override | ||
| public RelNode withHints(List<RelHint> hintList) { | ||
| return new PinotLogicalTableScan(getCluster(), traitSet, hintList, table); | ||
| } | ||
|
|
||
| @Override | ||
| public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) { | ||
| assert inputs.isEmpty(); | ||
| return new PinotLogicalTableScan(getCluster(), traitSet, hints, table); | ||
| } | ||
|
|
||
| public static PinotLogicalTableScan create(LogicalTableScan logicalTableScan) { | ||
| return new PinotLogicalTableScan(logicalTableScan.getCluster(), logicalTableScan.getTraitSet(), | ||
| logicalTableScan.getHints(), logicalTableScan.getTable()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotTableScanConverterRule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * 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.calcite.rel.rules; | ||
|
|
||
| import org.apache.calcite.plan.RelOptRule; | ||
| import org.apache.calcite.plan.RelOptRuleCall; | ||
| import org.apache.calcite.rel.core.TableScan; | ||
| import org.apache.calcite.rel.logical.LogicalTableScan; | ||
| import org.apache.calcite.tools.RelBuilderFactory; | ||
| import org.apache.pinot.calcite.rel.logical.PinotLogicalTableScan; | ||
|
|
||
|
|
||
| public class PinotTableScanConverterRule extends RelOptRule { | ||
| public static final PinotTableScanConverterRule INSTANCE = | ||
| new PinotTableScanConverterRule(PinotRuleUtils.PINOT_REL_FACTORY); | ||
|
|
||
| public PinotTableScanConverterRule(RelBuilderFactory factory) { | ||
| super(operand(TableScan.class, none()), factory, null); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMatch(RelOptRuleCall call) { | ||
| TableScan tableScan = call.rel(0); | ||
| if (tableScan instanceof LogicalTableScan) { | ||
| call.transformTo(PinotLogicalTableScan.create(call.rel(0))); | ||
| } else if (!(tableScan instanceof PinotLogicalTableScan)) { | ||
| throw new IllegalStateException("Unknown table scan in PinotTableScanConverterRule: " + tableScan.getClass()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,7 @@ public void testAggregateCaseToFilter() { | |
| + " PinotLogicalExchange(distribution=[hash])\n" | ||
| + " PinotLogicalAggregate(group=[{}], agg#0=[COUNT() FILTER $0], agg#1=[COUNT()], aggType=[LEAF])\n" | ||
| + " LogicalProject($f1=[=($0, _UTF-8'a')])\n" | ||
| + " LogicalTableScan(table=[[default, a]])\n"); | ||
| + " PinotLogicalTableScan(table=[[default, a]])\n"); | ||
| //@formatter:on | ||
| } | ||
|
|
||
|
|
@@ -592,13 +592,13 @@ private Object[][] provideQueriesWithExplainedLogicalPlan() { | |
| + " \"rels\": [\n" | ||
| + " {\n" | ||
| + " \"id\": \"0\",\n" | ||
| + " \"relOp\": \"LogicalTableScan\",\n" | ||
| + " \"relOp\": \"org.apache.pinot.calcite.rel.logical.PinotLogicalTableScan\",\n" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are required because |
||
| + " \"table\": [\n" | ||
| + " \"default\",\n" | ||
| + " \"a\"\n" | ||
| + " ],\n" | ||
| + " \"inputs\": [],\n" | ||
| + " \"type\": \"LogicalTableScan\"\n" | ||
| + " \"type\": \"PinotLogicalTableScan\"\n" | ||
| + " },\n" | ||
| + " {\n" | ||
| + " \"id\": \"1\",\n" | ||
|
|
@@ -626,7 +626,7 @@ private Object[][] provideQueriesWithExplainedLogicalPlan() { | |
| + "digraph {\n" | ||
| + "\"PinotLogicalExchange\\n\" -> \"PinotLogicalAggregat\\ne\\n\" [label=\"0\"]\n" | ||
| + "\"PinotLogicalAggregat\\ne\\n\" -> \"PinotLogicalExchange\\n\" [label=\"0\"]\n" | ||
| + "\"LogicalTableScan\\n\" -> \"PinotLogicalAggregat\\ne\\n\" [label=\"0\"]\n" | ||
| + "\"PinotLogicalTableSca\\nn\\n\" -> \"PinotLogicalAggregat\\ne\\n\" [label=\"0\"]\n" | ||
| + "}\n" | ||
| }, | ||
| new Object[]{"EXPLAIN PLAN FOR SELECT a.col1, b.col3 FROM a JOIN b ON a.col1 = b.col1", | ||
|
|
@@ -635,10 +635,10 @@ private Object[][] provideQueriesWithExplainedLogicalPlan() { | |
| + " LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n" | ||
| + " PinotLogicalExchange(distribution=[hash[0]])\n" | ||
| + " LogicalProject(col1=[$0])\n" | ||
| + " LogicalTableScan(table=[[default, a]])\n" | ||
| + " PinotLogicalTableScan(table=[[default, a]])\n" | ||
| + " PinotLogicalExchange(distribution=[hash[0]])\n" | ||
| + " LogicalProject(col1=[$0], col3=[$2])\n" | ||
| + " LogicalTableScan(table=[[default, b]])\n" | ||
| + " PinotLogicalTableScan(table=[[default, b]])\n" | ||
| }, | ||
| }; | ||
| //@formatter:on | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a QueryException here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thrown exception here would get caught in
MultiStageBrokerRequestHandlerwhich will set theQUERY_PLANNING_ERROR_CODE. I think the idea behind this approach is that the planner etc. can throw whatever exception seems right in their context (e.g. illegal state in this case), and the broker request handler will convert it to a structured form with an error code.I don't think QueryException is used for throwing. It is mainly used for getting a ProcessingException which shows up nicely in broker response (we should ideally make the contract explicit in QueryException javadocs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has recently changed in #15037. Now QueryException is an actual exception. The idea is that you can throw it anywhere during query processing and that way you can define the QueryErrorCode being used. That is not 100% true because there are still some paths that haven't been updated, but it is pretty safe to think that way.
For example, here we know that the error is not related to the query but a bug in our code, so it could be marked as QueryErrorCode.INTERNAL instead of QueryErrorCode.QUERY_PLANNING.
Anyway, it is completely valid to delegate the caller's responsibility to catch the exception and set the error code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah damn saw this comment after merging. I am working on another PR.. can update this there. Thanks for sharing this. This looks like a better approach to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 34, you can directly match
LogicalTableScan. I don't think we need to protect it from getting a differentTableScannode