-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Flatten FunctionCall as direct fields in AggregationNode#Aggregation #12789
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
3 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
75 changes: 75 additions & 0 deletions
75
presto-main/src/main/java/com/facebook/presto/sql/planner/AnalyzedExpressionRewriter.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,75 @@ | ||
| /* | ||
| * 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 com.facebook.presto.sql.planner; | ||
|
|
||
| import com.facebook.presto.Session; | ||
| import com.facebook.presto.execution.warnings.WarningCollector; | ||
| import com.facebook.presto.metadata.Metadata; | ||
| import com.facebook.presto.spi.type.Type; | ||
| import com.facebook.presto.sql.parser.SqlParser; | ||
| import com.facebook.presto.sql.tree.Expression; | ||
| import com.facebook.presto.sql.tree.ExpressionRewriter; | ||
| import com.facebook.presto.sql.tree.ExpressionTreeRewriter; | ||
| import com.facebook.presto.sql.tree.LambdaExpression; | ||
| import com.facebook.presto.sql.tree.NodeRef; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static com.facebook.presto.sql.analyzer.ExpressionAnalyzer.getExpressionTypes; | ||
| import static java.util.Collections.emptyList; | ||
|
|
||
| @Deprecated | ||
| public class AnalyzedExpressionRewriter | ||
| { | ||
| private final Session session; | ||
| private final Metadata metadata; | ||
| private final SqlParser sqlParser; | ||
| private final TypeProvider typeProvider; | ||
|
|
||
| public AnalyzedExpressionRewriter(Session session, Metadata metadata, SqlParser sqlParser, TypeProvider typeProvider) | ||
| { | ||
| this.session = session; | ||
| this.metadata = metadata; | ||
| this.sqlParser = sqlParser; | ||
| this.typeProvider = typeProvider; | ||
| } | ||
|
|
||
| public Expression rewriteWith(RewriterProvider<Void> rewriterProvider, Expression expression) | ||
| { | ||
| return rewriteWith(rewriterProvider, expression, null); | ||
| } | ||
|
|
||
| public <C> Expression rewriteWith(RewriterProvider<C> rewriterProvider, Expression expression, C context) | ||
| { | ||
| // Lambda cannot be analyzed outside the context of function, but its body can be rewritten. | ||
| if (expression instanceof LambdaExpression) { | ||
| LambdaExpression lambdaExpression = (LambdaExpression) expression; | ||
| return new LambdaExpression(lambdaExpression.getArguments(), rewriteWith(rewriterProvider, lambdaExpression.getBody(), context)); | ||
| } | ||
| Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes( | ||
| session, | ||
| metadata, | ||
| sqlParser, | ||
| typeProvider, | ||
| expression, | ||
| emptyList(), | ||
| WarningCollector.NOOP); | ||
| return ExpressionTreeRewriter.rewriteWith(rewriterProvider.get(expressionTypes), expression, context); | ||
| } | ||
|
|
||
| interface RewriterProvider<C> | ||
| { | ||
| ExpressionRewriter<C> get(Map<NodeRef<Expression>, Type> expressionTypes); | ||
| } | ||
| } | ||
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
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
72 changes: 72 additions & 0 deletions
72
presto-main/src/main/java/com/facebook/presto/sql/planner/PlannerUtils.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,72 @@ | ||
| /* | ||
| * 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 com.facebook.presto.sql.planner; | ||
|
|
||
| import com.facebook.presto.spi.block.SortOrder; | ||
| import com.facebook.presto.sql.tree.Expression; | ||
| import com.facebook.presto.sql.tree.OrderBy; | ||
| import com.facebook.presto.sql.tree.SortItem; | ||
| import com.facebook.presto.sql.tree.SymbolReference; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||
|
|
||
| public class PlannerUtils | ||
| { | ||
| private PlannerUtils() {} | ||
|
|
||
| public static SortOrder toSortOrder(SortItem sortItem) | ||
| { | ||
| if (sortItem.getOrdering() == SortItem.Ordering.ASCENDING) { | ||
| if (sortItem.getNullOrdering() == SortItem.NullOrdering.FIRST) { | ||
| return SortOrder.ASC_NULLS_FIRST; | ||
| } | ||
| return SortOrder.ASC_NULLS_LAST; | ||
| } | ||
| if (sortItem.getNullOrdering() == SortItem.NullOrdering.FIRST) { | ||
| return SortOrder.DESC_NULLS_FIRST; | ||
| } | ||
| return SortOrder.DESC_NULLS_LAST; | ||
| } | ||
|
|
||
| public static OrderingScheme toOrderingScheme(List<SortItem> sortItems) | ||
| { | ||
| return toOrderingScheme(sortItems, item -> { | ||
| checkArgument(item instanceof SymbolReference, "must be symbol reference"); | ||
| return new Symbol(((SymbolReference) item).getName()); | ||
| }); | ||
| } | ||
|
|
||
| public static OrderingScheme toOrderingScheme(List<SortItem> sortItems, Function<Expression, Symbol> translator) | ||
| { | ||
| // The logic is similar to QueryPlanner::sort | ||
| Map<Symbol, SortOrder> orderings = new LinkedHashMap<>(); | ||
| for (SortItem item : sortItems) { | ||
| Symbol symbol = translator.apply(item.getSortKey()); | ||
| // don't override existing keys, i.e. when "ORDER BY a ASC, a DESC" is specified | ||
|
hellium01 marked this conversation as resolved.
Outdated
|
||
| orderings.putIfAbsent(symbol, toSortOrder(item)); | ||
| } | ||
| return new OrderingScheme(orderings.keySet().stream().collect(toImmutableList()), orderings); | ||
| } | ||
|
|
||
| public static OrderingScheme toOrderingScheme(OrderBy orderBy) | ||
| { | ||
| return toOrderingScheme(orderBy.getSortItems()); | ||
| } | ||
| } | ||
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.
hmm...
AnalyzedExpressionRewritersounds a bit vague... let's talk in person quickly to figure out a better name (or decided that's the best name and we just need some comments.. 😃 )Uh oh!
There was an error while loading. Please reload this page.
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.
As discussed offline, will add a Deprecated Mark over there and keep the name as is.