linrrzqqq commented on code in PR #62520:
URL: https://github.com/apache/doris/pull/62520#discussion_r3097587226
##########
be/src/exprs/aggregate/aggregate_function_percentile.h:
##########
@@ -436,6 +429,194 @@ struct PercentileState {
}
};
+template <PrimitiveType T>
+struct PercentileExactState {
+ using ValueType = typename PrimitiveTypeTraits<T>::CppType;
+ static constexpr size_t bytes_in_arena = 64 - sizeof(PODArray<ValueType>);
+ using Array = PODArrayWithStackMemory<ValueType, bytes_in_arena>;
+
+ void add_single_range(const ValueType* data, size_t count, double
quantile) {
+ if (!inited_flag) {
+ _set_single_level(quantile);
+ inited_flag = true;
+ }
+ _append(data, count);
+ }
+
+ void add_many_range(const ValueType* data, size_t count,
+ const PaddedPODArray<Float64>& quantiles_data, const
NullMap& null_maps,
+ size_t start, int64_t arg_size) {
+ if (!inited_flag) {
+ _set_many_levels(quantiles_data, null_maps, start, arg_size);
+ inited_flag = true;
+ }
+ if (levels.empty()) {
+ return;
+ }
+ _append(data, count);
+ }
+
+ void write(BufferWritable& buf) const {
+ buf.write_binary(inited_flag);
+ if (!inited_flag) {
+ return;
+ }
+
+ levels.write(buf);
+ size_t size = values.size();
+ buf.write_binary(size);
+ if (size > 0) {
+ buf.write(reinterpret_cast<const char*>(values.data()),
sizeof(ValueType) * size);
+ }
+ }
+
+ void read(BufferReadable& buf) {
+ reset();
+ buf.read_binary(inited_flag);
+ if (!inited_flag) {
+ return;
+ }
+
+ levels.read(buf);
+ size_t size = 0;
+ buf.read_binary(size);
+ values.resize(size);
+ if (size > 0) {
+ auto raw = buf.read(sizeof(ValueType) * size);
+ memcpy(values.data(), raw.data, raw.size);
+ }
+ }
+
+ void merge(const PercentileExactState& rhs) {
+ if (!rhs.inited_flag) {
+ return;
+ }
+
+ if (!inited_flag) {
+ levels = rhs.levels;
+ inited_flag = true;
+ } else {
+ levels.merge(rhs.levels);
+ }
+ _append(rhs.values.data(), rhs.values.size());
+ }
+
+ void reset() {
+ values.clear();
+ levels.clear();
+ inited_flag = false;
+ }
+
+ double get() const {
+ if (!inited_flag || levels.empty() || values.empty()) {
+ return 0.0;
+ }
+
+ DCHECK_EQ(levels.quantiles.size(), 1);
+ return _get_float(levels.quantiles[0]);
+ }
+
+ void insert_result_into(IColumn& to) const {
+ auto& column_data = assert_cast<ColumnFloat64&>(to).get_data();
+ if (!inited_flag || levels.empty() || values.empty()) {
Review Comment:
行为不一致
```text
Doris> SELECT percentile(num, 0.5) FROM test_percent;
+----------------------+
| percentile(num, 0.5) |
+----------------------+
| NULL |
+----------------------+
1 row in set (0.228 sec)
Doris> SELECT percentile_array(num, [0.1, 0.5]) FROM test_percent;
+-----------------------------------+
| percentile_array(num, [0.1, 0.5]) |
+-----------------------------------+
| [] |
+-----------------------------------+
1 row in set (0.127 sec)
```
--
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]