Coverage Report

Created: 2026-04-15 12:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/function_string_replace.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <cstddef>
21
#include <cstring>
22
#include <string>
23
#include <string_view>
24
25
#include "common/compiler_util.h"
26
#include "common/status.h"
27
#include "core/assert_cast.h"
28
#include "core/block/block.h"
29
#include "core/block/column_numbers.h"
30
#include "core/column/column_const.h"
31
#include "core/column/column_nullable.h"
32
#include "core/column/column_string.h"
33
#include "core/column/column_vector.h"
34
#include "core/data_type/data_type_nullable.h"
35
#include "core/data_type/data_type_number.h"
36
#include "core/data_type/data_type_string.h"
37
#include "core/string_ref.h"
38
#include "exec/common/stringop_substring.h"
39
#include "exec/common/template_helpers.hpp"
40
#include "exprs/function/function.h"
41
#include "exprs/function/function_helpers.h"
42
#include "exprs/function_context.h"
43
#include "util/simd/vstring_function.h"
44
45
namespace doris {
46
#include "common/compile_check_avoid_begin.h"
47
48
struct ReplaceImpl {
49
    static constexpr auto name = "replace";
50
};
51
52
struct ReplaceEmptyImpl {
53
    static constexpr auto name = "replace_empty";
54
};
55
56
template <typename Impl, bool empty>
57
class FunctionReplace : public IFunction {
58
public:
59
    static constexpr auto name = Impl::name;
60
3.03k
    static FunctionPtr create() { return std::make_shared<FunctionReplace<Impl, empty>>(); }
_ZN5doris15FunctionReplaceINS_11ReplaceImplELb1EE6createEv
Line
Count
Source
60
1.51k
    static FunctionPtr create() { return std::make_shared<FunctionReplace<Impl, empty>>(); }
_ZN5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE6createEv
Line
Count
Source
60
1.51k
    static FunctionPtr create() { return std::make_shared<FunctionReplace<Impl, empty>>(); }
61
2
    String get_name() const override { return name; }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE8get_nameB5cxx11Ev
Line
Count
Source
61
1
    String get_name() const override { return name; }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE8get_nameB5cxx11Ev
Line
Count
Source
61
1
    String get_name() const override { return name; }
62
3.02k
    size_t get_number_of_arguments() const override { return 3; }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE23get_number_of_argumentsEv
Line
Count
Source
62
1.51k
    size_t get_number_of_arguments() const override { return 3; }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE23get_number_of_argumentsEv
Line
Count
Source
62
1.51k
    size_t get_number_of_arguments() const override { return 3; }
63
64
3.02k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
65
3.02k
        return std::make_shared<DataTypeString>();
66
3.02k
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
64
1.51k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
65
1.51k
        return std::make_shared<DataTypeString>();
66
1.51k
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
64
1.51k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
65
1.51k
        return std::make_shared<DataTypeString>();
66
1.51k
    }
67
68
2
    DataTypes get_variadic_argument_types_impl() const override {
69
2
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
70
2
                std::make_shared<DataTypeString>()};
71
2
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE32get_variadic_argument_types_implEv
Line
Count
Source
68
1
    DataTypes get_variadic_argument_types_impl() const override {
69
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
70
1
                std::make_shared<DataTypeString>()};
71
1
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE32get_variadic_argument_types_implEv
Line
Count
Source
68
1
    DataTypes get_variadic_argument_types_impl() const override {
69
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
70
1
                std::make_shared<DataTypeString>()};
71
1
    }
72
73
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
74
1.75k
                        uint32_t result, size_t input_rows_count) const override {
75
        // We need a local variable to hold a reference to the converted column.
76
        // So that the converted column will not be released before we use it.
77
1.75k
        ColumnPtr col[3];
78
1.75k
        bool col_const[3];
79
7.00k
        for (size_t i = 0; i < 3; ++i) {
80
5.25k
            std::tie(col[i], col_const[i]) =
81
5.25k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
82
5.25k
        }
83
84
1.75k
        const auto* col_origin_str = assert_cast<const ColumnString*>(col[0].get());
85
1.75k
        const auto* col_old_str = assert_cast<const ColumnString*>(col[1].get());
86
1.75k
        const auto* col_new_str = assert_cast<const ColumnString*>(col[2].get());
87
88
1.75k
        ColumnString::MutablePtr col_res = ColumnString::create();
89
90
1.75k
        std::visit(
91
1.75k
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
3.93k
                    for (int i = 0; i < input_rows_count; ++i) {
93
2.18k
                        StringRef origin_str =
94
2.18k
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
2.18k
                        StringRef old_str =
96
2.18k
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
2.18k
                        StringRef new_str =
98
2.18k
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
2.18k
                        std::string result =
101
2.18k
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
2.18k
                                        new_str.to_string_view());
103
104
2.18k
                        col_res->insert_data(result.data(), result.length());
105
2.18k
                    }
106
1.75k
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SI_EEDaSC_SD_SE_
Line
Count
Source
91
126
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
467
                    for (int i = 0; i < input_rows_count; ++i) {
93
341
                        StringRef origin_str =
94
341
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
341
                        StringRef old_str =
96
341
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
341
                        StringRef new_str =
98
341
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
341
                        std::string result =
101
341
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
341
                                        new_str.to_string_view());
103
104
341
                        col_res->insert_data(result.data(), result.length());
105
341
                    }
106
126
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SH_IbLb1EEEEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESI_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESJ_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESJ_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESI_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SH_IbLb0EEEEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
Unexecuted instantiation: _ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SI_EEDaSC_SD_SE_
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SI_EEDaSC_SD_SE_
Line
Count
Source
91
126
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
467
                    for (int i = 0; i < input_rows_count; ++i) {
93
341
                        StringRef origin_str =
94
341
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
341
                        StringRef old_str =
96
341
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
341
                        StringRef new_str =
98
341
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
341
                        std::string result =
101
341
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
341
                                        new_str.to_string_view());
