-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[multistage] Add Support for Broker Server/Segment Pruning #15959
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
8 commits
Select commit
Hold shift + click to select a range
8e870e4
[multistage] Add Support for Broker Server/Segment Pruning
f718813
minor cleanup
aeab4b4
add doc comments for query option
d9bfca9
make it re-usable
24dc178
fix bug
c005b5a
add precondition
080870f
invert boolean
0ad1251
self-review: rename method
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
105 changes: 105 additions & 0 deletions
105
...y-planner/src/main/java/org/apache/pinot/query/planner/logical/LeafStageToPinotQuery.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,105 @@ | ||
| /** | ||
| * 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 com.google.common.base.Preconditions; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.core.Filter; | ||
| import org.apache.calcite.rel.core.Project; | ||
| import org.apache.calcite.rel.core.TableScan; | ||
| import org.apache.pinot.common.request.DataSource; | ||
| import org.apache.pinot.common.request.Expression; | ||
| import org.apache.pinot.common.request.PinotQuery; | ||
| import org.apache.pinot.query.parser.CalciteRexExpressionParser; | ||
| import org.apache.pinot.sql.parsers.CalciteSqlParser; | ||
|
|
||
|
|
||
| /** | ||
| * Utility to convert a leaf stage to a {@link PinotQuery}. | ||
| */ | ||
| public class LeafStageToPinotQuery { | ||
| private LeafStageToPinotQuery() { | ||
| } | ||
|
|
||
| /** | ||
| * Converts a leaf stage root to a {@link PinotQuery}. This method only handles Project, Filter and TableScan nodes. | ||
| * Other node types are ignored since they don't impact routing. | ||
| * | ||
| * @param tableName the name of the table. Needs to be provided separately since it needs TableCache. | ||
| * @param leafStageRoot the root of the leaf stage | ||
| * @param skipFilter whether to skip the filter in the query | ||
| * @return a {@link PinotQuery} representing the leaf stage | ||
| */ | ||
| public static PinotQuery createPinotQueryForRouting(String tableName, RelNode leafStageRoot, boolean skipFilter) { | ||
| List<RelNode> bottomToTopNodes = new ArrayList<>(); | ||
| accumulateBottomToTop(leafStageRoot, bottomToTopNodes); | ||
| Preconditions.checkState(!bottomToTopNodes.isEmpty() && bottomToTopNodes.get(0) instanceof TableScan, | ||
| "Could not find table scan"); | ||
| TableScan tableScan = (TableScan) bottomToTopNodes.get(0); | ||
| PinotQuery pinotQuery = initializePinotQueryForTableScan(tableName, tableScan); | ||
| for (RelNode parentNode : bottomToTopNodes) { | ||
| if (parentNode instanceof Filter) { | ||
| if (!skipFilter) { | ||
| handleFilter((Filter) parentNode, pinotQuery); | ||
| } | ||
| } else if (parentNode instanceof Project) { | ||
| handleProject((Project) parentNode, pinotQuery); | ||
| } | ||
| } | ||
| return pinotQuery; | ||
| } | ||
|
|
||
| private static void accumulateBottomToTop(RelNode root, List<RelNode> parentNodes) { | ||
| Preconditions.checkState(root.getInputs().size() <= 1, | ||
| "Leaf stage nodes should have at most one input, found: %s", root.getInputs().size()); | ||
| for (RelNode input : root.getInputs()) { | ||
| accumulateBottomToTop(input, parentNodes); | ||
| } | ||
| parentNodes.add(root); | ||
| } | ||
|
|
||
| private static PinotQuery initializePinotQueryForTableScan(String tableName, TableScan tableScan) { | ||
| PinotQuery pinotQuery = new PinotQuery(); | ||
| pinotQuery.setDataSource(new DataSource()); | ||
| pinotQuery.getDataSource().setTableName(tableName); | ||
| pinotQuery.setSelectList(tableScan.getRowType().getFieldNames().stream().map( | ||
| CalciteSqlParser::compileToExpression).collect(Collectors.toList())); | ||
| return pinotQuery; | ||
| } | ||
|
|
||
| private static void handleProject(Project project, PinotQuery pinotQuery) { | ||
| if (project != null) { | ||
| List<RexExpression> rexExpressions = RexExpressionUtils.fromRexNodes(project.getProjects()); | ||
| List<Expression> selectList = CalciteRexExpressionParser.convertRexNodes(rexExpressions, | ||
| pinotQuery.getSelectList()); | ||
| pinotQuery.setSelectList(selectList); | ||
| } | ||
| } | ||
|
|
||
| private static void handleFilter(Filter filter, PinotQuery pinotQuery) { | ||
| if (filter != null) { | ||
| RexExpression rexExpression = RexExpressionUtils.fromRexNode(filter.getCondition()); | ||
| pinotQuery.setFilterExpression(CalciteRexExpressionParser.toExpression(rexExpression, | ||
| pinotQuery.getSelectList())); | ||
| } | ||
| } | ||
| } |
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
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.
simplifying this code. It was taking in a wider object than required. Only access to the selectList was required