HappenLee commented on code in PR #65847:
URL: https://github.com/apache/doris/pull/65847#discussion_r3688158849
##########
be/src/exprs/aggregate/aggregate_function_percentile.h:
##########
@@ -329,6 +329,241 @@ class AggregateFunctionPercentileApproxWeightedFourParams
final
}
};
+struct PercentileApproxArrayState {
+ void init(const PaddedPODArray<Float64>& quantiles, const NullMap&
null_map, size_t start,
+ size_t size, float compression = 10000) {
+ if (init_flag) {
+ return;
+ }
+
+ if (!std::isfinite(compression) || compression < 2048 || compression >
10000) {
+ compression = 10000;
+ }
+ compressions = compression;
+ levels.quantiles.resize(size);
+ levels.permutation.resize(size);
+ for (size_t i = 0; i < size; ++i) {
+ if (null_map[start + i]) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT,
+ "percentile_approx_array quantile should not
be null");
+ }
+ check_quantile(quantiles[start + i]);
+ levels.quantiles[i] = quantiles[start + i];
+ levels.permutation[i] = i;
+ }
+ if (!levels.empty()) {
+ digest = TDigest::create_unique(compressions);
+ }
+ init_flag = true;
+ }
+
+ void add_range(const Float64* values, size_t size) {
+ if (levels.empty()) {
+ return;
+ }
+ for (size_t i = 0; i < size; ++i) {
+ digest->add(static_cast<float>(values[i]));
+ }
+ }
+
+ void write(BufferWritable& buf) const {
+ buf.write_binary(init_flag);
+ if (!init_flag) {
+ return;
+ }
+
+ levels.write(buf);
+ buf.write_binary(compressions);
+ if (levels.empty()) {
+ return;
+ }
+ uint32_t serialize_size = digest->serialized_size();
+ std::string result(serialize_size, '0');
+ DCHECK(digest.get() != nullptr);
+ digest->serialize(reinterpret_cast<uint8_t*>(result.data()));
+ buf.write_binary(result);
+ }
+
+ void read(BufferReadable& buf) {
+ reset();
+ buf.read_binary(init_flag);
+ if (!init_flag) {
+ return;
+ }
+
+ levels.read(buf);
+ buf.read_binary(compressions);
+ if (levels.empty()) {
+ return;
+ }
+ std::string str;
+ buf.read_binary(str);
+ digest = TDigest::create_unique(compressions);
+ digest->unserialize(reinterpret_cast<const uint8_t*>(str.data()));
+ }
+
+ void merge(const PercentileApproxArrayState& rhs) {
+ if (!rhs.init_flag) {
+ return;
+ }
+
+ if (!init_flag) {
+ levels.merge(rhs.levels);
+ compressions = rhs.compressions;
+ if (!levels.empty()) {
+ digest = TDigest::create_unique(compressions);
+ }
+ init_flag = true;
+ } else {
+ if (compressions != rhs.compressions || levels.quantiles !=
rhs.levels.quantiles) {
+ throw Exception(
+ ErrorCode::INVALID_ARGUMENT,
+ "percentile_approx_array aggregate states have
incompatible quantiles "
+ "or compression");
+ }
+ levels.merge(rhs.levels);
Review Comment:
这个merge没有意义,418行检查过levels.quantiles != rhs.levels.quantiles
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]