zhangstar333 commented on code in PR #56648:
URL: https://github.com/apache/doris/pull/56648#discussion_r2435310934
##########
be/src/vec/functions/function_varbinary.cpp:
##########
@@ -143,11 +148,131 @@ class FunctionFromBinary : public IFunction {
}
};
+struct NameVarbinaryLength {
+ static constexpr auto name = "length";
+};
+
+struct VarbinaryLengthImpl {
+ using ReturnType = DataTypeInt32;
+ using ReturnColumnType = ColumnInt32;
+ static constexpr auto PrimitiveTypeImpl = PrimitiveType::TYPE_VARBINARY;
+
+ static DataTypes get_variadic_argument_types() {
+ return {std::make_shared<DataTypeVarbinary>()};
+ }
+
+ static Status vector(const PaddedPODArray<doris::StringView>& data,
+ PaddedPODArray<Int32>& res) {
+ size_t rows_count = data.size();
+ res.resize(rows_count);
+ for (size_t 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";
+ using ReturnType = DataTypeString;
+ using ColumnType = ColumnString;
+ static constexpr auto PrimitiveTypeImpl = PrimitiveType::TYPE_VARBINARY;
+
+ static Status vector(const PaddedPODArray<doris::StringView>& data,
+ ColumnString::Chars& dst_data, ColumnString::Offsets&
dst_offsets) {
+ auto rows_count = data.size();
+ dst_offsets.resize(rows_count);
+
+ int64_t total_size = 0;
+ for (size_t i = 0; i < rows_count; i++) {
+ total_size += 4 * ((data[i].size() + 2) / 3);
+ }
+ ColumnString::check_chars_length(total_size, rows_count);
+ dst_data.resize(total_size);
+ auto* dst_data_ptr = dst_data.data();
+ size_t offset = 0;
+
+ for (size_t i = 0; i < rows_count; i++) {
+ auto binary = data[i];
+ auto binlen = binary.size();
+
+ if (UNLIKELY(binlen == 0)) {
+ dst_offsets[i] = cast_set<uint32_t>(offset);
+ continue;
+ }
+
+ auto outlen = doris::base64_encode(
+ reinterpret_cast<const unsigned char*>(binary.data()),
binlen,
+ reinterpret_cast<unsigned char*>(dst_data_ptr + offset));
+
+ offset += outlen;
+ dst_offsets[i] = cast_set<uint32_t>(offset);
+ }
+
+ return Status::OK();
+ }
+};
+
+using FunctionToBase64Binary = FunctionStringEncode<ToBase64BinaryImpl, false>;
+
+struct FromBase64BinaryImpl {
+ static constexpr auto name = "from_base64_binary";
+ using ReturnType = DataTypeVarbinary;
+ using ColumnType = ColumnVarbinary;
+
+ static Status vector(const ColumnString::Chars& data, const
ColumnString::Offsets& offsets,
+ ColumnVarbinary* res, NullMap& null_map) {
+ auto rows_count = offsets.size();
+ res->get_data().resize(rows_count);
+
+ for (size_t i = 0; i < rows_count; i++) {
+ const auto* source = reinterpret_cast<const char*>(&data[offsets[i
- 1]]);
+ ColumnString::Offset slen = offsets[i] - offsets[i - 1];
+
+ if (UNLIKELY(slen == 0)) {
+ VarBinaryOP::insert_default(res->get_data()[i]);
Review Comment:
the res have resize at Line228,
seems no need insert 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.
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]