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
Use streaming aggregation for a correlated scalar subquery #10731
Merged
mbasmanova
merged 10 commits into
prestodb:master
from
mbasmanova:streaming-aggregation
Jun 20, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d31cb2a
Add preGroupedSymbols to AggregationNode
mbasmanova 6c97d9f
Update AddLocalExchanges to plan streaming aggregations
mbasmanova 4c31b76
Include join type when printing plan pattern
mbasmanova 3a28de7
Preserve local properties of the probe when passing through a LEFT join
mbasmanova ac5d37d
Add AggregationNode#isStreamable
mbasmanova c33a1a3
Enable streaming aggregation for pre-grouped inputs
mbasmanova 6666a7b
Identify streaming aggregations in EXPLAIN
mbasmanova 445d110
Push up AssignUniqueId through remote exchange
mbasmanova 2d4f084
Add plan checker for streaming aggregations
mbasmanova cc916c4
Add StreamingAggregationOperator
mbasmanova File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
79 changes: 79 additions & 0 deletions
79
presto-main/src/main/java/com/facebook/presto/operator/Aggregator.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,79 @@ | ||
/* | ||
* 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.operator; | ||
|
||
import com.facebook.presto.operator.aggregation.Accumulator; | ||
import com.facebook.presto.operator.aggregation.AccumulatorFactory; | ||
import com.facebook.presto.spi.Page; | ||
import com.facebook.presto.spi.block.BlockBuilder; | ||
import com.facebook.presto.spi.type.Type; | ||
import com.facebook.presto.sql.planner.plan.AggregationNode; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
class Aggregator | ||
{ | ||
private final Accumulator aggregation; | ||
private final AggregationNode.Step step; | ||
private final int intermediateChannel; | ||
|
||
Aggregator(AccumulatorFactory accumulatorFactory, AggregationNode.Step step) | ||
{ | ||
if (step.isInputRaw()) { | ||
intermediateChannel = -1; | ||
aggregation = accumulatorFactory.createAccumulator(); | ||
} | ||
else { | ||
checkArgument(accumulatorFactory.getInputChannels().size() == 1, "expected 1 input channel for intermediate aggregation"); | ||
intermediateChannel = accumulatorFactory.getInputChannels().get(0); | ||
aggregation = accumulatorFactory.createIntermediateAccumulator(); | ||
} | ||
this.step = step; | ||
} | ||
|
||
public Type getType() | ||
{ | ||
if (step.isOutputPartial()) { | ||
return aggregation.getIntermediateType(); | ||
} | ||
else { | ||
return aggregation.getFinalType(); | ||
} | ||
} | ||
|
||
public void processPage(Page page) | ||
{ | ||
if (step.isInputRaw()) { | ||
aggregation.addInput(page); | ||
} | ||
else { | ||
aggregation.addIntermediate(page.getBlock(intermediateChannel)); | ||
} | ||
} | ||
|
||
public void evaluate(BlockBuilder blockBuilder) | ||
{ | ||
if (step.isOutputPartial()) { | ||
aggregation.evaluateIntermediate(blockBuilder); | ||
} | ||
else { | ||
aggregation.evaluateFinal(blockBuilder); | ||
} | ||
} | ||
|
||
public long getEstimatedSize() | ||
{ | ||
return aggregation.getEstimatedSize(); | ||
} | ||
} |
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.
[Optiopnal] It would be great to add some benchmarks as we have for
BenchmarkHashBuildAndJoinOperators
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.
@sopel39 Karol, I created
BenchmarkStreamingAggregationOperator
usingBenchmarkHashBuildAndJoinOperators
as an example. The benchmark processes 1.4M rows split into pages 10K rows each.rowsPerGroup
parameter determines the number of rows with the same grouping key. Here are the results for 1, 10 and 1,000rowsPerGroup
:Processing larger groups is significantly faster than processing small groups. I'm going to explore your idea of reusable accumulators next.