zhangstar333 commented on code in PR #56648:
URL: https://github.com/apache/doris/pull/56648#discussion_r2422691472


##########
be/src/vec/functions/function_varbinary.cpp:
##########
@@ -143,11 +150,197 @@ class FunctionFromBinary : public IFunction {
     }
 };
 
+struct NameVarbinaryLength {
+    static constexpr auto name = "length";
+};
+
+struct VarbinaryLengthImpl {
+    using ReturnType = DataTypeInt32;
+    static constexpr auto PrimitiveTypeImpl = PrimitiveType::TYPE_VARBINARY;
+    using ReturnColumnType = ColumnInt32;
+
+    static DataTypes get_variadic_argument_types() {
+        return {std::make_shared<DataTypeVarbinary>()};
+    }
+
+    static Status vector(const PaddedPODArray<doris::StringView>& data,
+                         PaddedPODArray<Int32>& res) {
+        int rows_count = data.size();
+        res.resize(rows_count);
+        for (int i = 0; i < rows_count; ++i) {
+            res[i] = data[i].size();
+        }
+        return Status::OK();
+    }
+};
+
+using FunctionBinaryLength = FunctionUnaryToType<VarbinaryLengthImpl, 
NameVarbinaryLength>;
+
+struct ToBase64BinaryImpl {
+    static constexpr auto name = "to_base64_binary";
+    static constexpr auto is_nullable = false;
+
+    using ReturnType = DataTypeString;
+
+    static Status execute_impl(FunctionContext* context, Block& block,
+                               const ColumnNumbers& arguments, uint32_t result,
+                               size_t input_rows_count) {
+        auto& col_ptr = block.get_by_position(arguments[0]).column;
+        if (const auto* col = 
check_and_get_column<ColumnVarbinary>(col_ptr.get())) {
+            auto result_column = ColumnString::create();
+            result_column->get_offsets().reserve(input_rows_count);
+
+            for (size_t i = 0; i < input_rows_count; i++) {
+                auto binary = col->get_data_at(i);
+
+                if (binary.size == 0) {
+                    result_column->insert_default();
+                    continue;
+                }
+
+                char dst_array[MAX_STACK_CIPHER_LEN];
+                char* dst = dst_array;
+
+                int cipher_len = 4 * ((binary.size + 2) / 3);
+                std::unique_ptr<char[]> dst_uptr;
+                if (cipher_len > MAX_STACK_CIPHER_LEN) {
+                    dst_uptr.reset(new char[cipher_len]);
+                    dst = dst_uptr.get();
+                }
+
+                auto len = doris::base64_encode(reinterpret_cast<const 
unsigned char*>(binary.data),
+                                                binary.size, 
reinterpret_cast<unsigned char*>(dst));
+
+                result_column->insert_data(dst, len);
+            }
+            block.replace_by_position(result, std::move(result_column));
+        } else {
+            return Status::RuntimeError("Illegal column {} of argument of 
function {}",
+                                        
block.get_by_position(arguments[0]).column->get_name(),
+                                        ToBase64BinaryImpl::name);
+        }
+
+        return Status::OK();
+    }
+};
+
+using FunctionToBase64Binary = FunctionBinaryUnary<ToBase64BinaryImpl>;

Review Comment:
   i am little confused of this,?
   as seems if you use FunctionStringOperateToNullType class, you could add the 
ckeck of ColumnVarbinary, and the Impl::vector function you could design it by 
your self, same as you implement in FunctionBinaryUnary
   ```
   if (const auto* col = check_and_get_column<ColumnVarbinary>(col_ptr.get())) {
        Impl::vector(xxx)
   }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to