kangkaisen commented on a change in pull request #1599: Add bitmap Agg type and 
Udaf
URL: https://github.com/apache/incubator-doris/pull/1599#discussion_r311519204
 
 

 ##########
 File path: be/src/exprs/aggregate_functions.cpp
 ##########
 @@ -2381,6 +2382,95 @@ void 
AggregateFunctions::offset_fn_update(FunctionContext* ctx, const IntVal& sr
     *dst = src;
 }
 
+
+void AggregateFunctions::bitmap_init(FunctionContext* ctx, StringVal* dst) {
+    dst->is_null = false;
+    dst->len = sizeof(RoaringBitmap);
+    dst->ptr = (uint8_t*)new RoaringBitmap();
+}
+
+template <typename T>
+void AggregateFunctions::bitmap_update(FunctionContext* ctx, T& src, 
StringVal* dst) {
+    if (src.is_null) {
+        return;
+    }
+    DCHECK(!dst->is_null);
+
+    auto* dst_bitmap = reinterpret_cast<RoaringBitmap*>(dst->ptr);
+    dst_bitmap->update(src.val);
+}
+
+void AggregateFunctions::bitmap_merge(FunctionContext* ctx, StringVal& src, 
StringVal* dst) {
+    DCHECK(!dst->is_null);
+    DCHECK(!src.is_null);
+
+    RoaringBitmap src_bitmap = RoaringBitmap((char*)src.ptr);
+    auto* dst_bitmap = reinterpret_cast<RoaringBitmap*>(dst->ptr);
+    dst_bitmap->merge(src_bitmap);
+}
+
+StringVal AggregateFunctions::bitmap_serialize(FunctionContext* ctx, const 
StringVal& src) {
+    DCHECK(!src.is_null);
+
+    auto* src_bitmap = reinterpret_cast<RoaringBitmap*>(src.ptr);
+    StringVal result(ctx, src_bitmap->size());
+    src_bitmap->serialize((char*)result.ptr);
 
 Review comment:
   Yed

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