You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2019/10/10 03:06:43 UTC

[GitHub] [incubator-doris] imay commented on a change in pull request #1889: Enhance the speed of avg function

imay commented on a change in pull request #1889: Enhance the speed of avg function
URL: https://github.com/apache/incubator-doris/pull/1889#discussion_r333312367
 
 

 ##########
 File path: be/src/exprs/aggregate_functions.cpp
 ##########
 @@ -305,6 +250,59 @@ DoubleVal AggregateFunctions::percentile_approx_finalize(FunctionContext* ctx, c
     return DoubleVal(result);
 }
 
+struct AvgState {
+    double sum;
+    int64_t count;
+};
+
+struct DecimalAvgState {
+    DecimalVal sum;
+    int64_t count;
+};
+
+struct DecimalV2AvgState {
+    DecimalV2Val sum;
+    int64_t count = 0;
+};
+
+void AggregateFunctions::avg_init(FunctionContext* ctx, StringVal* dst) {
+    dst->is_null = false;
+    dst->len = sizeof(AvgState);
+    dst->ptr = ctx->allocate(dst->len);
+    memset(dst->ptr, 0, sizeof(AvgState));
 
 Review comment:
   better to give default value to AvgState, and call placement new to initialize it.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org