Skip to content

Commit

Permalink
added calculation for sum
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPresent-Han committed Nov 12, 2024
1 parent f2cb481 commit 73c3bcc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ endif ()
config_summary()

# **************************** Source files ****************************
set(BUILD_UNIT_TEST "ON")
if ( BUILD_UNIT_TEST STREQUAL "ON" AND BUILD_COVERAGE STREQUAL "ON" )
append_flags( CMAKE_CXX_FLAGS
FLAGS
Expand Down
2 changes: 1 addition & 1 deletion internal/core/src/common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ class RowType final {
AssertInfo(names_.size() == columns_types_.size(),
"Name count:{} and column count:{} must be the same",
names_.size(),
columns_types_.size())
columns_types_.size());
};

static const std::shared_ptr<const RowType> None;
Expand Down
10 changes: 10 additions & 0 deletions internal/core/src/common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,15 @@ inline std::string lowerString(const std::string& str) {
return ret;
}

template <typename T>
T checkPlus(const T& a, const T& b, const char* typeName = "integer"){
T result;
bool overflow = __builtin_add_overflow(a, b, &result);
if (UNLIKELY(overflow)) {
VELOX_ARITHMETIC_ERROR("{} overflow: {} + {}", typeName, a, b);
}
return result;
}

} // namespace milvus

9 changes: 4 additions & 5 deletions internal/core/src/exec/operator/query-agg/Aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ class Aggregate {
// so larger values need not be represented.
int32_t rowSizeOffset_ = 0;

// Number of null accumulators in the current state of the aggregation
// operator for this aggregate. If 0, clearing the null as part of update
// is not needed.
uint64_t numNulls_ = 0;

public:
DataType resultType() const {
return result_type_;
Expand Down Expand Up @@ -128,6 +123,10 @@ class Aggregate {
int32_t rowSizeOffset);

virtual void initializeNewGroupsInternal(char** groups, folly::Range<const vector_size_t*> indices) = 0;
// Number of null accumulators in the current state of the aggregation
// operator for this aggregate. If 0, clearing the null as part of update
// is not needed.
uint64_t numNulls_ = 0;
};

using AggregateFunctionFactory = std::function<std::unique_ptr<Aggregate>(plan::AggregationNode::Step step,
Expand Down
10 changes: 10 additions & 0 deletions internal/core/src/exec/operator/query-agg/SimpleNumericAggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class SimpleNumericAggregate : public exec::Aggregate {
}
}
}

template <bool tableHasNulls, typename TData = TResult,
typename TValue = TInput, typename UpdateSingleValue>
void updateGroups(char** groups,
const TargetBitmapView& rows,
const VectorPtr& vector,
UpdateSingleValue updateSingleValue,
bool mayPushdown){

}
};

}
Expand Down
34 changes: 34 additions & 0 deletions internal/core/src/exec/operator/query-agg/SumAggregateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// or implied. See the License for the specific language governing permissions and limitations under the License
#pragma once
#include "SimpleNumericAggregate.h"
#include "common/Utils.h"

namespace milvus{
namespace exec {
Expand Down Expand Up @@ -38,9 +39,42 @@ class SumAggregateBase: public SimpleNumericAggregate<TInput, TAccumulator, Resu
});
}

void addRawInput(char** groups, const TargetBitmapView& activeRows,
const std::vector<VectorPtr>& input, bool mayPushDown) override {

}

void initializeNewGroupsInternal(char** groups, folly::Range<const vector_size_t*> indices) override {

}

protected:
template <typename TData, typename TValue = TInput>
void updateInternal(char** groups, const TargetBitmapView& activeRows,
const std::vector<VectorPtr>& input, bool mayPushDown) {
const auto& input_column = input[0];
if (Aggregate::numNulls_) {
BaseAggregate::template updateGroups<true, TData, TValue>(groups, activeRows, input_column,
&updateSingleValue<TData>, false);
} else {
BaseAggregate::template updateGroups<false, TData, TValue>(groups, activeRows, input_column,
&updateSingleValue<TData>, false);
}
}

private:
template<typename TData>
#if defined(FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER)
FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER("signed-integer-overflow")
#endif
static void updateSingleValue(TData& result, TData value) {
if constexpr (std::is_same_v<TData, double> || std::is_same_v<TData, float>||
std::is_same_v<TData, int64_t> && Overflow) {
result += value;
} else {
result = checkPlus(result, value);
}
}
};
}
}

0 comments on commit 73c3bcc

Please sign in to comment.