-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add single worker execution mode for native execution
- Loading branch information
1 parent
ad9429d
commit 0d9137e
Showing
18 changed files
with
935 additions
and
406 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
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
107 changes: 107 additions & 0 deletions
107
.../java/com/facebook/presto/sql/planner/optimizations/AddExchangeForNativeSingleWorker.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,107 @@ | ||
/* | ||
* 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.optimizations; | ||
|
||
import com.facebook.presto.Session; | ||
import com.facebook.presto.metadata.Metadata; | ||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.spi.VariableAllocator; | ||
import com.facebook.presto.spi.WarningCollector; | ||
import com.facebook.presto.spi.plan.MergeJoinNode; | ||
import com.facebook.presto.spi.plan.Partitioning; | ||
import com.facebook.presto.spi.plan.PartitioningScheme; | ||
import com.facebook.presto.spi.plan.PlanNode; | ||
import com.facebook.presto.spi.plan.PlanNodeIdAllocator; | ||
import com.facebook.presto.spi.plan.TableFinishNode; | ||
import com.facebook.presto.sql.planner.PartitioningProviderManager; | ||
import com.facebook.presto.sql.planner.TypeProvider; | ||
import com.facebook.presto.sql.planner.plan.ChildReplacer; | ||
import com.facebook.presto.sql.planner.plan.ExchangeNode; | ||
import com.facebook.presto.sql.planner.plan.SimplePlanRewriter; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION; | ||
import static com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.REMOTE_STREAMING; | ||
import static com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER; | ||
import static com.facebook.presto.sql.planner.plan.ExchangeNode.ensureSourceOrderingGatheringExchange; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class AddExchangeForNativeSingleWorker | ||
implements PlanOptimizer | ||
{ | ||
private final Metadata metadata; | ||
private final PartitioningProviderManager partitioningProviderManager; | ||
|
||
public AddExchangeForNativeSingleWorker(Metadata metadata, PartitioningProviderManager partitioningProviderManager) | ||
{ | ||
this.metadata = requireNonNull(metadata, "metadata is null"); | ||
this.partitioningProviderManager = requireNonNull(partitioningProviderManager, "partitioningProviderManager is null"); | ||
} | ||
|
||
@Override | ||
public PlanOptimizerResult optimize(PlanNode plan, Session session, TypeProvider types, VariableAllocator variableAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) | ||
{ | ||
AddExchangeForNativeSingleWorker.Rewriter rewriter = new AddExchangeForNativeSingleWorker.Rewriter(variableAllocator, idAllocator, metadata, session); | ||
PlanNode rewrittenPlan = SimplePlanRewriter.rewriteWith(rewriter, plan, null); | ||
return PlanOptimizerResult.optimizerResult(rewrittenPlan, rewriter.isPlanChanged()); | ||
} | ||
|
||
private class Rewriter | ||
extends SimplePlanRewriter<Void> | ||
{ | ||
private final PlanNodeIdAllocator idAllocator; | ||
private final Session session; | ||
private boolean planChanged; | ||
|
||
public Rewriter(VariableAllocator variableAllocator, PlanNodeIdAllocator idAllocator, Metadata metadata, Session session) | ||
{ | ||
this.idAllocator = idAllocator; | ||
this.session = session; | ||
} | ||
|
||
public boolean isPlanChanged() | ||
{ | ||
return planChanged; | ||
} | ||
|
||
@Override | ||
public PlanNode visitTableFinish(TableFinishNode node, RewriteContext<Void> context) | ||
{ | ||
PlanNode child = node.getSource(); | ||
|
||
ExchangeNode gather; | ||
// in case the input is a union (see PushTableWriteThroughUnion), don't add another exchange | ||
if (child instanceof ExchangeNode) { | ||
ExchangeNode exchangeNode = (ExchangeNode) child; | ||
gather = new ExchangeNode( | ||
exchangeNode.getSourceLocation(), | ||
idAllocator.getNextId(), | ||
GATHER, | ||
REMOTE_STREAMING, | ||
new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), exchangeNode.getOutputVariables()), | ||
exchangeNode.getSources(), | ||
exchangeNode.getInputs(), | ||
true, | ||
Optional.empty()); | ||
} | ||
else { | ||
gather = ensureSourceOrderingGatheringExchange(idAllocator.getNextId(), REMOTE_STREAMING, child); | ||
} | ||
planChanged = true; | ||
return ChildReplacer.replaceChildren(node, ImmutableList.of(gather)); | ||
} | ||
} | ||
} |
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.