Skip to content
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

Handle the case when enableNullHandling is true and an aggregation function is used w/ a column that has an empty null bitmap #9566

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ public void aggregate(int length, AggregationResultHolder aggregationResultHolde
Map<ExpressionContext, BlockValSet> blockValSetMap) {
BlockValSet blockValSet = blockValSetMap.get(_expression);
if (_nullHandlingEnabled) {
// TODO: avoid the null bitmap check when it is null or empty for better performance.
RoaringBitmap nullBitmap = blockValSet.getNullBitmap();
if (nullBitmap != null && !nullBitmap.isEmpty()) {
aggregateNullHandlingEnabled(length, aggregationResultHolder, blockValSet, nullBitmap);
return;
if (nullBitmap == null) {
nullBitmap = new RoaringBitmap();
}
aggregateNullHandlingEnabled(length, aggregationResultHolder, blockValSet, nullBitmap);
return;
}

switch (blockValSet.getValueType().getStoredType()) {
Expand Down Expand Up @@ -219,20 +221,21 @@ public void aggregateGroupBySV(int length, int[] groupKeyArray, GroupByResultHol
BlockValSet blockValSet = blockValSetMap.get(_expression);
if (_nullHandlingEnabled) {
RoaringBitmap nullBitmap = blockValSet.getNullBitmap();
if (nullBitmap != null && !nullBitmap.isEmpty()) {
if (nullBitmap.getCardinality() < length) {
double[] valueArray = blockValSet.getDoubleValuesSV();
for (int i = 0; i < length; i++) {
double value = valueArray[i];
int groupKey = groupKeyArray[i];
Double result = groupByResultHolder.getResult(groupKey);
if (!nullBitmap.contains(i) && (result == null || value > result)) {
groupByResultHolder.setValueForKey(groupKey, value);
}
if (nullBitmap == null) {
nullBitmap = new RoaringBitmap();
}
if (nullBitmap.getCardinality() < length) {
double[] valueArray = blockValSet.getDoubleValuesSV();
for (int i = 0; i < length; i++) {
double value = valueArray[i];
int groupKey = groupKeyArray[i];
Double result = groupByResultHolder.getResult(groupKey);
if (!nullBitmap.contains(i) && (result == null || value > result)) {
groupByResultHolder.setValueForKey(groupKey, value);
}
}
return;
}
return;
}

double[] valueArray = blockValSet.getDoubleValuesSV();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ public void aggregate(int length, AggregationResultHolder aggregationResultHolde
BlockValSet blockValSet = blockValSetMap.get(_expression);
if (_nullHandlingEnabled) {
RoaringBitmap nullBitmap = blockValSet.getNullBitmap();
if (nullBitmap != null && !nullBitmap.isEmpty()) {
aggregateNullHandlingEnabled(length, aggregationResultHolder, blockValSet, nullBitmap);
return;
if (nullBitmap == null) {
nullBitmap = new RoaringBitmap();
}
aggregateNullHandlingEnabled(length, aggregationResultHolder, blockValSet, nullBitmap);
return;
}

switch (blockValSet.getValueType().getStoredType()) {
Expand Down Expand Up @@ -219,20 +220,21 @@ public void aggregateGroupBySV(int length, int[] groupKeyArray, GroupByResultHol
BlockValSet blockValSet = blockValSetMap.get(_expression);
if (_nullHandlingEnabled) {
RoaringBitmap nullBitmap = blockValSet.getNullBitmap();
if (nullBitmap != null && !nullBitmap.isEmpty()) {
if (nullBitmap.getCardinality() < length) {
double[] valueArray = blockValSet.getDoubleValuesSV();
for (int i = 0; i < length; i++) {
double value = valueArray[i];
int groupKey = groupKeyArray[i];
Double result = groupByResultHolder.getResult(groupKey);
if (!nullBitmap.contains(i) && (result == null || value < result)) {
groupByResultHolder.setValueForKey(groupKey, value);
}
if (nullBitmap == null) {
nullBitmap = new RoaringBitmap();
}
if (nullBitmap.getCardinality() < length) {
double[] valueArray = blockValSet.getDoubleValuesSV();
for (int i = 0; i < length; i++) {
double value = valueArray[i];
int groupKey = groupKeyArray[i];
Double result = groupByResultHolder.getResult(groupKey);
if (!nullBitmap.contains(i) && (result == null || value < result)) {
groupByResultHolder.setValueForKey(groupKey, value);
}
}
return;
}
return;
}

double[] valueArray = blockValSet.getDoubleValuesSV();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ public void aggregate(int length, AggregationResultHolder aggregationResultHolde
BlockValSet blockValSet = blockValSetMap.get(_expression);
if (_nullHandlingEnabled) {
RoaringBitmap nullBitmap = blockValSet.getNullBitmap();
if (nullBitmap != null && !nullBitmap.isEmpty()) {
aggregateNullHandlingEnabled(length, aggregationResultHolder, blockValSet, nullBitmap);
return;
if (nullBitmap == null) {
nullBitmap = new RoaringBitmap();
}
aggregateNullHandlingEnabled(length, aggregationResultHolder, blockValSet, nullBitmap);
return;
}

double sum = aggregationResultHolder.getDoubleResult();
Expand Down Expand Up @@ -207,26 +208,27 @@ public void aggregateGroupBySV(int length, int[] groupKeyArray, GroupByResultHol
BlockValSet blockValSet = blockValSetMap.get(_expression);
if (_nullHandlingEnabled) {
RoaringBitmap nullBitmap = blockValSet.getNullBitmap();
if (nullBitmap != null && !nullBitmap.isEmpty()) {
if (nullBitmap.getCardinality() < length) {
double[] valueArray = blockValSet.getDoubleValuesSV();
for (int i = 0; i < length; i++) {
if (!nullBitmap.contains(i)) {
int groupKey = groupKeyArray[i];
Double result = groupByResultHolder.getResult(groupKey);
groupByResultHolder.setValueForKey(groupKey, result == null ? valueArray[i] : result + valueArray[i]);
// In presto:
// SELECT sum (cast(id AS DOUBLE)) as sum, min(id) as min, max(id) as max, key FROM (VALUES (null, 1),
// (null, 2)) AS t(id, key) GROUP BY key ORDER BY max DESC;
// sum | min | max | key
//------+------+------+-----
// NULL | NULL | NULL | 2
// NULL | NULL | NULL | 1
}
if (nullBitmap == null) {
nullBitmap = new RoaringBitmap();
}
if (nullBitmap.getCardinality() < length) {
double[] valueArray = blockValSet.getDoubleValuesSV();
for (int i = 0; i < length; i++) {
if (!nullBitmap.contains(i)) {
int groupKey = groupKeyArray[i];
Double result = groupByResultHolder.getResult(groupKey);
groupByResultHolder.setValueForKey(groupKey, result == null ? valueArray[i] : result + valueArray[i]);
// In presto:
// SELECT sum (cast(id AS DOUBLE)) as sum, min(id) as min, max(id) as max, key FROM (VALUES (null, 1),
// (null, 2)) AS t(id, key) GROUP BY key ORDER BY max DESC;
// sum | min | max | key
//------+------+------+-----
// NULL | NULL | NULL | 2
// NULL | NULL | NULL | 1
}
}
return;
}
return;
}

double[] valueArray = blockValSet.getDoubleValuesSV();
Expand Down
Loading