zclllyybb commented on code in PR #49392: URL: https://github.com/apache/doris/pull/49392#discussion_r2016338382
########## be/src/vec/functions/function_string.cpp: ########## @@ -928,6 +928,44 @@ struct UnHexImpl { return Status::OK(); } + + static Status vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets, + ColumnString::Chars& dst_data, ColumnString::Offsets& dst_offsets, + ColumnUInt8::Container& null_map_data) { + auto rows_count = offsets.size(); + dst_offsets.resize(rows_count); + + for (int i = 0; i < rows_count; ++i) { + const auto* source = reinterpret_cast<const char*>(&data[offsets[i - 1]]); + ColumnString::Offset srclen = offsets[i] - offsets[i - 1]; + + if (srclen == 0) { + StringOP::push_null_string(i, dst_data, dst_offsets, null_map_data); + continue; + } + + char dst_array[MAX_STACK_CIPHER_LEN]; + char* dst = dst_array; + + int cipher_len = srclen / 2; + std::unique_ptr<char[]> dst_uptr; + if (cipher_len > MAX_STACK_CIPHER_LEN) { + dst_uptr.reset(new char[cipher_len]); + dst = dst_uptr.get(); + } + + int outlen = hex_decode(source, srclen, dst); + if (outlen == 0) { + LOG(INFO) << "--ftw: outlen == 0 "; Review Comment: remove this log ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonExtractNoQuotes.java: ########## @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.expressions.functions.scalar; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.util.ExpressionUtils; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'json_object'. This class is generated by GenerateFunction. + */ +public class JsonExtractNoQuotes extends ScalarFunction + implements ExplicitlyCastableSignature, AlwaysNullable { + + public static final List<FunctionSignature> SIGNATURES = + ImmutableList.of(FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) Review Comment: 这个支持多参数?需要有测试case保证。 ########## be/src/vec/functions/function_string.cpp: ########## @@ -928,6 +928,44 @@ struct UnHexImpl { return Status::OK(); } + + static Status vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets, Review Comment: 这个函数也可以直接合并到上面那个vector,加个模板参数Nullable,然后null_map_data变成指针形式。958行用if constexpr套起来就可以了。 ########## gensrc/script/doris_builtins_functions.py: ########## Review Comment: no need to modify this file anymore ########## be/src/vec/functions/function_totype.h: ########## @@ -519,4 +518,41 @@ class FunctionStringEncode : public IFunction { } }; +template <typename Impl> +class FunctionStringEncodeNullable : public IFunction { +public: + static constexpr auto name = "unhex_null"; + + static FunctionPtr create() { return std::make_shared<FunctionStringEncodeNullable>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return make_nullable(std::make_shared<typename Impl::ReturnType>()); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + uint32_t result, size_t input_rows_count) const override { + auto& col_ptr = block.get_by_position(arguments[0]).column; + auto null_map = ColumnUInt8::create(input_rows_count, 0); + // auto const_null_map = ColumnUInt8::create(input_rows_count, 0); + auto& null_map_data = null_map->get_data(); + if (const auto* col = check_and_get_column<ColumnString>(col_ptr.get())) { Review Comment: 直接用`assert_cast`,不要check_and_get_column了 ########## be/src/vec/functions/function_totype.h: ########## @@ -519,4 +518,41 @@ class FunctionStringEncode : public IFunction { } }; +template <typename Impl> +class FunctionStringEncodeNullable : public IFunction { Review Comment: 这个模板可能没必要存在,直接用FunctionStringEncode就可以了。加一个模板参数bool Nullable。然后544-549,以及get_return_type_impl,用if constexpr就可以。 -- 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