yiguolei commented on code in PR #23759:
URL: https://github.com/apache/doris/pull/23759#discussion_r1312852685


##########
be/src/vec/functions/function_bitmap.cpp:
##########
@@ -887,6 +942,40 @@ struct BitmapToString {
     }
 };
 
+struct NameBitmapToBase64 {
+    static constexpr auto name = "bitmap_to_base64";
+};
+
+struct BitmapToBase64 {
+    using ReturnType = DataTypeString;
+    static constexpr auto TYPE_INDEX = TypeIndex::BitMap;
+    using Type = DataTypeBitMap::FieldType;
+    using ReturnColumnType = ColumnString;
+    using Chars = ColumnString::Chars;
+    using Offsets = ColumnString::Offsets;
+
+    static Status vector(const std::vector<BitmapValue>& data, Chars& chars, 
Offsets& offsets) {
+        size_t size = data.size();
+        offsets.resize(size);
+        chars.reserve(size);
+        for (size_t i = 0; i < size; ++i) {
+            BitmapValue& bitmap_val = const_cast<BitmapValue&>(data[i]);
+            auto ser_size = bitmap_val.getSizeInBytes();
+            char ser_buff[ser_size];
+            bitmap_val.write_to(ser_buff);
+
+            int encoded_size = (int)(4.0 * ceil((double)ser_size / 3.0));
+            char dst[encoded_size];
+            memset(dst, 0, encoded_size);
+            int outlen =
+                    base64_encode((const unsigned char*)ser_buff, ser_size, 
(unsigned char*)dst);
+            DCHECK(outlen > 0);
+            StringOP::push_value_string(std::string_view(dst, outlen), i, 
chars, offsets);

Review Comment:
   IF the output string will copy the column, then we could reuse the buffer. 
And realloc a new buffer if it size is less than needed.



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

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to