Skip to content
Draft
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
24 changes: 23 additions & 1 deletion be/src/exprs/aggregate/aggregate_function_avg.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#pragma once

#include <glog/logging.h>
#include <string.h>

#include <cstring>
#include <limits>
#include <memory>
#include <ostream>
Expand Down Expand Up @@ -60,6 +60,28 @@ struct AggregateFunctionAvgData {

AggregateFunctionAvgData& operator=(const AggregateFunctionAvgData<T>& src) = default;

void reset() {
sum = {};
count = 0;
}

template <PrimitiveType InputType>
NO_SANITIZE_UNDEFINED void add(typename PrimitiveTypeTraits<InputType>::CppType value) {
#ifdef __clang__
#pragma clang fp reassociate(on)
#endif
if constexpr (InputType == TYPE_DECIMALV2) {
sum += value;
} else if constexpr (is_decimal(InputType)) {
sum += value.value;
} else {
sum += static_cast<ResultType>(value);
}
++count;
}

bool has_value() const { return count > 0; }

template <typename ResultT>
ResultT result(ResultType multiplier) const {
if (!count) {
Expand Down
5 changes: 3 additions & 2 deletions be/src/exprs/aggregate/aggregate_function_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

#pragma once

#include <stddef.h>

#include <cstddef>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -50,6 +49,8 @@ template <PrimitiveType T>
struct AggregateFunctionSumData {
typename PrimitiveTypeTraits<T>::CppType sum {};

void reset() { sum = {}; }

NO_SANITIZE_UNDEFINED void add(typename PrimitiveTypeTraits<T>::CppType value) {
#ifdef __clang__
#pragma clang fp reassociate(on)
Expand Down
Loading
Loading