103
104
341
                        col_res->insert_data(result.data(), result.length());
105
341
                    }
106
126
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SH_IbLb1EEEEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESI_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESJ_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESJ_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESI_EEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SH_IbLb0EEEEDaSC_SD_SE_
Line
Count
Source
91
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
250
                    for (int i = 0; i < input_rows_count; ++i) {
93
125
                        StringRef origin_str =
94
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
125
                        StringRef old_str =
96
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
125
                        StringRef new_str =
98
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
125
                        std::string result =
101
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
125
                                        new_str.to_string_view());
103
104
125
                        col_res->insert_data(result.data(), result.length());
105
125
                    }
106
125
                },
Unexecuted instantiation: _ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SI_EEDaSC_SD_SE_
107
1.75k
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
108
1.75k
                make_bool_variant(col_const[2]));
109
110
1.75k
        block.replace_by_position(result, std::move(col_res));
111
1.75k
        return Status::OK();
112
1.75k
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
74
876
                        uint32_t result, size_t input_rows_count) const override {
75
        // We need a local variable to hold a reference to the converted column.
76
        // So that the converted column will not be released before we use it.
77
876
        ColumnPtr col[3];
78
876
        bool col_const[3];
79
3.50k
        for (size_t i = 0; i < 3; ++i) {
80
2.62k
            std::tie(col[i], col_const[i]) =
81
2.62k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
82
2.62k
        }
83
84
876
        const auto* col_origin_str = assert_cast<const ColumnString*>(col[0].get());
85
876
        const auto* col_old_str = assert_cast<const ColumnString*>(col[1].get());
86
876
        const auto* col_new_str = assert_cast<const ColumnString*>(col[2].get());
87
88
876
        ColumnString::MutablePtr col_res = ColumnString::create();
89
90
876
        std::visit(
91
876
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
876
                    for (int i = 0; i < input_rows_count; ++i) {
93
876
                        StringRef origin_str =
94
876
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
876
                        StringRef old_str =
96
876
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
876
                        StringRef new_str =
98
876
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
876
                        std::string result =
101
876
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
876
                                        new_str.to_string_view());
103
104
876
                        col_res->insert_data(result.data(), result.length());
105
876
                    }
106
876
                },
107
876
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
108
876
                make_bool_variant(col_const[2]));
109
110
876
        block.replace_by_position(result, std::move(col_res));
111
876
        return Status::OK();
112
876
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
74
876
                        uint32_t result, size_t input_rows_count) const override {
75
        // We need a local variable to hold a reference to the converted column.
76
        // So that the converted column will not be released before we use it.
77
876
        ColumnPtr col[3];
78
876
        bool col_const[3];
79
3.50k
        for (size_t i = 0; i < 3; ++i) {
80
2.62k
            std::tie(col[i], col_const[i]) =
81
2.62k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
82
2.62k
        }
83
84
876
        const auto* col_origin_str = assert_cast<const ColumnString*>(col[0].get());
85
876
        const auto* col_old_str = assert_cast<const ColumnString*>(col[1].get());
86
876
        const auto* col_new_str = assert_cast<const ColumnString*>(col[2].get());
87
88
876
        ColumnString::MutablePtr col_res = ColumnString::create();
89
90
876
        std::visit(
91
876
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
92
876
                    for (int i = 0; i < input_rows_count; ++i) {
93
876
                        StringRef origin_str =
94
876
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
95
876
                        StringRef old_str =
96
876
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
97
876
                        StringRef new_str =
98
876
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
99
100
876
                        std::string result =
101
876
                                replace(origin_str.to_string(), old_str.to_string_view(),
102
876
                                        new_str.to_string_view());
103
104
876
                        col_res->insert_data(result.data(), result.length());
105
876
                    }
106
876
                },
107
876
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
108
876
                make_bool_variant(col_const[2]));
109
110
876
        block.replace_by_position(result, std::move(col_res));
111
876
        return Status::OK();
112
876
    }
