Skip to content

Commit e7044cf

Browse files
liujiayi771GlutenPerfBot
authored and
GlutenPerfBot
committed
[6020 ] Spark sql avg agg function support decimal
fix decimal avg function precision issue
1 parent 81bc358 commit e7044cf

File tree

4 files changed

+523
-24
lines changed

4 files changed

+523
-24
lines changed

velox/functions/lib/aggregates/AverageAggregateBase.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace facebook::velox::functions::aggregate {
2121
void checkAvgIntermediateType(const TypePtr& type) {
2222
VELOX_USER_CHECK(
2323
type->isRow() || type->isVarbinary(),
24-
"Input type for final average must be row type or varbinary type.");
24+
"Input type for final average must be row type or varbinary type, find {}",
25+
type->toString());
2526
if (type->kind() == TypeKind::VARBINARY) {
2627
return;
2728
}

velox/functions/lib/aggregates/DecimalAggregate.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class DecimalAggregate : public exec::Aggregate {
7878
}
7979

8080
int32_t accumulatorAlignmentSize() const override {
81-
return static_cast<int32_t>(sizeof(int128_t));
81+
return alignof(LongDecimalWithOverflowState);
8282
}
8383

8484
void addRawInput(
@@ -275,7 +275,9 @@ class DecimalAggregate : public exec::Aggregate {
275275
}
276276

277277
virtual TResultType computeFinalValue(
278-
LongDecimalWithOverflowState* accumulator) = 0;
278+
LongDecimalWithOverflowState* accumulator) {
279+
return 0;
280+
};
279281

280282
void extractValues(char** groups, int32_t numGroups, VectorPtr* result)
281283
override {
@@ -327,11 +329,11 @@ class DecimalAggregate : public exec::Aggregate {
327329
}
328330
}
329331

330-
private:
331332
inline LongDecimalWithOverflowState* decimalAccumulator(char* group) {
332333
return exec::Aggregate::value<LongDecimalWithOverflowState>(group);
333334
}
334335

336+
private:
335337
DecodedVector decodedRaw_;
336338
DecodedVector decodedPartial_;
337339
};

0 commit comments

Comments
 (0)