imay commented on a change in pull request #1432: Add percentile_approx 
aggregate function
URL: https://github.com/apache/incubator-doris/pull/1432#discussion_r301529949
 
 

 ##########
 File path: be/src/exprs/aggregate_functions.cpp
 ##########
 @@ -231,6 +232,84 @@ void AggregateFunctions::avg_update(FunctionContext* ctx, 
const T& src, StringVa
     ++avg->count;
 }
 
+struct PercentileApproxState {
+public:
+    TDigest *digest = nullptr;
+    double targetQuantile = -1.0;
+
+    ~PercentileApproxState() {
+        if (digest != nullptr) {
+            delete digest;
+        }
+    }
+};
+
+void AggregateFunctions::percentile_approx_init(FunctionContext* ctx, 
StringVal* dst) {
+    dst->is_null = false;
+    dst->len = sizeof(PercentileApproxState);
+    dst->ptr = (uint8_t*) new PercentileApproxState();
+
+    PercentileApproxState* percentile = 
reinterpret_cast<PercentileApproxState*>(dst->ptr);
+    percentile->targetQuantile = -1.0;
+    percentile->digest = new TDigest();
+};
+
+template<typename T>
+void AggregateFunctions::percentile_approx_update(FunctionContext* ctx, const 
T& src, const DoubleVal& quantile, StringVal* dst) {
+    if (src.is_null) {
+        return;
+    }
+    DCHECK(dst->ptr != NULL);
+    DCHECK_EQ(sizeof(PercentileApproxState), dst->len);
+
+    PercentileApproxState* percentile = 
reinterpret_cast<PercentileApproxState*>(dst->ptr);
+    percentile->digest->add(src.val);
+    percentile->targetQuantile = quantile.val;
 
 Review comment:
   I think you should check quantile in Frontend which should be a const 
expression. If quantile is not const, I think this function has no use.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to