113
114
private:
115
2.18k
    std::string replace(std::string str, std::string_view old_str, std::string_view new_str) const {
116
2.18k
        if (old_str.empty()) {
117
494
            if constexpr (empty) {
118
247
                return str;
119
247
            } else {
120
                // Different from "Replace" only when the search string is empty.
121
                // it will insert `new_str` in front of every character and at the end of the old str.
122
247
                if (new_str.empty()) {
123
59
                    return str;
124
59
                }
125
188
                if (simd::VStringFunctions::is_ascii({str.data(), str.size()})) {
126
188
                    std::string result;
127
188
                    ColumnString::check_chars_length(
128
188
                            str.length() * (new_str.length() + 1) + new_str.length(), 0);
129
188
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
130
648
                    for (char c : str) {
131
648
                        result += new_str;
132
648
                        result += c;
133
648
                    }
134
188
                    result += new_str;
135
188
                    return result;
136
188
                } else {
137
0
                    std::string result;
138
0
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
139
0
                    for (size_t i = 0, utf8_char_len = 0; i < str.size(); i += utf8_char_len) {
140
0
                        utf8_char_len = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
141
0
                        result += new_str;
142
0
                        result.append(&str[i], utf8_char_len);
143
0
                    }
144
0
                    result += new_str;
145
0
                    ColumnString::check_chars_length(result.size(), 0);
146
0
                    return result;
147
0
                }
148
188
            }
149
1.68k
        } else {
150
1.68k
            std::string::size_type pos = 0;
151
1.68k
            std::string::size_type oldLen = old_str.size();
152
1.68k
            std::string::size_type newLen = new_str.size();
153
2.34k
            while ((pos = str.find(old_str, pos)) != std::string::npos) {
154
656
                str.replace(pos, oldLen, new_str);
155
656
                pos += newLen;
156
656
            }
157
1.68k
            return str;
158
1.68k
        }
159
2.18k
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE7replaceENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt17basic_string_viewIcS6_ESA_
Line
Count
Source
115
1.09k
    std::string replace(std::string str, std::string_view old_str, std::string_view new_str) const {
116
1.09k
        if (old_str.empty()) {
117
247
            if constexpr (empty) {
118
247
                return str;
119
            } else {
120
                // Different from "Replace" only when the search string is empty.
121
                // it will insert `new_str` in front of every character and at the end of the old str.
122
                if (new_str.empty()) {
123
                    return str;
124
                }
125
                if (simd::VStringFunctions::is_ascii({str.data(), str.size()})) {
126
                    std::string result;
127
                    ColumnString::check_chars_length(
128
                            str.length() * (new_str.length() + 1) + new_str.length(), 0);
129
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
130
                    for (char c : str) {
131
                        result += new_str;
132
                        result += c;
133
                    }
134
                    result += new_str;
135
                    return result;
136
                } else {
137
                    std::string result;
138
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
139
                    for (size_t i = 0, utf8_char_len = 0; i < str.size(); i += utf8_char_len) {
140
                        utf8_char_len = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
141
                        result += new_str;
142
                        result.append(&str[i], utf8_char_len);
143
                    }
144
                    result += new_str;
145
                    ColumnString::check_chars_length(result.size(), 0);
146
                    return result;
147
                }
148
            }
149
844
        } else {
150
844
            std::string::size_type pos = 0;
151
844
            std::string::size_type oldLen = old_str.size();
152
844
            std::string::size_type newLen = new_str.size();
153
1.17k
            while ((pos = str.find(old_str, pos)) != std::string::npos) {
154
328
                str.replace(pos, oldLen, new_str);
155
328
                pos += newLen;
156
328
            }
157
844
            return str;
158
844
        }
159
1.09k
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE7replaceENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt17basic_string_viewIcS6_ESA_
Line
Count
Source
115
1.09k
    std::string replace(std::string str, std::string_view old_str, std::string_view new_str) const {
116
1.09k
        if (old_str.empty()) {
117
            if constexpr (empty) {
118
                return str;
119
247
            } else {
120
                // Different from "Replace" only when the search string is empty.
121
                // it will insert `new_str` in front of every character and at the end of the old str.
122
247
                if (new_str.empty()) {
123
59
                    return str;
124
59
                }
125
188
                if (simd::VStringFunctions::is_ascii({str.data(), str.size()})) {
126
188
                    std::string result;
127
188
                    ColumnString::check_chars_length(
128
188
                            str.length() * (new_str.length() + 1) + new_str.length(), 0);
129
188
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
130
648
                    for (char c : str) {
131
648
                        result += new_str;
132
648
                        result += c;
133
648
                    }
134
188
                    result += new_str;
135
188
                    return result;
136
188
                } else {
137
0
                    std::string result;
138
0
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
139
0
                    for (size_t i = 0, utf8_char_len = 0; i < str.size(); i += utf8_char_len) {
140
0
                        utf8_char_len = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
141
0
                        result += new_str;
142
0
                        result.append(&str[i], utf8_char_len);
143
0
                    }
144
0
                    result += new_str;
145
0
                    ColumnString::check_chars_length(result.size(), 0);
146
0
                    return result;
147
0
                }
148
188
            }
149
844
        } else {
150
844
            std::string::size_type pos = 0;
151
844
            std::string::size_type oldLen = old_str.size();
152
844
            std::string::size_type newLen = new_str.size();
153
1.17k
            while ((pos = str.find(old_str, pos)) != std::string::npos) {
154
328
                str.replace(pos, oldLen, new_str);
155
328
                pos += newLen;
156
328
            }
157
844
            return str;
158
844
        }
159
1.09k
    }
160
};
161
162
struct ReverseImpl {
163
    static Status vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets,
164
53
                         ColumnString::Chars& res_data, ColumnString::Offsets& res_offsets) {
165
53
        auto rows_count = offsets.size();
166
53
        res_offsets.resize(rows_count);
167
53
        res_data.reserve(data.size());
168
158
        for (ssize_t i = 0; i < rows_count; ++i) {
169
105
            auto src_str = reinterpret_cast<const char*>(&data[offsets[i - 1]]);
170
105
            int64_t src_len = offsets[i] - offsets[i - 1];
171
105
            std::string dst;
172
105
            dst.resize(src_len);
173
105
            simd::VStringFunctions::reverse(StringRef((uint8_t*)src_str, src_len), &dst);
174
105
            StringOP::push_value_string(std::string_view(dst.data(), src_len), i, res_data,
175
105
                                        res_offsets);
176
105
        }
177
53
        return Status::OK();
178
53
    }
179
};
180
181
template <typename Impl>
182
class FunctionSubReplace : public IFunction {
183
public:
184
    static constexpr auto name = "sub_replace";
185
186
4
    static FunctionPtr create() { return std::make_shared<FunctionSubReplace<Impl>>(); }
_ZN5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE6createEv
Line
Count
Source
186
2
    static FunctionPtr create() { return std::make_shared<FunctionSubReplace<Impl>>(); }
_ZN5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE6createEv
Line
Count
Source
186
2
    static FunctionPtr create() { return std::make_shared<FunctionSubReplace<Impl>>(); }
187
188
0
    String get_name() const override { return name; }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE8get_nameB5cxx11Ev
189
190
0
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
191
0
        return make_nullable(std::make_shared<DataTypeString>());
192
0
    }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
