-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Partial projections pushdown #1868
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
823212f
Fix translation of FieldDereference to DereferenceExpression
phd3 206668e
Add validation for projections returned from metadata#applyProjection…
phd3 c9ba203
Support partial projection pushdown into table scan
phd3 9ff9864
Update constructor visibility in ReferenceAwareExpressionNodeInliner
phd3 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
91 changes: 91 additions & 0 deletions
91
presto-main/src/main/java/io/prestosql/spi/expression/PartialTranslator.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,91 @@ | ||
| /* | ||
| * Licensed 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 io.prestosql.spi.expression; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import io.prestosql.Session; | ||
| import io.prestosql.spi.type.Type; | ||
| import io.prestosql.sql.planner.TypeAnalyzer; | ||
| import io.prestosql.sql.planner.TypeProvider; | ||
| import io.prestosql.sql.tree.AstVisitor; | ||
| import io.prestosql.sql.tree.Expression; | ||
| import io.prestosql.sql.tree.LambdaExpression; | ||
| import io.prestosql.sql.tree.NodeRef; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class PartialTranslator | ||
| { | ||
| private PartialTranslator() {} | ||
|
|
||
| /** | ||
| * Produces {@link ConnectorExpression} translations for disjoint components in the {@param inputExpression} in a | ||
| * top-down manner. i.e. if an expression node is translatable, we do not consider its children. | ||
| */ | ||
| public static Map<NodeRef<Expression>, ConnectorExpression> extractPartialTranslations( | ||
| Expression inputExpression, | ||
| Session session, | ||
| TypeAnalyzer typeAnalyzer, | ||
| TypeProvider typeProvider) | ||
| { | ||
| requireNonNull(inputExpression, "expressions is null"); | ||
| requireNonNull(session, "session is null"); | ||
| requireNonNull(typeAnalyzer, "typeAnalyzer is null"); | ||
| requireNonNull(typeProvider, "typeProvider is null"); | ||
|
|
||
| Map<NodeRef<Expression>, ConnectorExpression> partialTranslations = new HashMap<>(); | ||
| new Visitor(typeAnalyzer.getTypes(session, typeProvider, inputExpression), partialTranslations).process(inputExpression); | ||
| return ImmutableMap.copyOf(partialTranslations); | ||
| } | ||
|
|
||
| private static class Visitor | ||
| extends AstVisitor<Void, Void> | ||
| { | ||
| private final Map<NodeRef<Expression>, ConnectorExpression> translatedSubExpressions; | ||
| private final ConnectorExpressionTranslator.SqlToConnectorExpressionTranslator translator; | ||
|
|
||
| Visitor(Map<NodeRef<Expression>, Type> types, Map<NodeRef<Expression>, ConnectorExpression> translatedSubExpressions) | ||
| { | ||
| requireNonNull(types, "types is null"); | ||
| this.translatedSubExpressions = requireNonNull(translatedSubExpressions, "translatedSubExpressions is null"); | ||
| this.translator = new ConnectorExpressionTranslator.SqlToConnectorExpressionTranslator(types); | ||
| } | ||
|
|
||
| @Override | ||
| public Void visitExpression(Expression node, Void context) | ||
| { | ||
| Optional<ConnectorExpression> result = translator.process(node); | ||
|
|
||
| if (result.isPresent()) { | ||
| translatedSubExpressions.put(NodeRef.of(node), result.get()); | ||
| } | ||
| else { | ||
| node.getChildren().forEach(this::process); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| // TODO support lambda expressions for partial projection | ||
| @Override | ||
| public Void visitLambdaExpression(LambdaExpression functionCall, Void context) | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ public static Expression replaceExpression(Expression expression, Map<NodeRef<Ex | |
|
|
||
|
Member
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. Rephrase the commit message: "Update constructor visibility in ReferenceAwareExpressionNodeInliner" |
||
| private final Map<NodeRef<Expression>, Expression> mappings; | ||
|
|
||
| public ReferenceAwareExpressionNodeInliner(Map<NodeRef<Expression>, Expression> mappings) | ||
| private ReferenceAwareExpressionNodeInliner(Map<NodeRef<Expression>, Expression> mappings) | ||
| { | ||
| this.mappings = ImmutableMap.copyOf(requireNonNull(mappings, "mappings is null")); | ||
| } | ||
|
|
||
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.
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.
is it possible to test this?
also, cmt title is too long. Maybe just
Fix translation of FieldDereference to DereferenceExpression.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.
@findepi Fixed the message. Added a test in
TestConnectorExpressionTranslator. I haven't added literals for the test since the translation for them would rely on how ExpressionAnalyzer and LiteralEncoder.