Skip to content

Commit

Permalink
fix min_by/max_by null handle in final aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
yma11 committed Mar 27, 2024
1 parent 8d08a86 commit 53395a8
Showing 1 changed file with 10 additions and 36 deletions.
46 changes: 10 additions & 36 deletions velox/functions/lib/aggregates/MinMaxByAggregatesBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,26 +354,17 @@ class MinMaxByAggregateBase : public exec::Aggregate {

decodedValue_.decode(*baseRowVector->childAt(0), rows);
decodedComparison_.decode(*baseRowVector->childAt(1), rows);

if (decodedIntermediateResult_.isConstantMapping() &&
decodedIntermediateResult_.isNullAt(0)) {
return;
}
if (decodedIntermediateResult_.mayHaveNulls()) {
rows.applyToSelected([&](vector_size_t i) {
if (decodedIntermediateResult_.isNullAt(i)) {
return;
}
const auto decodedIndex = decodedIntermediateResult_.index(i);
updateValues(
groups[i],
decodedValue_,
decodedComparison_,
decodedIndex,
decodedValue_.isNullAt(decodedIndex),
mayUpdate);
});
if (decodedIntermediateResult_.isConstantMapping()) {
const auto decodedIndex = decodedIntermediateResult_.index(0);
updateValues(
groups[0],
decodedValue_,
decodedComparison_,
decodedIndex,
decodedValue_.isNullAt(decodedIndex),
mayUpdate);
} else {
// We don't need special null value handle in final aggregation
rows.applyToSelected([&](vector_size_t i) {
const auto decodedIndex = decodedIntermediateResult_.index(i);
updateValues(
Expand Down Expand Up @@ -457,9 +448,6 @@ class MinMaxByAggregateBase : public exec::Aggregate {
decodedComparison_.decode(*baseRowVector->childAt(1), rows);

if (decodedIntermediateResult_.isConstantMapping()) {
if (decodedIntermediateResult_.isNullAt(0)) {
return;
}
const auto decodedIndex = decodedIntermediateResult_.index(0);
updateValues(
group,
Expand All @@ -468,20 +456,6 @@ class MinMaxByAggregateBase : public exec::Aggregate {
decodedIndex,
decodedValue_.isNullAt(decodedIndex),
mayUpdate);
} else if (decodedIntermediateResult_.mayHaveNulls()) {
rows.applyToSelected([&](vector_size_t i) {
if (decodedIntermediateResult_.isNullAt(i)) {
return;
}
const auto decodedIndex = decodedIntermediateResult_.index(i);
updateValues(
group,
decodedValue_,
decodedComparison_,
decodedIndex,
decodedValue_.isNullAt(decodedIndex),
mayUpdate);
});
} else {
rows.applyToSelected([&](vector_size_t i) {
const auto decodedIndex = decodedIntermediateResult_.index(i);
Expand Down

0 comments on commit 53395a8

Please sign in to comment.