-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Set initial number of tasks for scaled writer with HBO #20901
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
2 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,11 @@ | |
| import com.facebook.presto.spi.statistics.JoinNodeStatistics; | ||
| import com.facebook.presto.spi.statistics.PlanStatistics; | ||
| import com.facebook.presto.spi.statistics.PlanStatisticsWithSourceInfo; | ||
| import com.facebook.presto.spi.statistics.TableWriterNodeStatistics; | ||
| import com.facebook.presto.sql.planner.CanonicalPlan; | ||
| import com.facebook.presto.sql.planner.PlanNodeCanonicalInfo; | ||
| import com.facebook.presto.sql.planner.plan.JoinNode; | ||
| import com.facebook.presto.sql.planner.plan.TableWriterNode; | ||
| import com.facebook.presto.sql.planner.planPrinter.PlanNodeStats; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.collect.ImmutableMap; | ||
|
|
@@ -52,6 +55,7 @@ | |
| import static com.facebook.presto.common.resourceGroups.QueryType.INSERT; | ||
| import static com.facebook.presto.common.resourceGroups.QueryType.SELECT; | ||
| import static com.facebook.presto.cost.HistoricalPlanStatisticsUtil.updatePlanStatistics; | ||
| import static com.facebook.presto.sql.planner.SystemPartitioningHandle.SCALED_WRITER_DISTRIBUTION; | ||
| import static com.facebook.presto.sql.planner.planPrinter.PlanNodeStatsSummarizer.aggregateStageStats; | ||
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||
| import static com.google.common.collect.ImmutableMap.toImmutableMap; | ||
|
|
@@ -130,6 +134,7 @@ public Map<PlanNodeWithHash, PlanStatisticsWithSourceInfo> getQueryStats(QueryIn | |
| if (!stageInfo.getPlan().isPresent()) { | ||
| continue; | ||
| } | ||
| boolean isScaledWriterStage = stageInfo.getPlan().isPresent() && stageInfo.getPlan().get().getPartitioning().equals(SCALED_WRITER_DISTRIBUTION); | ||
| PlanNode root = stageInfo.getPlan().get().getRoot(); | ||
| for (PlanNode planNode : forTree(PlanNode::getSources).depthFirstPreOrder(root)) { | ||
| if (!planNode.getStatsEquivalentPlanNode().isPresent()) { | ||
|
|
@@ -144,6 +149,16 @@ public Map<PlanNodeWithHash, PlanStatisticsWithSourceInfo> getQueryStats(QueryIn | |
| double nullJoinBuildKeyCount = planNodeStats.getPlanNodeNullJoinBuildKeyCount(); | ||
| double joinBuildKeyCount = planNodeStats.getPlanNodeJoinBuildKeyCount(); | ||
|
|
||
| JoinNodeStatistics joinNodeStatistics = JoinNodeStatistics.empty(); | ||
| if (planNode instanceof JoinNode) { | ||
| joinNodeStatistics = new JoinNodeStatistics(Estimate.of(nullJoinBuildKeyCount), Estimate.of(joinBuildKeyCount)); | ||
| } | ||
|
|
||
| TableWriterNodeStatistics tableWriterNodeStatistics = TableWriterNodeStatistics.empty(); | ||
| if (isScaledWriterStage && planNode instanceof TableWriterNode) { | ||
| tableWriterNodeStatistics = new TableWriterNodeStatistics(Estimate.of(stageInfo.getLatestAttemptExecutionInfo().getStats().getTotalTasks())); | ||
|
||
| } | ||
|
|
||
| PlanNode statsEquivalentPlanNode = planNode.getStatsEquivalentPlanNode().get(); | ||
| for (PlanCanonicalizationStrategy strategy : historyBasedPlanCanonicalizationStrategyList()) { | ||
| Optional<PlanNodeCanonicalInfo> planNodeCanonicalInfo = Optional.ofNullable( | ||
|
|
@@ -152,20 +167,23 @@ public Map<PlanNodeWithHash, PlanStatisticsWithSourceInfo> getQueryStats(QueryIn | |
| String hash = planNodeCanonicalInfo.get().getHash(); | ||
| List<PlanStatistics> inputTableStatistics = planNodeCanonicalInfo.get().getInputTableStatistics(); | ||
| PlanNodeWithHash planNodeWithHash = new PlanNodeWithHash(statsEquivalentPlanNode, Optional.of(hash)); | ||
| // Plan node added after HistoricalStatisticsEquivalentPlanMarkingOptimizer will have the same hash as its source node. If the source node is join node, | ||
| // the newly added node will have the same hash with the join but no join statistics, hence we need to overwrite in this case. | ||
| if (!planStatistics.containsKey(planNodeWithHash) || nullJoinBuildKeyCount > 0 || joinBuildKeyCount > 0) { | ||
| planStatistics.put( | ||
| planNodeWithHash, | ||
| new PlanStatisticsWithSourceInfo( | ||
| planNode.getId(), | ||
| new PlanStatistics( | ||
| Estimate.of(outputPositions), | ||
| Double.isNaN(outputBytes) ? Estimate.unknown() : Estimate.of(outputBytes), | ||
| 1.0, | ||
| new JoinNodeStatistics(Estimate.of(nullJoinBuildKeyCount), Estimate.of(joinBuildKeyCount))), | ||
| new HistoryBasedSourceInfo(Optional.of(hash), Optional.of(inputTableStatistics)))); | ||
| // Plan node added after HistoricalStatisticsEquivalentPlanMarkingOptimizer will have the same hash as its source node. If the source node is not join or | ||
| // table writer node, the newly added node will have the same hash but no join/table writer statistics, hence we need to overwrite in this case. | ||
| PlanStatistics newPlanNodeStats = new PlanStatistics( | ||
| Estimate.of(outputPositions), | ||
| Double.isNaN(outputBytes) ? Estimate.unknown() : Estimate.of(outputBytes), | ||
| 1.0, | ||
| joinNodeStatistics, | ||
| tableWriterNodeStatistics); | ||
| if (planStatistics.containsKey(planNodeWithHash)) { | ||
| newPlanNodeStats = planStatistics.get(planNodeWithHash).getPlanStatistics().update(newPlanNodeStats); | ||
| } | ||
| planStatistics.put( | ||
| planNodeWithHash, | ||
| new PlanStatisticsWithSourceInfo( | ||
| planNode.getId(), | ||
| newPlanNodeStats, | ||
| new HistoryBasedSourceInfo(Optional.of(hash), Optional.of(inputTableStatistics)))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import com.facebook.presto.spi.statistics.PlanStatistics; | ||
| import com.facebook.presto.spi.statistics.PlanStatisticsWithSourceInfo; | ||
| import com.facebook.presto.spi.statistics.SourceInfo; | ||
| import com.facebook.presto.spi.statistics.TableWriterNodeStatistics; | ||
| import com.facebook.presto.sql.Serialization; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
@@ -49,7 +50,7 @@ | |
| public class PlanNodeStatsEstimate | ||
| { | ||
| private static final double DEFAULT_DATA_SIZE_PER_COLUMN = 50; | ||
| private static final PlanNodeStatsEstimate UNKNOWN = new PlanNodeStatsEstimate(NaN, NaN, false, ImmutableMap.of()); | ||
| private static final PlanNodeStatsEstimate UNKNOWN = new PlanNodeStatsEstimate(NaN, NaN, false, ImmutableMap.of(), JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown()); | ||
|
|
||
| private final double outputRowCount; | ||
| private final double totalSize; | ||
|
|
@@ -59,6 +60,8 @@ public class PlanNodeStatsEstimate | |
|
|
||
| private final JoinNodeStatsEstimate joinNodeStatsEstimate; | ||
|
|
||
| private final TableWriterNodeStatsEstimate tableWriterNodeStatsEstimate; | ||
|
|
||
|
||
| public static PlanNodeStatsEstimate unknown() | ||
| { | ||
| return UNKNOWN; | ||
|
|
@@ -69,9 +72,11 @@ public PlanNodeStatsEstimate( | |
| @JsonProperty("outputRowCount") double outputRowCount, | ||
| @JsonProperty("totalSize") double totalSize, | ||
| @JsonProperty("confident") boolean confident, | ||
| @JsonProperty("variableStatistics") Map<VariableReferenceExpression, VariableStatsEstimate> variableStatistics) | ||
| @JsonProperty("variableStatistics") Map<VariableReferenceExpression, VariableStatsEstimate> variableStatistics, | ||
| @JsonProperty("joinNodeStatsEstimate") JoinNodeStatsEstimate joinNodeStatsEstimate, | ||
| @JsonProperty("tableWriterNodeStatsEstimate") TableWriterNodeStatsEstimate tableWriterNodeStatsEstimate) | ||
| { | ||
| this(outputRowCount, totalSize, confident, HashTreePMap.from(requireNonNull(variableStatistics, "variableStatistics is null"))); | ||
| this(outputRowCount, totalSize, HashTreePMap.from(requireNonNull(variableStatistics, "variableStatistics is null")), new CostBasedSourceInfo(confident), joinNodeStatsEstimate, tableWriterNodeStatsEstimate); | ||
| } | ||
|
|
||
| private PlanNodeStatsEstimate(double outputRowCount, double totalSize, boolean confident, PMap<VariableReferenceExpression, VariableStatsEstimate> variableStatistics) | ||
|
|
@@ -81,18 +86,19 @@ private PlanNodeStatsEstimate(double outputRowCount, double totalSize, boolean c | |
|
|
||
| public PlanNodeStatsEstimate(double outputRowCount, double totalSize, PMap<VariableReferenceExpression, VariableStatsEstimate> variableStatistics, SourceInfo sourceInfo) | ||
| { | ||
| this(outputRowCount, totalSize, variableStatistics, sourceInfo, JoinNodeStatsEstimate.unknown()); | ||
| this(outputRowCount, totalSize, variableStatistics, sourceInfo, JoinNodeStatsEstimate.unknown(), TableWriterNodeStatsEstimate.unknown()); | ||
| } | ||
|
|
||
| public PlanNodeStatsEstimate(double outputRowCount, double totalSize, PMap<VariableReferenceExpression, VariableStatsEstimate> variableStatistics, SourceInfo sourceInfo, | ||
| JoinNodeStatsEstimate joinNodeStatsEstimate) | ||
| JoinNodeStatsEstimate joinNodeStatsEstimate, TableWriterNodeStatsEstimate tableWriterNodeStatsEstimate) | ||
| { | ||
| checkArgument(isNaN(outputRowCount) || outputRowCount >= 0, "outputRowCount cannot be negative"); | ||
| this.outputRowCount = outputRowCount; | ||
| this.totalSize = totalSize; | ||
| this.variableStatistics = variableStatistics; | ||
| this.sourceInfo = requireNonNull(sourceInfo, "SourceInfo is null"); | ||
| this.joinNodeStatsEstimate = requireNonNull(joinNodeStatsEstimate, "joinNodeSpecificStatsEstimate is null"); | ||
| this.tableWriterNodeStatsEstimate = requireNonNull(tableWriterNodeStatsEstimate, "tableWriterNodeStatsEstimate is null"); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -122,11 +128,18 @@ public SourceInfo getSourceInfo() | |
| return sourceInfo; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public JoinNodeStatsEstimate getJoinNodeStatsEstimate() | ||
| { | ||
| return joinNodeStatsEstimate; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public TableWriterNodeStatsEstimate getTableWriterNodeStatsEstimate() | ||
| { | ||
| return tableWriterNodeStatsEstimate; | ||
| } | ||
|
|
||
| /** | ||
| * Only use when getting all columns and meanwhile do not want to | ||
| * do per-column estimation. | ||
|
|
@@ -241,9 +254,12 @@ public PlanNodeStatsEstimate combineStats(PlanStatistics planStatistics, SourceI | |
| planStatistics.getOutputSize().getValue(), | ||
| variableStatistics, | ||
| statsSourceInfo, | ||
| new JoinNodeStatsEstimate( | ||
| planStatistics.getJoinNodeStatistics().getNullJoinBuildKeyCount().getValue(), | ||
| planStatistics.getJoinNodeStatistics().getJoinBuildKeyCount().getValue())); | ||
| planStatistics.getJoinNodeStatistics().isEmpty() ? getJoinNodeStatsEstimate() : | ||
| new JoinNodeStatsEstimate( | ||
| planStatistics.getJoinNodeStatistics().getNullJoinBuildKeyCount().getValue(), | ||
| planStatistics.getJoinNodeStatistics().getJoinBuildKeyCount().getValue()), | ||
| planStatistics.getTableWriterNodeStatistics().isEmpty() ? getTableWriterNodeStatsEstimate() : | ||
| new TableWriterNodeStatsEstimate(planStatistics.getTableWriterNodeStatistics().getTaskCountIfScaledWriter().getValue())); | ||
| } | ||
| return this; | ||
| } | ||
|
|
@@ -293,7 +309,8 @@ public PlanStatisticsWithSourceInfo toPlanStatisticsWithSourceInfo(PlanNodeId id | |
| sourceInfo.isConfident() ? 1 : 0, | ||
| new JoinNodeStatistics( | ||
| Estimate.estimateFromDouble(joinNodeStatsEstimate.getNullJoinBuildKeyCount()), | ||
| Estimate.estimateFromDouble(joinNodeStatsEstimate.getJoinBuildKeyCount()))), | ||
| Estimate.estimateFromDouble(joinNodeStatsEstimate.getJoinBuildKeyCount())), | ||
| new TableWriterNodeStatistics(Estimate.estimateFromDouble(tableWriterNodeStatsEstimate.getTaskCountIfScaledWriter()))), | ||
| sourceInfo); | ||
| } | ||
|
|
||
|
|
||
73 changes: 73 additions & 0 deletions
73
presto-main/src/main/java/com/facebook/presto/cost/TableWriterNodeStatsEstimate.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,73 @@ | ||
| /* | ||
| * 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.cost; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import static com.google.common.base.MoreObjects.toStringHelper; | ||
| import static java.lang.Double.NaN; | ||
|
|
||
| public class TableWriterNodeStatsEstimate | ||
| { | ||
| private static final TableWriterNodeStatsEstimate UNKNOWN = new TableWriterNodeStatsEstimate(NaN); | ||
|
|
||
| private final double taskCountIfScaledWriter; | ||
|
|
||
| @JsonCreator | ||
| public TableWriterNodeStatsEstimate(@JsonProperty("taskCountIfScaledWriter") double taskCountIfScaledWriter) | ||
| { | ||
| this.taskCountIfScaledWriter = taskCountIfScaledWriter; | ||
| } | ||
|
|
||
| public static TableWriterNodeStatsEstimate unknown() | ||
| { | ||
| return UNKNOWN; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public double getTaskCountIfScaledWriter() | ||
| { | ||
| return taskCountIfScaledWriter; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return toStringHelper(this) | ||
| .add("taskCountIfScaledWriter", taskCountIfScaledWriter) | ||
| .toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) | ||
| { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| TableWriterNodeStatsEstimate that = (TableWriterNodeStatsEstimate) o; | ||
| return Double.compare(taskCountIfScaledWriter, that.taskCountIfScaledWriter) == 0; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| return Objects.hash(taskCountIfScaledWriter); | ||
| } | ||
| } |
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 TableWriterMergeNode relevant here?
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.
No, the scaled writer optimization is only related to table writer node, not related to table writer merger node.