-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Aggregation delay conversion to double #8139
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
siddharthteotia
merged 3 commits into
apache:master
from
richardstartin:aggregation-delay-conversion-to-double
Feb 7, 2022
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -54,10 +54,39 @@ public GroupByResultHolder createGroupByResultHolder(int initialCapacity, int ma | |
| @Override | ||
| public void aggregate(int length, AggregationResultHolder aggregationResultHolder, | ||
| Map<ExpressionContext, BlockValSet> blockValSetMap) { | ||
| double[] valueArray = blockValSetMap.get(_expression).getDoubleValuesSV(); | ||
| double sum = aggregationResultHolder.getDoubleResult(); | ||
| for (int i = 0; i < length; i++) { | ||
| sum += valueArray[i]; | ||
| BlockValSet blockValSet = blockValSetMap.get(_expression); | ||
| switch (blockValSet.getValueType().getStoredType()) { | ||
| case INT: { | ||
| int[] values = blockValSet.getIntValuesSV(); | ||
| for (int i = 0; i < length & i < values.length; i++) { | ||
| sum += values[i]; | ||
| } | ||
| break; | ||
| } | ||
| case LONG: { | ||
| long[] values = blockValSet.getLongValuesSV(); | ||
| for (int i = 0; i < length & i < values.length; i++) { | ||
| sum += values[i]; | ||
| } | ||
| break; | ||
| } | ||
| case FLOAT: { | ||
| float[] values = blockValSet.getFloatValuesSV(); | ||
| for (int i = 0; i < length & i < values.length; i++) { | ||
| sum += values[i]; | ||
| } | ||
| break; | ||
| } | ||
| case DOUBLE: { | ||
| double[] values = blockValSet.getDoubleValuesSV(); | ||
| for (int i = 0; i < length & i < values.length; i++) { | ||
| sum += values[i]; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| throw new IllegalStateException("Cannot compute min for non-numeric type: " + blockValSet.getValueType()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the exception message to reflect the correct aggregation
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will follow up |
||
| } | ||
| aggregationResultHolder.setValue(sum); | ||
| } | ||
|
|
||
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.
I understand how delaying conversion to double will help with heap usage. Couple of questions on performance:
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.
You can see some numbers on #7920 (read longs as longs vs convert to double) but I’ll pull out some disassembly to demonstrate, as well as attach some numbers 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.
Regarding the switch statement, there is one per block, so it’s cost is amortised (just like all the virtual calls we do)
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.
@siddharthteotia I've added some rationale and numbers to the PR description, please take a look.
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.
Thanks for sharing perf numbers, @richardstartin. I was also curious to see the disassembled code as you said auto-vectorization probability increases with continuing to treat as long. Please share if you have.
I am good with the PR. Please also check-in the benchmark
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.
The vectorized method is Copy::conjoint_swap, as mentioned above, which hsdis does not dissemble.