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

 ##########
 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();
 
 Review comment:
   I think you'd better to move `new TDigest()` to PercentileApproxState's 
constructor

----------------------------------------------------------------
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