193
194
2
    bool is_variadic() const override { return true; }
_ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE11is_variadicEv
Line
Count
Source
194
1
    bool is_variadic() const override { return true; }
_ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE11is_variadicEv
Line
Count
Source
194
1
    bool is_variadic() const override { return true; }
195
196
2
    DataTypes get_variadic_argument_types_impl() const override {
197
2
        return Impl::get_variadic_argument_types();
198
2
    }
_ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE32get_variadic_argument_types_implEv
Line
Count
Source
196
1
    DataTypes get_variadic_argument_types_impl() const override {
197
1
        return Impl::get_variadic_argument_types();
198
1
    }
_ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE32get_variadic_argument_types_implEv
Line
Count
Source
196
1
    DataTypes get_variadic_argument_types_impl() const override {
197
1
        return Impl::get_variadic_argument_types();
198
1
    }
199
200
0
    size_t get_number_of_arguments() const override {
201
0
        return get_variadic_argument_types_impl().size();
202
0
    }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE23get_number_of_argumentsEv
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE23get_number_of_argumentsEv
203
204
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
205
0
                        uint32_t result, size_t input_rows_count) const override {
206
0
        return Impl::execute_impl(context, block, arguments, result, input_rows_count);
207
0
    }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
208
};
209
210
struct SubReplaceImpl {
211
    static Status replace_execute(Block& block, const ColumnNumbers& arguments, uint32_t result,
212
1
                                  size_t input_rows_count) {
213
1
        auto res_column = ColumnString::create();
214
1
        auto* result_column = assert_cast<ColumnString*>(res_column.get());
215
1
        auto args_null_map = ColumnUInt8::create(input_rows_count, 0);
216
1
        ColumnPtr argument_columns[4];
217
1
        bool col_const[4];
218
5
        for (int i = 0; i < 4; ++i) {
219
4
            std::tie(argument_columns[i], col_const[i]) =
220
4
                    unpack_if_const(block.get_by_position(arguments[i]).column);
221
4
        }
222
1
        const auto* data_column = assert_cast<const ColumnString*>(argument_columns[0].get());
223
1
        const auto* mask_column = assert_cast<const ColumnString*>(argument_columns[1].get());
224
1
        const auto* start_column = assert_cast<const ColumnInt32*>(argument_columns[2].get());
225
1
        const auto* length_column = assert_cast<const ColumnInt32*>(argument_columns[3].get());
226
227
1
        std::visit(
228
1
                [&](auto origin_str_const, auto new_str_const, auto start_const, auto len_const) {
229
1
                    if (data_column->is_ascii()) {
230
1
                        vector_ascii<origin_str_const, new_str_const, start_const, len_const>(
231
1
                                data_column, mask_column, start_column->get_data(),
232
1
                                length_column->get_data(), args_null_map->get_data(), result_column,
233
1
                                input_rows_count);
234
1
                    } else {
235
0
                        vector_utf8<origin_str_const, new_str_const, start_const, len_const>(
236
0
                                data_column, mask_column, start_column->get_data(),
237
0
                                length_column->get_data(), args_null_map->get_data(), result_column,
238
0
                                input_rows_count);
239
0
                    }
240
1
                },
_ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESF_SF_SF_EEDaS8_S9_SA_SB_
Line
Count
Source
228
1
                [&](auto origin_str_const, auto new_str_const, auto start_const, auto len_const) {
229
1
                    if (data_column->is_ascii()) {
230
1
                        vector_ascii<origin_str_const, new_str_const, start_const, len_const>(
231
1
                                data_column, mask_column, start_column->get_data(),
232
1
                                length_column->get_data(), args_null_map->get_data(), result_column,
233
1
                                input_rows_count);
234
1
                    } else {
235
0
                        vector_utf8<origin_str_const, new_str_const, start_const, len_const>(
236
0
                                data_column, mask_column, start_column->get_data(),
237
0
                                length_column->get_data(), args_null_map->get_data(), result_column,
238
0
                                input_rows_count);
239
0
                    }
240
1
                },
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESF_SF_SE_IbLb1EEEEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESF_SE_IbLb1EESF_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESF_SE_IbLb1EESG_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESE_IbLb1EESF_SF_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESE_IbLb1EESF_SG_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESE_IbLb1EESG_SF_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESE_IbLb1EESG_SG_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESE_IbLb0EESG_SG_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESE_IbLb0EESG_SF_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESE_IbLb0EESF_SG_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESE_IbLb0EESF_SF_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESF_SE_IbLb0EESG_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESF_SE_IbLb0EESF_EEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESF_SF_SE_IbLb0EEEEDaS8_S9_SA_SB_
Unexecuted instantiation: _ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESF_SF_SF_EEDaS8_S9_SA_SB_
241
1
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
242
1
                make_bool_variant(col_const[2]), make_bool_variant(col_const[3]));
243
1
        block.get_by_position(result).column =
244
1
                ColumnNullable::create(std::move(res_column), std::move(args_null_map));
245
1
        return Status::OK();
246
1
    }
247
248
private:
249
    template <bool origin_str_const, bool new_str_const, bool start_const, bool len_const>
250
    static void vector_ascii(const ColumnString* data_column, const ColumnString* mask_column,
251
                             const PaddedPODArray<Int32>& args_start,
252
                             const PaddedPODArray<Int32>& args_length, NullMap& args_null_map,
253
1
                             ColumnString* result_column, size_t input_rows_count) {
254
1
        ColumnString::Chars& res_chars = result_column->get_chars();
255
1
        ColumnString::Offsets& res_offsets = result_column->get_offsets();
256
10.2k
        for (size_t row = 0; row < input_rows_count; ++row) {
257
10.2k
            StringRef origin_str =
258
10.2k
                    data_column->get_data_at(index_check_const<origin_str_const>(row));
259
10.2k
            StringRef new_str = mask_column->get_data_at(index_check_const<new_str_const>(row));
260
10.2k
            const auto start = args_start[index_check_const<start_const>(row)];
261
10.2k
            const auto length = args_length[index_check_const<len_const>(row)];
262
10.2k
            const size_t origin_str_len = origin_str.size;
263
            //input is null, start < 0, len < 0, str_size <= start. return NULL
264
10.2k
            if (args_null_map[row] || start < 0 || length < 0 || origin_str_len <= start) {
265
10.2k
                res_offsets.push_back(res_chars.size());
266
10.2k
                args_null_map[row] = 1;
267
10.2k
            } else {
268
0
                std::string_view replace_str = new_str.to_string_view();
269
0
                std::string result = origin_str.to_string();
270
0
                result.replace(start, length, replace_str);
271
0
                result_column->insert_data(result.data(), result.length());
272
0
            }
273
10.2k
        }
274
1
    }
_ZN5doris14SubReplaceImpl12vector_asciiILb0ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Line
Count
Source
253
1
                             ColumnString* result_column, size_t input_rows_count) {
254
1
        ColumnString::Chars& res_chars = result_column->get_chars();
255
1
        ColumnString::Offsets& res_offsets = result_column->get_offsets();
256
10.2k
        for (size_t row = 0; row < input_rows_count; ++row) {
257
10.2k
            StringRef origin_str =
258
10.2k
                    data_column->get_data_at(index_check_const<origin_str_const>(row));
259
10.2k
            StringRef new_str = mask_column->get_data_at(index_check_const<new_str_const>(row));
260
10.2k
            const auto start = args_start[index_check_const<start_const>(row)];
261
10.2k
            const auto length = args_length[index_check_const<len_const>(row)];
262
10.2k
            const size_t origin_str_len = origin_str.size;
263
            //input is null, start < 0, len < 0, str_size <= start. return NULL
264
10.2k
            if (args_null_map[row] || start < 0 || length < 0 || origin_str_len <= start) {
265
10.2k
                res_offsets.push_back(res_chars.size());
266
10.2k
                args_null_map[row] = 1;
267
10.2k
            } else {
268
0
                std::string_view replace_str = new_str.to_string_view();
269
0
                std::string result = origin_str.to_string();
270
0
                result.replace(start, length, replace_str);
271
0
                result_column->insert_data(result.data(), result.length());
272
0
            }
273
10.2k
        }
274
1
    }
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb0ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl12vector_asciiILb1ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
275
276
    template <bool origin_str_const, bool new_str_const, bool start_const, bool len_const>
