Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiayi771 committed Feb 28, 2024
1 parent 12e10e0 commit e1614c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
16 changes: 12 additions & 4 deletions velox/docs/develop/aggregate-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ For aggregaiton functions of default-null behavior, the author defines an
// Optional. Default is false.
static constexpr bool use_external_memory_ = true;

// Optional. Default is false.
static constexpr bool aligned_accumulator_ = true;

explicit AccumulatorType(HashStringAllocator* allocator);

void addInput(HashStringAllocator* allocator, exec::arg_type<T1> value1, ...);
Expand All @@ -274,7 +277,9 @@ The author defines an optional flag `is_fixed_size_` indicating whether the
every accumulator takes fixed amount of memory. This flag is true by default.
Next, the author defines another optional flag `use_external_memory_`
indicating whether the accumulator uses memory that is not tracked by Velox.
This flag is false by default.
This flag is false by default. Then, the author can define optional flag
`aligned_accumulator_` indicationg whether the accumulator requires aligned
access. This flag is false by default.

The author defines a constructor that takes a single argument of
`HashStringAllocator*`. This constructor is called before aggregation starts to
Expand Down Expand Up @@ -345,6 +350,9 @@ For aggregaiton functions of non-default-null behavior, the author defines an
// Optional. Default is false.
static constexpr bool use_external_memory_ = true;

// Optional. Default is false.
static constexpr bool aligned_accumulator_ = true;

explicit AccumulatorType(HashStringAllocator* allocator);

bool addInput(HashStringAllocator* allocator, exec::optional_arg_type<T1> value1, ...);
Expand All @@ -361,9 +369,9 @@ For aggregaiton functions of non-default-null behavior, the author defines an
void destroy(HashStringAllocator* allocator);
};

The definition of `is_fixed_size_`, `use_external_memory_`, the constructor,
and the `destroy` method are exactly the same as those for default-null
behavior.
The definition of `is_fixed_size_`, `use_external_memory_`,
`aligned_accumulator_` the constructor, and the `destroy` method are exactly
the same as those for default-null behavior.

On the other hand, the C++ function signatures of `addInput`, `combine`,
`writeIntermediateResult`, and `writeFinalResult` are different.
Expand Down
4 changes: 4 additions & 0 deletions velox/functions/sparksql/aggregates/DecimalSumAggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class DecimalSumAggregate {

// isEmpty is never null.
VELOX_CHECK(otherIsEmpty.has_value());
if (isEmpty && otherIsEmpty.value()) {
// Both accumulators are empty, no need to do the combination.
return false;
}

bool currentOverflow = !isEmpty && !sum.has_value();
bool otherOverflow = !otherIsEmpty.value() && !otherSum.has_value();
Expand Down
16 changes: 5 additions & 11 deletions velox/functions/sparksql/aggregates/SumAggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ namespace {
template <typename TInput, typename TAccumulator, typename ResultType>
using SumAggregate = SumAggregateBase<TInput, TAccumulator, ResultType, true>;

TypePtr getDecimalSumType(
const TypePtr& resultType,
core::AggregationNode::Step step) {
if (exec::isPartialOutput(step)) {
return resultType->childAt(0);
}
if (step == core::AggregationNode::Step::kSingle && resultType->isRow()) {
// For companion function of decimal sum. For a partial companion function
// of single step, the result type is like partial output, consisting of sum
// and isEmpty.
TypePtr getDecimalSumType(const TypePtr& resultType) {
if (resultType->isRow()) {
// If the resultType is ROW, then the type if sum is the type of the first
// child of the ROW.
return resultType->childAt(0);
}
return resultType;
Expand Down Expand Up @@ -105,7 +99,7 @@ exec::AggregateRegistrationResult registerSum(
BIGINT());
case TypeKind::BIGINT: {
if (inputType->isShortDecimal()) {
auto const sumType = getDecimalSumType(resultType, step);
auto const sumType = getDecimalSumType(resultType);
if (sumType->isShortDecimal()) {
return std::make_unique<exec::SimpleAggregateAdapter<
DecimalSumAggregate<int64_t, int64_t>>>(resultType);
Expand Down

0 comments on commit e1614c7

Please sign in to comment.