imay commented on a change in pull request #1529: Refactor storage aggregate 
framework
URL: https://github.com/apache/incubator-doris/pull/1529#discussion_r306245059
 
 

 ##########
 File path: be/src/olap/aggregate_func.h
 ##########
 @@ -15,221 +15,283 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#ifndef DORIS_BE_SRC_OLAP_AGGREGATE_FUNC_H
-#define DORIS_BE_SRC_OLAP_AGGREGATE_FUNC_H
+#pragma once
 
 #include "olap/hll.h"
 #include "olap/types.h"
 #include "util/arena.h"
 
 namespace doris {
 
-using AggregateFunc = void (*)(char* left, const char* right, Arena* arena);
-using FinalizeFunc = void (*)(char* data);
+using AggeInitFunc = void (*)(char* dst, Arena* arena);
+using AggUpdateFunc = void (*)(char* dst, const char* src, Arena* arena);
+using AggFinalizeFunc = void (*)(char* data, Arena* arena);
 
-template<FieldAggregationMethod agg_method,
-        FieldType field_type> struct AggregateFuncTraits {};
+// This class contains information about aggregate operation.
+class AggregateInfo {
+public:
+    // Init function will initialize aggregation execute environment in dst.
+    // For example: for sum, we just initial dst to 0. For HLL column, it will
+    // allocate and init context used to compute HLL.
+    //
+    // Memory Note: For plain memory can be allocated from arena, whose 
lifetime
+    // will last util finalize function is called. Memory allocated from heap 
should
+    // be freed in finalize functioin to avoid memory leak.
+    inline void init(void* dst, Arena* arena) const {
+        _init_fn((char*)dst, arena);
+    }
+
+    // Actually do the aggregate operation. dst is the context which is 
initialized
+    // by init function, src is the current value which is to be aggregated.
+    // For example: For sum, dst is the current sum, and src is the next value 
which
+    // will be added to sum.
+    // This function usually is used when load function.
+    //
+    // Memory Note: Same with init function.
+    inline void update(void* dst, const void* src, Arena* arena) const {
+        _update_fn((char*)dst, (const char*)src, arena);
+    }
+
+    // Merge aggregated intermediate data. Data stored in engine is aggregated,
+    // because storage has done some aggregate when loading or compaction.
+    // So this function is often used in read operation.
+    // 
+    // Memory Note: Same with init function.
+    inline void merge(void* dst, const void* src, Arena* arena) const {
+        _merge_fn((char*)dst, (const char*)src, arena);
+    }
+
+    // Finalize function convert intermediate context into final format. For 
example:
+    // For HLL type, finalize function will serialize the aggregate context 
into a slice.
+    // For input src points to the context, and when function is finished, 
result will be
+    // saved in src.
+    //
+    // Memory Note: All heap memory allocated in init and update function 
should be freed
+    // before this function return. Memory allocated from arena will be still 
available
+    // and will be freed by client.
+    inline void finalize(void* src, Arena* arena) const {
+        _finalize_fn((char*)src, arena);
+    }
 
-template<FieldType field_type>
-struct AggregateFuncTraits<OLAP_FIELD_AGGREGATION_NONE, field_type> {
-    static void aggregate(char* left, const char* right, Arena* arena) {}
+private:
+    void (*_init_fn)(char* dst, Arena* arena);
+    void (*_update_fn)(char* dst, const char* src, Arena* arena);
+    void (*_merge_fn)(char* dst, const char* src, Arena* arena);
+    void (*_finalize_fn)(char* dst, Arena* arena);
+
+    friend class AggregateFuncResolver;
+
+    template<typename Traits>
+    AggregateInfo(const Traits& traits);
+};
+
+struct BaseAggregateFuncs {
 
 Review comment:
   No, we can't remove this. Because 1. we need to define a merge function 
here. 2. For none aggregate method, whose update operation is default.

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