277
    static void vector_utf8(const ColumnString* data_column, const ColumnString* mask_column,
278
                            const PaddedPODArray<Int32>& args_start,
279
                            const PaddedPODArray<Int32>& args_length, NullMap& args_null_map,
280
0
                            ColumnString* result_column, size_t input_rows_count) {
281
0
        ColumnString::Chars& res_chars = result_column->get_chars();
282
0
        ColumnString::Offsets& res_offsets = result_column->get_offsets();
283
284
0
        for (size_t row = 0; row < input_rows_count; ++row) {
285
0
            StringRef origin_str =
286
0
                    data_column->get_data_at(index_check_const<origin_str_const>(row));
287
0
            StringRef new_str = mask_column->get_data_at(index_check_const<new_str_const>(row));
288
0
            const auto start = args_start[index_check_const<start_const>(row)];
289
0
            const auto length = args_length[index_check_const<len_const>(row)];
290
            //input is null, start < 0, len < 0 return NULL
291
0
            if (args_null_map[row] || start < 0 || length < 0) {
292
0
                res_offsets.push_back(res_chars.size());
293
0
                args_null_map[row] = 1;
294
0
                continue;
295
0
            }
296
297
0
            const auto [start_byte_len, start_char_len] =
298
0
                    simd::VStringFunctions::iterate_utf8_with_limit_length(origin_str.begin(),
299
0
                                                                           origin_str.end(), start);
300
301
            // start >= orgin.size
302
0
            DCHECK(start_char_len <= start);
303
0
            if (start_byte_len == origin_str.size) {
304
0
                res_offsets.push_back(res_chars.size());
305
0
                args_null_map[row] = 1;
306
0
                continue;
307
0
            }
308
309
0
            auto [end_byte_len, end_char_len] =
310
0
                    simd::VStringFunctions::iterate_utf8_with_limit_length(
311
0
                            origin_str.begin() + start_byte_len, origin_str.end(), length);
312
0
            DCHECK(end_char_len <= length);
313
0
            std::string_view replace_str = new_str.to_string_view();
314
0
            std::string result = origin_str.to_string();
315
0
            result.replace(start_byte_len, end_byte_len, replace_str);
316
0
            result_column->insert_data(result.data(), result.length());
317
0
        }
318
0
    }
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb0ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Unexecuted instantiation: _ZN5doris14SubReplaceImpl11vector_utf8ILb1ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
319
};
320
321
struct SubReplaceThreeImpl {
322
1
    static DataTypes get_variadic_argument_types() {
323
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
324
1
                std::make_shared<DataTypeInt32>()};
325
1
    }
