Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[only test] #41069

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 44 additions & 6 deletions be/src/vec/aggregate_functions/aggregate_function_percentile.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class AggregateFunctionPercentileApproxWeightedFourParams
};

template <typename T>
struct PercentileState {
struct PercentileStateArray {
mutable std::vector<Counts<T>> vec_counts;
std::vector<double> vec_quantile {-1};
bool inited_flag = false;
Expand Down Expand Up @@ -635,7 +635,7 @@ struct PercentileState {
}
}

void merge(const PercentileState& rhs) {
void merge(const PercentileStateArray& rhs) {
if (!rhs.inited_flag) {
return;
}
Expand Down Expand Up @@ -670,6 +670,44 @@ struct PercentileState {
}
};

template <typename T>
struct PercentileState {
mutable Counts<T> count;
double quantile {-1};

void write(BufferWritable& buf) const {
write_binary(quantile, buf);
count.serialize(buf);
}

void read(BufferReadable& buf) {
read_binary(quantile, buf);
count.unserialize(buf);
}

void add(T source, const Float64& q) {
DCHECK(quantile == -1 || quantile == q);
quantile = q;
count.increment(source, 1);
}

void merge(const PercentileState& rhs) {
if (quantile == -1) {
quantile = rhs.quantile;
}
count.merge(const_cast<Counts<T>*>(&(rhs.count)));
}

void reset() {}

double get() const { return quantile == -1 ? 0 : count.terminate(quantile); }

void insert_result_into(IColumn& to) const {
auto& column_data = assert_cast<ColumnFloat64&>(to).get_data();
column_data.push_back(get());
}
};

template <typename T>
class AggregateFunctionPercentile final
: public IAggregateFunctionDataHelper<PercentileState<T>, AggregateFunctionPercentile<T>> {
Expand All @@ -689,7 +727,7 @@ class AggregateFunctionPercentile final
const auto& quantile =
assert_cast<const ColumnFloat64&, TypeCheckOnRelease::DISABLE>(*columns[1]);
AggregateFunctionPercentile::data(place).add(sources.get_data()[row_num],
quantile.get_data(), 1);
quantile.get_data()[0]);
}

void reset(AggregateDataPtr __restrict place) const override {
Expand Down Expand Up @@ -718,12 +756,12 @@ class AggregateFunctionPercentile final

template <typename T>
class AggregateFunctionPercentileArray final
: public IAggregateFunctionDataHelper<PercentileState<T>,
: public IAggregateFunctionDataHelper<PercentileStateArray<T>,
AggregateFunctionPercentileArray<T>> {
public:
using ColVecType = ColumnVector<T>;
using Base =
IAggregateFunctionDataHelper<PercentileState<T>, AggregateFunctionPercentileArray<T>>;
using Base = IAggregateFunctionDataHelper<PercentileStateArray<T>,
AggregateFunctionPercentileArray<T>>;
AggregateFunctionPercentileArray(const DataTypes& argument_types_) : Base(argument_types_) {}

String get_name() const override { return "percentile_array"; }
Expand Down
Loading