Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ApplyNode representation of subquery
For more design details please see: https://docs.google.com/document/d/18HN7peS2eR8lZsErqcmnoWyMEPb6p4OQeidH1JP_EkA Apply node is a generic representation of subquery abstract correlation between outer and nested queries. Subquery is rewritten into an ApplyNode then if ApplyNode does not have any correlation it is removed (rewritten to some form of join) by UncorrelatedInPredicateApplyRemover and UncorrelatedScalarApplyRemover.
- Loading branch information
Showing
25 changed files
with
772 additions
and
146 deletions.
There are no files selected for viewing
This file contains 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
65 changes: 65 additions & 0 deletions
65
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionExtractor.java
This file contains 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,65 @@ | ||
/* | ||
* 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.sql.planner.plan.FilterNode; | ||
import com.facebook.presto.sql.planner.plan.PlanNode; | ||
import com.facebook.presto.sql.planner.plan.ProjectNode; | ||
import com.facebook.presto.sql.planner.plan.TableScanNode; | ||
import com.facebook.presto.sql.planner.plan.ValuesNode; | ||
import com.facebook.presto.sql.tree.Expression; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
|
||
public class ExpressionExtractor | ||
extends SimplePlanVisitor<ImmutableList.Builder<Expression>> | ||
{ | ||
public static List<Expression> extractExpressions(PlanNode plan) | ||
{ | ||
ImmutableList.Builder<Expression> expressionsBuilder = ImmutableList.builder(); | ||
plan.accept(new ExpressionExtractor(), expressionsBuilder); | ||
return expressionsBuilder.build(); | ||
} | ||
|
||
@Override | ||
public Void visitFilter(FilterNode node, ImmutableList.Builder<Expression> context) | ||
{ | ||
context.add(node.getPredicate()); | ||
return super.visitFilter(node, context); | ||
} | ||
|
||
@Override | ||
public Void visitProject(ProjectNode node, ImmutableList.Builder<Expression> context) | ||
{ | ||
context.addAll(node.getAssignments().values()); | ||
return super.visitProject(node, context); | ||
} | ||
|
||
@Override | ||
public Void visitTableScan(TableScanNode node, ImmutableList.Builder<Expression> context) | ||
{ | ||
if (node.getOriginalConstraint() != null) { | ||
context.add(node.getOriginalConstraint()); | ||
} | ||
return super.visitTableScan(node, context); | ||
} | ||
|
||
@Override | ||
public Void visitValues(ValuesNode node, ImmutableList.Builder<Expression> context) | ||
{ | ||
node.getRows().forEach(context::addAll); | ||
return super.visitValues(node, context); | ||
} | ||
} |
This file contains 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 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 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 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 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.