326
327
    static Status execute_impl(FunctionContext* context, Block& block,
328
                               const ColumnNumbers& arguments, uint32_t result,
329
0
                               size_t input_rows_count) {
330
0
        auto params = ColumnInt32::create(input_rows_count);
331
0
        auto& strlen_data = params->get_data();
332
333
0
        auto str_col =
334
0
                block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
335
0
        if (const auto* nullable = check_and_get_column<const ColumnNullable>(*str_col)) {
336
0
            str_col = nullable->get_nested_column_ptr();
337
0
        }
338
0
        const auto* str_column = assert_cast<const ColumnString*>(str_col.get());
339
        // use utf8 len
340
0
        for (int i = 0; i < input_rows_count; ++i) {
341
0
            StringRef str_ref = str_column->get_data_at(i);
342
0
            strlen_data[i] = simd::VStringFunctions::get_char_len(str_ref.data, str_ref.size);
343
0
        }
344
345
0
        block.insert({std::move(params), std::make_shared<DataTypeInt32>(), "strlen"});
346
0
        ColumnNumbers temp_arguments = {arguments[0], arguments[1], arguments[2],
347
0
                                        block.columns() - 1};
348
0
        return SubReplaceImpl::replace_execute(block, temp_arguments, result, input_rows_count);
349
0
    }
350
};
351
352
struct SubReplaceFourImpl {
353
1
    static DataTypes get_variadic_argument_types() {
354
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
355
1
                std::make_shared<DataTypeInt32>(), std::make_shared<DataTypeInt32>()};
356
1
    }
357
358
    static Status execute_impl(FunctionContext* context, Block& block,
359
                               const ColumnNumbers& arguments, uint32_t result,
360
0
                               size_t input_rows_count) {
361
0
        return SubReplaceImpl::replace_execute(block, arguments, result, input_rows_count);
362
0
    }
363
};
364
365
class FunctionOverlay : public IFunction {
366
public:
367
    static constexpr auto name = "overlay";
368
19
    static FunctionPtr create() { return std::make_shared<FunctionOverlay>(); }
369
1
    String get_name() const override { return name; }
370
17
    size_t get_number_of_arguments() const override { return 4; }
371
372
17
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
373
17
        return std::make_shared<DataTypeString>();
374
17
    }
375
376
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
377
13
                        uint32_t result, size_t input_rows_count) const override {
378
13
        DCHECK_EQ(arguments.size(), 4);
379
380
13
        bool col_const[4];
381
13
        ColumnPtr argument_columns[4];
382
65
        for (int i = 0; i < 4; ++i) {
383
52
            std::tie(argument_columns[i], col_const[i]) =
384
52
                    unpack_if_const(block.get_by_position(arguments[i]).column);
385
52
        }
386
387
13
        const auto* col_origin = assert_cast<const ColumnString*>(argument_columns[0].get());
388
389
13
        const auto* col_pos =
390
13
                assert_cast<const ColumnInt32*>(argument_columns[1].get())->get_data().data();
391
13
        const auto* col_len =
392
13
                assert_cast<const ColumnInt32*>(argument_columns[2].get())->get_data().data();
393
13
        const auto* col_insert = assert_cast<const ColumnString*>(argument_columns[3].get());
394
395
13
        ColumnString::MutablePtr col_res = ColumnString::create();
396
397
        // if all input string is ascii, we can use ascii function to handle it
398
13
        const bool is_all_ascii = col_origin->is_ascii() && col_insert->is_ascii();
399
13
        std::visit(
400
13
                [&](auto origin_const, auto pos_const, auto len_const, auto insert_const) {
401
13
                    if (is_all_ascii) {
402
6
                        vector_ascii<origin_const, pos_const, len_const, insert_const>(
403
6
                                col_origin, col_pos, col_len, col_insert, col_res,
404
6
                                input_rows_count);
405
7
                    } else {
406
7
                        vector_utf8<origin_const, pos_const, len_const, insert_const>(
407
7
                                col_origin, col_pos, col_len, col_insert, col_res,
408
7
                                input_rows_count);
409
7
                    }
410
13
                },
_ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESH_SH_SH_EEDaSA_SB_SC_SD_
Line
Count
Source
400
1
                [&](auto origin_const, auto pos_const, auto len_const, auto insert_const) {
401
1
                    if (is_all_ascii) {
402
0
                        vector_ascii<origin_const, pos_const, len_const, insert_const>(
403
0
                                col_origin, col_pos, col_len, col_insert, col_res,
404
0
                                input_rows_count);
405
1
                    } else {
406
1
                        vector_utf8<origin_const, pos_const, len_const, insert_const>(
407
1
                                col_origin, col_pos, col_len, col_insert, col_res,
408
1
                                input_rows_count);
409
1
                    }
410
1
                },
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESH_SH_SH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESH_SH_SG_IbLb0EEEEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESH_SG_IbLb0EESH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESH_SG_IbLb0EESI_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESG_IbLb0EESH_SH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESG_IbLb0EESH_SI_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESG_IbLb0EESI_SH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb1EESG_IbLb0EESI_SI_EEDaSA_SB_SC_SD_
_ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESG_IbLb1EESI_SI_EEDaSA_SB_SC_SD_
Line
Count
Source
400
12
                [&](auto origin_const, auto pos_const, auto len_const, auto insert_const) {
401
12
                    if (is_all_ascii) {
402
6
                        vector_ascii<origin_const, pos_const, len_const, insert_const>(
403
6
                                col_origin, col_pos, col_len, col_insert, col_res,
404
6
                                input_rows_count);
405
6
                    } else {
406
6
                        vector_utf8<origin_const, pos_const, len_const, insert_const>(
407
6
                                col_origin, col_pos, col_len, col_insert, col_res,
408
6
                                input_rows_count);
409
6
                    }
410
12
                },
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESG_IbLb1EESI_SH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESG_IbLb1EESH_SI_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESG_IbLb1EESH_SH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESH_SG_IbLb1EESI_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESH_SG_IbLb1EESH_EEDaSA_SB_SC_SD_
Unexecuted instantiation: _ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESH_SH_SG_IbLb1EEEEDaSA_SB_SC_SD_
411
13
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
412
13
                make_bool_variant(col_const[2]), make_bool_variant(col_const[3]));
413
13
        block.replace_by_position(result, std::move(col_res));
414
13
        return Status::OK();
415
13
    }
416
417
private:
418
    template <bool origin_const, bool pos_const, bool len_const, bool insert_const>
419
    static void vector_ascii(const ColumnString* col_origin, int const* col_pos, int const* col_len,
420
                             const ColumnString* col_insert, ColumnString::MutablePtr& col_res,
421
6
                             size_t input_rows_count) {
422
6
        auto& col_res_chars = col_res->get_chars();
423
6
        auto& col_res_offsets = col_res->get_offsets();
424
6
        StringRef origin_str, insert_str;
425
12
        for (size_t i = 0; i < input_rows_count; i++) {
426
6
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
427
            // pos is 1-based index,so we need to minus 1
428
6
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
429
6
            const auto len = col_len[index_check_const<len_const>(i)];
430
6
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
431
6
            const auto origin_size = origin_str.size;
432
6
            if (pos >= origin_size || pos < 0) {
433
                // If pos is not within the length of the string, the original string is returned.
434
3
                col_res->insert_data(origin_str.data, origin_str.size);
435
3
                continue;
436
3
            }
437
3
            col_res_chars.insert(origin_str.data,
438
3
                                 origin_str.data + pos); // copy origin_str with index 0 to pos - 1
439
3
            if (pos + len > origin_size || len < 0) {
440
1
                col_res_chars.insert(insert_str.begin(),
441
1
                                     insert_str.end()); // copy all of insert_str.
442
2
            } else {
443
2
                col_res_chars.insert(insert_str.begin(),
444
2
                                     insert_str.end()); // copy all of insert_str.
445
2
                col_res_chars.insert(
446
2
                        origin_str.data + pos + len,
447
2
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
448
2
            }
449
3
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
450
3
            col_res_offsets.push_back(col_res_chars.size());
451
3
        }
452
6
    }
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb1ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
_ZN5doris15FunctionOverlay12vector_asciiILb0ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Line
Count
Source
421
6
                             size_t input_rows_count) {
422
6
        auto& col_res_chars = col_res->get_chars();
423
6
        auto& col_res_offsets = col_res->get_offsets();
424
6
        StringRef origin_str, insert_str;
425
12
        for (size_t i = 0; i < input_rows_count; i++) {
426
6
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
427
            // pos is 1-based index,so we need to minus 1
428
6
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
429
6
            const auto len = col_len[index_check_const<len_const>(i)];
430
6
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
431
6
            const auto origin_size = origin_str.size;
432
6
            if (pos >= origin_size || pos < 0) {
433
                // If pos is not within the length of the string, the original string is returned.
434
3
                col_res->insert_data(origin_str.data, origin_str.size);
435
3
                continue;
436
3
            }
437
3
            col_res_chars.insert(origin_str.data,
438
3
                                 origin_str.data + pos); // copy origin_str with index 0 to pos - 1
439
3
            if (pos + len > origin_size || len < 0) {
440
1
                col_res_chars.insert(insert_str.begin(),
441
1
                                     insert_str.end()); // copy all of insert_str.
442
2
            } else {
443
2
                col_res_chars.insert(insert_str.begin(),
444
2
                                     insert_str.end()); // copy all of insert_str.
445
2
                col_res_chars.insert(
446
2
                        origin_str.data + pos + len,
447
2
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
448
2
            }
449
3
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
450
3
            col_res_offsets.push_back(col_res_chars.size());
451
3
        }
452
6
    }
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay12vector_asciiILb0ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
453
454
    template <bool origin_const, bool pos_const, bool len_const, bool insert_const>
455
    NO_SANITIZE_UNDEFINED static void vector_utf8(const ColumnString* col_origin,
456
                                                  int const* col_pos, int const* col_len,
457
                                                  const ColumnString* col_insert,
458
                                                  ColumnString::MutablePtr& col_res,
459
7
                                                  size_t input_rows_count) {
460
7
        auto& col_res_chars = col_res->get_chars();
461
7
        auto& col_res_offsets = col_res->get_offsets();
462
7
        StringRef origin_str, insert_str;
463
        // utf8_origin_offsets is used to store the offset of each utf8 character in the original string.
464
        // for example, if the original string is "丝多a睿", utf8_origin_offsets will be {0, 3, 6, 7}.
465
7
        std::vector<size_t> utf8_origin_offsets;
466
29
        for (size_t i = 0; i < input_rows_count; i++) {
467
22
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
468
            // pos is 1-based index,so we need to minus 1
469
22
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
470
22
            const auto len = col_len[index_check_const<len_const>(i)];
471
22
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
472
22
            utf8_origin_offsets.clear();
473
474
160
            for (size_t ni = 0, char_size = 0; ni < origin_str.size; ni += char_size) {
475
138
                utf8_origin_offsets.push_back(ni);
476
138
                char_size = get_utf8_byte_length(origin_str.data[ni]);
477
138
            }
478
479
22
            const size_t utf8_origin_size = utf8_origin_offsets.size();
480
481
22
            if (pos >= utf8_origin_size || pos < 0) {
482
                // If pos is not within the length of the string, the original string is returned.
483
13
                col_res->insert_data(origin_str.data, origin_str.size);
484
13
                continue;
485
13
            }
486
9
            col_res_chars.insert(
487
9
                    origin_str.data,
488
9
                    origin_str.data +
489
9
                            utf8_origin_offsets[pos]); // copy origin_str with index 0 to pos - 1
490
9
            if (pos + len >= utf8_origin_size || len < 0) {
491
4
                col_res_chars.insert(insert_str.begin(),
492
4
                                     insert_str.end()); // copy all of insert_str.
493
5
            } else {
494
5
                col_res_chars.insert(insert_str.begin(),
495
5
                                     insert_str.end()); // copy all of insert_str.
496
5
                col_res_chars.insert(
497
5
                        origin_str.data + utf8_origin_offsets[pos + len],
498
5
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
499
5
            }
500
9
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
501
9
            col_res_offsets.push_back(col_res_chars.size());
502
9
        }
503
7
    }
_ZN5doris15FunctionOverlay11vector_utf8ILb0ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Line
Count
Source
459
1
                                                  size_t input_rows_count) {
460
1
        auto& col_res_chars = col_res->get_chars();
461
1
        auto& col_res_offsets = col_res->get_offsets();
462
1
        StringRef origin_str, insert_str;
463
        // utf8_origin_offsets is used to store the offset of each utf8 character in the original string.
464
        // for example, if the original string is "丝多a睿", utf8_origin_offsets will be {0, 3, 6, 7}.
465
1
        std::vector<size_t> utf8_origin_offsets;
466
17
        for (size_t i = 0; i < input_rows_count; i++) {
467
16
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
468
            // pos is 1-based index,so we need to minus 1
469
16
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
470
16
            const auto len = col_len[index_check_const<len_const>(i)];
471
16
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
472
16
            utf8_origin_offsets.clear();
473
474
116
            for (size_t ni = 0, char_size = 0; ni < origin_str.size; ni += char_size) {
475
100
                utf8_origin_offsets.push_back(ni);
476
100
                char_size = get_utf8_byte_length(origin_str.data[ni]);
477
100
            }
478
479
16
            const size_t utf8_origin_size = utf8_origin_offsets.size();
480
481
16
            if (pos >= utf8_origin_size || pos < 0) {
482
                // If pos is not within the length of the string, the original string is returned.
483
10
                col_res->insert_data(origin_str.data, origin_str.size);
484
10
                continue;
485
10
            }
486
6
            col_res_chars.insert(
487
6
                    origin_str.data,
488
6
                    origin_str.data +
489
6
                            utf8_origin_offsets[pos]); // copy origin_str with index 0 to pos - 1
490
6
            if (pos + len >= utf8_origin_size || len < 0) {
491
3
                col_res_chars.insert(insert_str.begin(),
492
3
                                     insert_str.end()); // copy all of insert_str.
493
3
            } else {
494
3
                col_res_chars.insert(insert_str.begin(),
495
3
                                     insert_str.end()); // copy all of insert_str.
496
3
                col_res_chars.insert(
497
3
                        origin_str.data + utf8_origin_offsets[pos + len],
498
3
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
499
3
            }
500
6
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
501
6
            col_res_offsets.push_back(col_res_chars.size());
502
6
        }
503
1
    }
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb1ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
_ZN5doris15FunctionOverlay11vector_utf8ILb0ELb1ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Line
Count
Source
459
6
                                                  size_t input_rows_count) {
460
6
        auto& col_res_chars = col_res->get_chars();
461
6
        auto& col_res_offsets = col_res->get_offsets();
462
6
        StringRef origin_str, insert_str;
463
        // utf8_origin_offsets is used to store the offset of each utf8 character in the original string.
464
        // for example, if the original string is "丝多a睿", utf8_origin_offsets will be {0, 3, 6, 7}.
465
6
        std::vector<size_t> utf8_origin_offsets;
466
12
        for (size_t i = 0; i < input_rows_count; i++) {
467
6
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
468
            // pos is 1-based index,so we need to minus 1
469
6
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
470
6
            const auto len = col_len[index_check_const<len_const>(i)];
471
6
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
472
6
            utf8_origin_offsets.clear();
473
474
44
            for (size_t ni = 0, char_size = 0; ni < origin_str.size; ni += char_size) {
475
38
                utf8_origin_offsets.push_back(ni);
476
38
                char_size = get_utf8_byte_length(origin_str.data[ni]);
477
38
            }
478
479
6
            const size_t utf8_origin_size = utf8_origin_offsets.size();
480
481
6
            if (pos >= utf8_origin_size || pos < 0) {
482
                // If pos is not within the length of the string, the original string is returned.
483
3
                col_res->insert_data(origin_str.data, origin_str.size);
484
3
                continue;
485
3
            }
486
3
            col_res_chars.insert(
487
3
                    origin_str.data,
488
3
                    origin_str.data +
489
3
                            utf8_origin_offsets[pos]); // copy origin_str with index 0 to pos - 1
490
3
            if (pos + len >= utf8_origin_size || len < 0) {
491
1
                col_res_chars.insert(insert_str.begin(),
492
1
                                     insert_str.end()); // copy all of insert_str.
493
2
            } else {
494
2
                col_res_chars.insert(insert_str.begin(),
495
2
                                     insert_str.end()); // copy all of insert_str.
496
2
                col_res_chars.insert(
497
2
                        origin_str.data + utf8_origin_offsets[pos + len],
498
2
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
499
2
            }
500
3
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
501
3
            col_res_offsets.push_back(col_res_chars.size());
502
3
        }
503
6
    }
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb0ELb1ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb0ELb1ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb0ELb1ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb0ELb0ELb1ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb0ELb0ELb1ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Unexecuted instantiation: _ZN5doris15FunctionOverlay11vector_utf8ILb0ELb0ELb0ELb1EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
504
};
505
506
#include "common/compile_check_avoid_end.h"
507
} // namespace doris