Coverage Report

Created: 2026-04-22 18:57

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/string_searcher.h"
39
#include "exec/common/stringop_substring.h"
40
#include "exec/common/template_helpers.hpp"
41
#include "exprs/function/function.h"
42
#include "exprs/function/function_helpers.h"
43
#include "exprs/function_context.h"
44
#include "util/simd/vstring_function.h"
45
46
namespace doris {
47
#include "common/compile_check_avoid_begin.h"
48
49
struct ReplaceImpl {
50
    static constexpr auto name = "replace";
51
};
52
53
struct ReplaceEmptyImpl {
54
    static constexpr auto name = "replace_empty";
55
};
56
57
template <typename Impl, bool empty>
58
class FunctionReplace : public IFunction {
59
public:
60
    static constexpr auto name = Impl::name;
61
3.03k
    static FunctionPtr create() { return std::make_shared<FunctionReplace<Impl, empty>>(); }
_ZN5doris15FunctionReplaceINS_11ReplaceImplELb1EE6createEv
Line
Count
Source
61
1.51k
    static FunctionPtr create() { return std::make_shared<FunctionReplace<Impl, empty>>(); }
_ZN5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE6createEv
Line
Count
Source
61
1.51k
    static FunctionPtr create() { return std::make_shared<FunctionReplace<Impl, empty>>(); }
62
2
    String get_name() const override { return name; }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE8get_nameB5cxx11Ev
Line
Count
Source
62
1
    String get_name() const override { return name; }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE8get_nameB5cxx11Ev
Line
Count
Source
62
1
    String get_name() const override { return name; }
63
3.02k
    size_t get_number_of_arguments() const override { return 3; }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE23get_number_of_argumentsEv
Line
Count
Source
63
1.51k
    size_t get_number_of_arguments() const override { return 3; }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE23get_number_of_argumentsEv
Line
Count
Source
63
1.51k
    size_t get_number_of_arguments() const override { return 3; }
64
65
3.02k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
66
3.02k
        return std::make_shared<DataTypeString>();
67
3.02k
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
65
1.51k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
66
1.51k
        return std::make_shared<DataTypeString>();
67
1.51k
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
65
1.51k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
66
1.51k
        return std::make_shared<DataTypeString>();
67
1.51k
    }
68
69
2
    DataTypes get_variadic_argument_types_impl() const override {
70
2
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
71
2
                std::make_shared<DataTypeString>()};
72
2
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE32get_variadic_argument_types_implEv
Line
Count
Source
69
1
    DataTypes get_variadic_argument_types_impl() const override {
70
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
71
1
                std::make_shared<DataTypeString>()};
72
1
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE32get_variadic_argument_types_implEv
Line
Count
Source
69
1
    DataTypes get_variadic_argument_types_impl() const override {
70
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
71
1
                std::make_shared<DataTypeString>()};
72
1
    }
73
74
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
75
1.75k
                        uint32_t result, size_t input_rows_count) const override {
76
        // We need a local variable to hold a reference to the converted column.
77
        // So that the converted column will not be released before we use it.
78
1.75k
        ColumnPtr col[3];
79
1.75k
        bool col_const[3];
80
7.00k
        for (size_t i = 0; i < 3; ++i) {
81
5.25k
            std::tie(col[i], col_const[i]) =
82
5.25k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
83
5.25k
        }
84
85
1.75k
        const auto* col_origin_str = assert_cast<const ColumnString*>(col[0].get());
86
1.75k
        const auto* col_old_str = assert_cast<const ColumnString*>(col[1].get());
87
1.75k
        const auto* col_new_str = assert_cast<const ColumnString*>(col[2].get());
88
89
1.75k
        ColumnString::MutablePtr col_res = ColumnString::create();
90
91
        // Fast path: when old_str and new_str are both constant and old_str is
92
        // non-empty (the common case for replace(col, 'literal', 'literal')).
93
        // Works directly on ColumnString chars/offsets to avoid per-row
94
        // std::string allocation and copy overhead.
95
        // Applies to both replace (empty=true) and replace_empty (empty=false):
96
        // when old_str is non-empty the two variants behave identically.
97
1.75k
        if (col_const[1] && col_const[2]) {
98
250
            StringRef old_ref = col_old_str->get_data_at(0);
99
250
            StringRef new_ref = col_new_str->get_data_at(0);
100
250
            if (old_ref.size > 0) {
101
200
                _replace_const_pattern(*col_origin_str, old_ref, new_ref, *col_res,
102
200
                                       input_rows_count, col_const[0]);
103
200
                block.replace_by_position(result, std::move(col_res));
104
200
                return Status::OK();
105
200
            }
106
250
        }
107
108
1.55k
        std::visit(
109
1.55k
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
3.53k
                    for (int i = 0; i < input_rows_count; ++i) {
111
1.98k
                        StringRef origin_str =
112
1.98k
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
1.98k
                        StringRef old_str =
114
1.98k
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
1.98k
                        StringRef new_str =
116
1.98k
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
1.98k
                        std::string result =
119
1.98k
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
1.98k
                                        new_str.to_string_view());
121
122
1.98k
                        col_res->insert_data(result.data(), result.length());
123
1.98k
                    }
124
1.55k
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SI_EEDaSC_SD_SE_
Line
Count
Source
109
126
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
467
                    for (int i = 0; i < input_rows_count; ++i) {
111
341
                        StringRef origin_str =
112
341
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
341
                        StringRef old_str =
114
341
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
341
                        StringRef new_str =
116
341
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
341
                        std::string result =
119
341
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
341
                                        new_str.to_string_view());
121
122
341
                        col_res->insert_data(result.data(), result.length());
123
341
                    }
124
126
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SH_IbLb1EEEEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESI_EEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESJ_EEDaSC_SD_SE_
Line
Count
Source
109
25
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
50
                    for (int i = 0; i < input_rows_count; ++i) {
111
25
                        StringRef origin_str =
112
25
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
25
                        StringRef old_str =
114
25
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
25
                        StringRef new_str =
116
25
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
25
                        std::string result =
119
25
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
25
                                        new_str.to_string_view());
121
122
25
                        col_res->insert_data(result.data(), result.length());
123
25
                    }
124
25
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESJ_EEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESI_EEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SH_IbLb0EEEEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
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
109
126
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
467
                    for (int i = 0; i < input_rows_count; ++i) {
111
341
                        StringRef origin_str =
112
341
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
341
                        StringRef old_str =
114
341
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
341
                        StringRef new_str =
116
341
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
341
                        std::string result =
119
341
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
341
                                        new_str.to_string_view());
121
122
341
                        col_res->insert_data(result.data(), result.length());
123
341
                    }
124
126
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESI_SH_IbLb1EEEEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESI_EEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESH_IbLb1EESJ_EEDaSC_SD_SE_
Line
Count
Source
109
25
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
50
                    for (int i = 0; i < input_rows_count; ++i) {
111
25
                        StringRef origin_str =
112
25
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
25
                        StringRef old_str =
114
25
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
25
                        StringRef new_str =
116
25
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
25
                        std::string result =
119
25
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
25
                                        new_str.to_string_view());
121
122
25
                        col_res->insert_data(result.data(), result.length());
123
25
                    }
124
25
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESJ_EEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESH_IbLb0EESI_EEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
_ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SH_IbLb0EEEEDaSC_SD_SE_
Line
Count
Source
109
125
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
250
                    for (int i = 0; i < input_rows_count; ++i) {
111
125
                        StringRef origin_str =
112
125
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
125
                        StringRef old_str =
114
125
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
125
                        StringRef new_str =
116
125
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
125
                        std::string result =
119
125
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
125
                                        new_str.to_string_view());
121
122
125
                        col_res->insert_data(result.data(), result.length());
123
125
                    }
124
125
                },
Unexecuted instantiation: _ZZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESI_SI_EEDaSC_SD_SE_
125
1.55k
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
126
1.55k
                make_bool_variant(col_const[2]));
127
128
1.55k
        block.replace_by_position(result, std::move(col_res));
129
1.55k
        return Status::OK();
130
1.75k
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
75
876
                        uint32_t result, size_t input_rows_count) const override {
76
        // We need a local variable to hold a reference to the converted column.
77
        // So that the converted column will not be released before we use it.
78
876
        ColumnPtr col[3];
79
876
        bool col_const[3];
80
3.50k
        for (size_t i = 0; i < 3; ++i) {
81
2.62k
            std::tie(col[i], col_const[i]) =
82
2.62k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
83
2.62k
        }
84
85
876
        const auto* col_origin_str = assert_cast<const ColumnString*>(col[0].get());
86
876
        const auto* col_old_str = assert_cast<const ColumnString*>(col[1].get());
87
876
        const auto* col_new_str = assert_cast<const ColumnString*>(col[2].get());
88
89
876
        ColumnString::MutablePtr col_res = ColumnString::create();
90
91
        // Fast path: when old_str and new_str are both constant and old_str is
92
        // non-empty (the common case for replace(col, 'literal', 'literal')).
93
        // Works directly on ColumnString chars/offsets to avoid per-row
94
        // std::string allocation and copy overhead.
95
        // Applies to both replace (empty=true) and replace_empty (empty=false):
96
        // when old_str is non-empty the two variants behave identically.
97
876
        if (col_const[1] && col_const[2]) {
98
125
            StringRef old_ref = col_old_str->get_data_at(0);
99
125
            StringRef new_ref = col_new_str->get_data_at(0);
100
125
            if (old_ref.size > 0) {
101
100
                _replace_const_pattern(*col_origin_str, old_ref, new_ref, *col_res,
102
100
                                       input_rows_count, col_const[0]);
103
100
                block.replace_by_position(result, std::move(col_res));
104
100
                return Status::OK();
105
100
            }
106
125
        }
107
108
776
        std::visit(
109
776
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
776
                    for (int i = 0; i < input_rows_count; ++i) {
111
776
                        StringRef origin_str =
112
776
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
776
                        StringRef old_str =
114
776
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
776
                        StringRef new_str =
116
776
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
776
                        std::string result =
119
776
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
776
                                        new_str.to_string_view());
121
122
776
                        col_res->insert_data(result.data(), result.length());
123
776
                    }
124
776
                },
125
776
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
126
776
                make_bool_variant(col_const[2]));
127
128
776
        block.replace_by_position(result, std::move(col_res));
129
776
        return Status::OK();
130
876
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
75
876
                        uint32_t result, size_t input_rows_count) const override {
76
        // We need a local variable to hold a reference to the converted column.
77
        // So that the converted column will not be released before we use it.
78
876
        ColumnPtr col[3];
79
876
        bool col_const[3];
80
3.50k
        for (size_t i = 0; i < 3; ++i) {
81
2.62k
            std::tie(col[i], col_const[i]) =
82
2.62k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
83
2.62k
        }
84
85
876
        const auto* col_origin_str = assert_cast<const ColumnString*>(col[0].get());
86
876
        const auto* col_old_str = assert_cast<const ColumnString*>(col[1].get());
87
876
        const auto* col_new_str = assert_cast<const ColumnString*>(col[2].get());
88
89
876
        ColumnString::MutablePtr col_res = ColumnString::create();
90
91
        // Fast path: when old_str and new_str are both constant and old_str is
92
        // non-empty (the common case for replace(col, 'literal', 'literal')).
93
        // Works directly on ColumnString chars/offsets to avoid per-row
94
        // std::string allocation and copy overhead.
95
        // Applies to both replace (empty=true) and replace_empty (empty=false):
96
        // when old_str is non-empty the two variants behave identically.
97
876
        if (col_const[1] && col_const[2]) {
98
125
            StringRef old_ref = col_old_str->get_data_at(0);
99
125
            StringRef new_ref = col_new_str->get_data_at(0);
100
125
            if (old_ref.size > 0) {
101
100
                _replace_const_pattern(*col_origin_str, old_ref, new_ref, *col_res,
102
100
                                       input_rows_count, col_const[0]);
103
100
                block.replace_by_position(result, std::move(col_res));
104
100
                return Status::OK();
105
100
            }
106
125
        }
107
108
776
        std::visit(
109
776
                [&](auto origin_str_const, auto old_str_const, auto new_str_const) {
110
776
                    for (int i = 0; i < input_rows_count; ++i) {
111
776
                        StringRef origin_str =
112
776
                                col_origin_str->get_data_at(index_check_const<origin_str_const>(i));
113
776
                        StringRef old_str =
114
776
                                col_old_str->get_data_at(index_check_const<old_str_const>(i));
115
776
                        StringRef new_str =
116
776
                                col_new_str->get_data_at(index_check_const<new_str_const>(i));
117
118
776
                        std::string result =
119
776
                                replace(origin_str.to_string(), old_str.to_string_view(),
120
776
                                        new_str.to_string_view());
121
122
776
                        col_res->insert_data(result.data(), result.length());
123
776
                    }
124
776
                },
125
776
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
126
776
                make_bool_variant(col_const[2]));
127
128
776
        block.replace_by_position(result, std::move(col_res));
129
776
        return Status::OK();
130
876
    }
131
132
private:
133
    // Optimized replace path for constant old_str (non-empty) and constant new_str.
134
    // Avoids per-row std::string allocation by working directly on ColumnString
135
    // chars/offsets.  Two-level search strategy:
136
    //  1. memchr (glibc AVX512) scans for the needle's first byte.  If absent,
137
    //     the row is guaranteed no-match and is bulk-copied with a single memcpy.
138
    //  2. When the first byte is present, ASCIICaseSensitiveStringSearcher
139
    //     (SSE4.1, prebuilt once outside the row loop) does the full needle scan.
140
    static void _replace_const_pattern(const ColumnString& src, StringRef old_ref,
141
                                       StringRef new_ref, ColumnString& dst,
142
200
                                       size_t input_rows_count, bool src_const) {
143
200
        auto& dst_chars = dst.get_chars();
144
200
        auto& dst_offsets = dst.get_offsets();
145
146
200
        dst_chars.reserve(src_const ? (src.get_data_at(0).size * input_rows_count)
147
200
                                    : src.get_chars().size());
148
200
        dst_offsets.resize(input_rows_count);
149
150
        // Build SSE4.1 searcher once — first+second byte masks precomputed here.
151
200
        ASCIICaseSensitiveStringSearcher searcher(old_ref.data, old_ref.size);
152
200
        const size_t needle_size = old_ref.size;
153
200
        const size_t replacement_size = new_ref.size;
154
200
        const char* replacement_data = new_ref.data;
155
200
        const auto needle_first = static_cast<unsigned char>(old_ref.data[0]);
156
157
400
        for (size_t i = 0; i < input_rows_count; ++i) {
158
200
            StringRef row = src.get_data_at(src_const ? 0 : i);
159
200
            const char* const row_end = row.data + row.size;
160
161
            // Level-1: memchr for needle's first byte (glibc uses AVX512 internally).
162
            // If the first byte is absent the entire row cannot contain the needle;
163
            // bulk-copy it and move to the next row without entering the SSE4.1 loop.
164
200
            if (memchr(row.data, needle_first, row.size) == nullptr) {
165
120
                StringOP::push_value_string({row.data, row.size}, i, dst_chars, dst_offsets);
166
120
                continue;
167
120
            }
168
169
            // Level-2: SSE4.1 searcher handles needle matching for this row.
170
80
            const char* pos = row.data;
171
160
            while (pos < row_end) {
172
110
                const char* match = searcher.search(pos, row_end);
173
                // Copy prefix before match
174
110
                size_t prefix_len = static_cast<size_t>(match - pos);
175
110
                if (prefix_len > 0) {
176
60
                    size_t old_size = dst_chars.size();
177
60
                    ColumnString::check_chars_length(old_size + prefix_len, i + 1);
178
60
                    dst_chars.resize(old_size + prefix_len);
179
60
                    memcpy(&dst_chars[old_size], pos, prefix_len);
180
60
                }
181
110
                if (match == row_end) {
182
30
                    break;
183
30
                }
184
                // Copy replacement
185
80
                if (replacement_size > 0) {
186
64
                    size_t old_size = dst_chars.size();
187
64
                    ColumnString::check_chars_length(old_size + replacement_size, i + 1);
188
64
                    dst_chars.resize(old_size + replacement_size);
189
64
                    memcpy(&dst_chars[old_size], replacement_data, replacement_size);
190
64
                }
191
80
                pos = match + needle_size;
192
80
            }
193
80
            StringOP::push_empty_string(i, dst_chars, dst_offsets);
194
80
        }
195
200
    }
_ZN5doris15FunctionReplaceINS_11ReplaceImplELb1EE22_replace_const_patternERKNS_9ColumnStrIjEENS_9StringRefES7_RS4_mb
Line
Count
Source
142
100
                                       size_t input_rows_count, bool src_const) {
143
100
        auto& dst_chars = dst.get_chars();
144
100
        auto& dst_offsets = dst.get_offsets();
145
146
100
        dst_chars.reserve(src_const ? (src.get_data_at(0).size * input_rows_count)
147
100
                                    : src.get_chars().size());
148
100
        dst_offsets.resize(input_rows_count);
149
150
        // Build SSE4.1 searcher once — first+second byte masks precomputed here.
151
100
        ASCIICaseSensitiveStringSearcher searcher(old_ref.data, old_ref.size);
152
100
        const size_t needle_size = old_ref.size;
153
100
        const size_t replacement_size = new_ref.size;
154
100
        const char* replacement_data = new_ref.data;
155
100
        const auto needle_first = static_cast<unsigned char>(old_ref.data[0]);
156
157
200
        for (size_t i = 0; i < input_rows_count; ++i) {
158
100
            StringRef row = src.get_data_at(src_const ? 0 : i);
159
100
            const char* const row_end = row.data + row.size;
160
161
            // Level-1: memchr for needle's first byte (glibc uses AVX512 internally).
162
            // If the first byte is absent the entire row cannot contain the needle;
163
            // bulk-copy it and move to the next row without entering the SSE4.1 loop.
164
100
            if (memchr(row.data, needle_first, row.size) == nullptr) {
165
60
                StringOP::push_value_string({row.data, row.size}, i, dst_chars, dst_offsets);
166
60
                continue;
167
60
            }
168
169
            // Level-2: SSE4.1 searcher handles needle matching for this row.
170
40
            const char* pos = row.data;
171
80
            while (pos < row_end) {
172
55
                const char* match = searcher.search(pos, row_end);
173
                // Copy prefix before match
174
55
                size_t prefix_len = static_cast<size_t>(match - pos);
175
55
                if (prefix_len > 0) {
176
30
                    size_t old_size = dst_chars.size();
177
30
                    ColumnString::check_chars_length(old_size + prefix_len, i + 1);
178
30
                    dst_chars.resize(old_size + prefix_len);
179
30
                    memcpy(&dst_chars[old_size], pos, prefix_len);
180
30
                }
181
55
                if (match == row_end) {
182
15
                    break;
183
15
                }
184
                // Copy replacement
185
40
                if (replacement_size > 0) {
186
32
                    size_t old_size = dst_chars.size();
187
32
                    ColumnString::check_chars_length(old_size + replacement_size, i + 1);
188
32
                    dst_chars.resize(old_size + replacement_size);
189
32
                    memcpy(&dst_chars[old_size], replacement_data, replacement_size);
190
32
                }
191
40
                pos = match + needle_size;
192
40
            }
193
40
            StringOP::push_empty_string(i, dst_chars, dst_offsets);
194
40
        }
195
100
    }
_ZN5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE22_replace_const_patternERKNS_9ColumnStrIjEENS_9StringRefES7_RS4_mb
Line
Count
Source
142
100
                                       size_t input_rows_count, bool src_const) {
143
100
        auto& dst_chars = dst.get_chars();
144
100
        auto& dst_offsets = dst.get_offsets();
145
146
100
        dst_chars.reserve(src_const ? (src.get_data_at(0).size * input_rows_count)
147
100
                                    : src.get_chars().size());
148
100
        dst_offsets.resize(input_rows_count);
149
150
        // Build SSE4.1 searcher once — first+second byte masks precomputed here.
151
100
        ASCIICaseSensitiveStringSearcher searcher(old_ref.data, old_ref.size);
152
100
        const size_t needle_size = old_ref.size;
153
100
        const size_t replacement_size = new_ref.size;
154
100
        const char* replacement_data = new_ref.data;
155
100
        const auto needle_first = static_cast<unsigned char>(old_ref.data[0]);
156
157
200
        for (size_t i = 0; i < input_rows_count; ++i) {
158
100
            StringRef row = src.get_data_at(src_const ? 0 : i);
159
100
            const char* const row_end = row.data + row.size;
160
161
            // Level-1: memchr for needle's first byte (glibc uses AVX512 internally).
162
            // If the first byte is absent the entire row cannot contain the needle;
163
            // bulk-copy it and move to the next row without entering the SSE4.1 loop.
164
100
            if (memchr(row.data, needle_first, row.size) == nullptr) {
165
60
                StringOP::push_value_string({row.data, row.size}, i, dst_chars, dst_offsets);
166
60
                continue;
167
60
            }
168
169
            // Level-2: SSE4.1 searcher handles needle matching for this row.
170
40
            const char* pos = row.data;
171
80
            while (pos < row_end) {
172
55
                const char* match = searcher.search(pos, row_end);
173
                // Copy prefix before match
174
55
                size_t prefix_len = static_cast<size_t>(match - pos);
175
55
                if (prefix_len > 0) {
176
30
                    size_t old_size = dst_chars.size();
177
30
                    ColumnString::check_chars_length(old_size + prefix_len, i + 1);
178
30
                    dst_chars.resize(old_size + prefix_len);
179
30
                    memcpy(&dst_chars[old_size], pos, prefix_len);
180
30
                }
181
55
                if (match == row_end) {
182
15
                    break;
183
15
                }
184
                // Copy replacement
185
40
                if (replacement_size > 0) {
186
32
                    size_t old_size = dst_chars.size();
187
32
                    ColumnString::check_chars_length(old_size + replacement_size, i + 1);
188
32
                    dst_chars.resize(old_size + replacement_size);
189
32
                    memcpy(&dst_chars[old_size], replacement_data, replacement_size);
190
32
                }
191
40
                pos = match + needle_size;
192
40
            }
193
40
            StringOP::push_empty_string(i, dst_chars, dst_offsets);
194
40
        }
195
100
    }
196
197
1.98k
    std::string replace(std::string str, std::string_view old_str, std::string_view new_str) const {
198
1.98k
        if (old_str.empty()) {
199
494
            if constexpr (empty) {
200
247
                return str;
201
247
            } else {
202
                // Different from "Replace" only when the search string is empty.
203
                // it will insert `new_str` in front of every character and at the end of the old str.
204
247
                if (new_str.empty()) {
205
59
                    return str;
206
59
                }
207
188
                if (simd::VStringFunctions::is_ascii({str.data(), str.size()})) {
208
188
                    std::string result;
209
188
                    ColumnString::check_chars_length(
210
188
                            str.length() * (new_str.length() + 1) + new_str.length(), 0);
211
188
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
212
648
                    for (char c : str) {
213
648
                        result += new_str;
214
648
                        result += c;
215
648
                    }
216
188
                    result += new_str;
217
188
                    return result;
218
188
                } else {
219
0
                    std::string result;
220
0
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
221
0
                    for (size_t i = 0, utf8_char_len = 0; i < str.size(); i += utf8_char_len) {
222
0
                        utf8_char_len = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
223
0
                        result += new_str;
224
0
                        result.append(&str[i], utf8_char_len);
225
0
                    }
226
0
                    result += new_str;
227
0
                    ColumnString::check_chars_length(result.size(), 0);
228
0
                    return result;
229
0
                }
230
188
            }
231
1.48k
        } else {
232
1.48k
            std::string::size_type pos = 0;
233
1.48k
            std::string::size_type oldLen = old_str.size();
234
1.48k
            std::string::size_type newLen = new_str.size();
235
2.06k
            while ((pos = str.find(old_str, pos)) != std::string::npos) {
236
576
                str.replace(pos, oldLen, new_str);
237
576
                pos += newLen;
238
576
            }
239
1.48k
            return str;
240
1.48k
        }
241
1.98k
    }
_ZNK5doris15FunctionReplaceINS_11ReplaceImplELb1EE7replaceENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt17basic_string_viewIcS6_ESA_
Line
Count
Source
197
991
    std::string replace(std::string str, std::string_view old_str, std::string_view new_str) const {
198
991
        if (old_str.empty()) {
199
247
            if constexpr (empty) {
200
247
                return str;
201
            } else {
202
                // Different from "Replace" only when the search string is empty.
203
                // it will insert `new_str` in front of every character and at the end of the old str.
204
                if (new_str.empty()) {
205
                    return str;
206
                }
207
                if (simd::VStringFunctions::is_ascii({str.data(), str.size()})) {
208
                    std::string result;
209
                    ColumnString::check_chars_length(
210
                            str.length() * (new_str.length() + 1) + new_str.length(), 0);
211
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
212
                    for (char c : str) {
213
                        result += new_str;
214
                        result += c;
215
                    }
216
                    result += new_str;
217
                    return result;
218
                } else {
219
                    std::string result;
220
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
221
                    for (size_t i = 0, utf8_char_len = 0; i < str.size(); i += utf8_char_len) {
222
                        utf8_char_len = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
223
                        result += new_str;
224
                        result.append(&str[i], utf8_char_len);
225
                    }
226
                    result += new_str;
227
                    ColumnString::check_chars_length(result.size(), 0);
228
                    return result;
229
                }
230
            }
231
744
        } else {
232
744
            std::string::size_type pos = 0;
233
744
            std::string::size_type oldLen = old_str.size();
234
744
            std::string::size_type newLen = new_str.size();
235
1.03k
            while ((pos = str.find(old_str, pos)) != std::string::npos) {
236
288
                str.replace(pos, oldLen, new_str);
237
288
                pos += newLen;
238
288
            }
239
744
            return str;
240
744
        }
241
991
    }
_ZNK5doris15FunctionReplaceINS_16ReplaceEmptyImplELb0EE7replaceENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt17basic_string_viewIcS6_ESA_
Line
Count
Source
197
991
    std::string replace(std::string str, std::string_view old_str, std::string_view new_str) const {
198
991
        if (old_str.empty()) {
199
            if constexpr (empty) {
200
                return str;
201
247
            } else {
202
                // Different from "Replace" only when the search string is empty.
203
                // it will insert `new_str` in front of every character and at the end of the old str.
204
247
                if (new_str.empty()) {
205
59
                    return str;
206
59
                }
207
188
                if (simd::VStringFunctions::is_ascii({str.data(), str.size()})) {
208
188
                    std::string result;
209
188
                    ColumnString::check_chars_length(
210
188
                            str.length() * (new_str.length() + 1) + new_str.length(), 0);
211
188
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
212
648
                    for (char c : str) {
213
648
                        result += new_str;
214
648
                        result += c;
215
648
                    }
216
188
                    result += new_str;
217
188
                    return result;
218
188
                } else {
219
0
                    std::string result;
220
0
                    result.reserve(str.length() * (new_str.length() + 1) + new_str.length());
221
0
                    for (size_t i = 0, utf8_char_len = 0; i < str.size(); i += utf8_char_len) {
222
0
                        utf8_char_len = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
223
0
                        result += new_str;
224
0
                        result.append(&str[i], utf8_char_len);
225
0
                    }
226
0
                    result += new_str;
227
0
                    ColumnString::check_chars_length(result.size(), 0);
228
0
                    return result;
229
0
                }
230
188
            }
231
744
        } else {
232
744
            std::string::size_type pos = 0;
233
744
            std::string::size_type oldLen = old_str.size();
234
744
            std::string::size_type newLen = new_str.size();
235
1.03k
            while ((pos = str.find(old_str, pos)) != std::string::npos) {
236
288
                str.replace(pos, oldLen, new_str);
237
288
                pos += newLen;
238
288
            }
239
744
            return str;
240
744
        }
241
991
    }
242
};
243
244
struct ReverseImpl {
245
    static Status vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets,
246
53
                         ColumnString::Chars& res_data, ColumnString::Offsets& res_offsets) {
247
53
        auto rows_count = offsets.size();
248
53
        res_offsets.resize(rows_count);
249
53
        res_data.reserve(data.size());
250
158
        for (ssize_t i = 0; i < rows_count; ++i) {
251
105
            auto src_str = reinterpret_cast<const char*>(&data[offsets[i - 1]]);
252
105
            int64_t src_len = offsets[i] - offsets[i - 1];
253
105
            std::string dst;
254
105
            dst.resize(src_len);
255
105
            simd::VStringFunctions::reverse(StringRef((uint8_t*)src_str, src_len), &dst);
256
105
            StringOP::push_value_string(std::string_view(dst.data(), src_len), i, res_data,
257
105
                                        res_offsets);
258
105
        }
259
53
        return Status::OK();
260
53
    }
261
};
262
263
template <typename Impl>
264
class FunctionSubReplace : public IFunction {
265
public:
266
    static constexpr auto name = "sub_replace";
267
268
4
    static FunctionPtr create() { return std::make_shared<FunctionSubReplace<Impl>>(); }
_ZN5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE6createEv
Line
Count
Source
268
2
    static FunctionPtr create() { return std::make_shared<FunctionSubReplace<Impl>>(); }
_ZN5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE6createEv
Line
Count
Source
268
2
    static FunctionPtr create() { return std::make_shared<FunctionSubReplace<Impl>>(); }
269
270
0
    String get_name() const override { return name; }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE8get_nameB5cxx11Ev
271
272
0
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
273
0
        return make_nullable(std::make_shared<DataTypeString>());
274
0
    }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
275
276
2
    bool is_variadic() const override { return true; }
_ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE11is_variadicEv
Line
Count
Source
276
1
    bool is_variadic() const override { return true; }
_ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE11is_variadicEv
Line
Count
Source
276
1
    bool is_variadic() const override { return true; }
277
278
2
    DataTypes get_variadic_argument_types_impl() const override {
279
2
        return Impl::get_variadic_argument_types();
280
2
    }
_ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE32get_variadic_argument_types_implEv
Line
Count
Source
278
1
    DataTypes get_variadic_argument_types_impl() const override {
279
1
        return Impl::get_variadic_argument_types();
280
1
    }
_ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE32get_variadic_argument_types_implEv
Line
Count
Source
278
1
    DataTypes get_variadic_argument_types_impl() const override {
279
1
        return Impl::get_variadic_argument_types();
280
1
    }
281
282
0
    size_t get_number_of_arguments() const override {
283
0
        return get_variadic_argument_types_impl().size();
284
0
    }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE23get_number_of_argumentsEv
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE23get_number_of_argumentsEv
285
286
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
287
0
                        uint32_t result, size_t input_rows_count) const override {
288
0
        return Impl::execute_impl(context, block, arguments, result, input_rows_count);
289
0
    }
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_19SubReplaceThreeImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Unexecuted instantiation: _ZNK5doris18FunctionSubReplaceINS_18SubReplaceFourImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
290
};
291
292
struct SubReplaceImpl {
293
    static Status replace_execute(Block& block, const ColumnNumbers& arguments, uint32_t result,
294
1
                                  size_t input_rows_count) {
295
1
        auto res_column = ColumnString::create();
296
1
        auto* result_column = assert_cast<ColumnString*>(res_column.get());
297
1
        auto args_null_map = ColumnUInt8::create(input_rows_count, 0);
298
1
        ColumnPtr argument_columns[4];
299
1
        bool col_const[4];
300
5
        for (int i = 0; i < 4; ++i) {
301
4
            std::tie(argument_columns[i], col_const[i]) =
302
4
                    unpack_if_const(block.get_by_position(arguments[i]).column);
303
4
        }
304
1
        const auto* data_column = assert_cast<const ColumnString*>(argument_columns[0].get());
305
1
        const auto* mask_column = assert_cast<const ColumnString*>(argument_columns[1].get());
306
1
        const auto* start_column = assert_cast<const ColumnInt32*>(argument_columns[2].get());
307
1
        const auto* length_column = assert_cast<const ColumnInt32*>(argument_columns[3].get());
308
309
1
        std::visit(
310
1
                [&](auto origin_str_const, auto new_str_const, auto start_const, auto len_const) {
311
1
                    if (data_column->is_ascii()) {
312
1
                        vector_ascii<origin_str_const, new_str_const, start_const, len_const>(
313
1
                                data_column, mask_column, start_column->get_data(),
314
1
                                length_column->get_data(), args_null_map->get_data(), result_column,
315
1
                                input_rows_count);
316
1
                    } else {
317
0
                        vector_utf8<origin_str_const, new_str_const, start_const, len_const>(
318
0
                                data_column, mask_column, start_column->get_data(),
319
0
                                length_column->get_data(), args_null_map->get_data(), result_column,
320
0
                                input_rows_count);
321
0
                    }
322
1
                },
_ZZN5doris14SubReplaceImpl15replace_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESF_SF_SF_EEDaS8_S9_SA_SB_
Line
Count
Source
310
1
                [&](auto origin_str_const, auto new_str_const, auto start_const, auto len_const) {
311
1
                    if (data_column->is_ascii()) {
312
1
                        vector_ascii<origin_str_const, new_str_const, start_const, len_const>(
313
1
                                data_column, mask_column, start_column->get_data(),
314
1
                                length_column->get_data(), args_null_map->get_data(), result_column,
315
1
                                input_rows_count);
316
1
                    } else {
317
0
                        vector_utf8<origin_str_const, new_str_const, start_const, len_const>(
318
0
                                data_column, mask_column, start_column->get_data(),
319
0
                                length_column->get_data(), args_null_map->get_data(), result_column,
320
0
                                input_rows_count);
321
0
                    }
322
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_
323
1
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
324
1
                make_bool_variant(col_const[2]), make_bool_variant(col_const[3]));
325
1
        block.get_by_position(result).column =
326
1
                ColumnNullable::create(std::move(res_column), std::move(args_null_map));
327
1
        return Status::OK();
328
1
    }
329
330
private:
331
    template <bool origin_str_const, bool new_str_const, bool start_const, bool len_const>
332
    static void vector_ascii(const ColumnString* data_column, const ColumnString* mask_column,
333
                             const PaddedPODArray<Int32>& args_start,
334
                             const PaddedPODArray<Int32>& args_length, NullMap& args_null_map,
335
1
                             ColumnString* result_column, size_t input_rows_count) {
336
1
        ColumnString::Chars& res_chars = result_column->get_chars();
337
1
        ColumnString::Offsets& res_offsets = result_column->get_offsets();
338
10.2k
        for (size_t row = 0; row < input_rows_count; ++row) {
339
10.2k
            StringRef origin_str =
340
10.2k
                    data_column->get_data_at(index_check_const<origin_str_const>(row));
341
10.2k
            StringRef new_str = mask_column->get_data_at(index_check_const<new_str_const>(row));
342
10.2k
            const auto start = args_start[index_check_const<start_const>(row)];
343
10.2k
            const auto length = args_length[index_check_const<len_const>(row)];
344
10.2k
            const size_t origin_str_len = origin_str.size;
345
            //input is null, start < 0, len < 0, str_size <= start. return NULL
346
10.2k
            if (args_null_map[row] || start < 0 || length < 0 || origin_str_len <= start) {
347
10.2k
                res_offsets.push_back(res_chars.size());
348
10.2k
                args_null_map[row] = 1;
349
10.2k
            } else {
350
0
                std::string_view replace_str = new_str.to_string_view();
351
0
                std::string result = origin_str.to_string();
352
0
                result.replace(start, length, replace_str);
353
0
                result_column->insert_data(result.data(), result.length());
354
0
            }
355
10.2k
        }
356
1
    }
_ZN5doris14SubReplaceImpl12vector_asciiILb0ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEES5_RKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESC_RNS6_IhLm4096ES9_Lm16ELm15EEEPS3_m
Line
Count
Source
335
1
                             ColumnString* result_column, size_t input_rows_count) {
336
1
        ColumnString::Chars& res_chars = result_column->get_chars();
337
1
        ColumnString::Offsets& res_offsets = result_column->get_offsets();
338
10.2k
        for (size_t row = 0; row < input_rows_count; ++row) {
339
10.2k
            StringRef origin_str =
340
10.2k
                    data_column->get_data_at(index_check_const<origin_str_const>(row));
341
10.2k
            StringRef new_str = mask_column->get_data_at(index_check_const<new_str_const>(row));
342
10.2k
            const auto start = args_start[index_check_const<start_const>(row)];
343
10.2k
            const auto length = args_length[index_check_const<len_const>(row)];
344
10.2k
            const size_t origin_str_len = origin_str.size;
345
            //input is null, start < 0, len < 0, str_size <= start. return NULL
346
10.2k
            if (args_null_map[row] || start < 0 || length < 0 || origin_str_len <= start) {
347
10.2k
                res_offsets.push_back(res_chars.size());
348
10.2k
                args_null_map[row] = 1;
349
10.2k
            } else {
350
0
                std::string_view replace_str = new_str.to_string_view();
351
0
                std::string result = origin_str.to_string();
352
0
                result.replace(start, length, replace_str);
353
0
                result_column->insert_data(result.data(), result.length());
354
0
            }
355
10.2k
        }
356
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
357
358
    template <bool origin_str_const, bool new_str_const, bool start_const, bool len_const>
359
    static void vector_utf8(const ColumnString* data_column, const ColumnString* mask_column,
360
                            const PaddedPODArray<Int32>& args_start,
361
                            const PaddedPODArray<Int32>& args_length, NullMap& args_null_map,
362
0
                            ColumnString* result_column, size_t input_rows_count) {
363
0
        ColumnString::Chars& res_chars = result_column->get_chars();
364
0
        ColumnString::Offsets& res_offsets = result_column->get_offsets();
365
366
0
        for (size_t row = 0; row < input_rows_count; ++row) {
367
0
            StringRef origin_str =
368
0
                    data_column->get_data_at(index_check_const<origin_str_const>(row));
369
0
            StringRef new_str = mask_column->get_data_at(index_check_const<new_str_const>(row));
370
0
            const auto start = args_start[index_check_const<start_const>(row)];
371
0
            const auto length = args_length[index_check_const<len_const>(row)];
372
            //input is null, start < 0, len < 0 return NULL
373
0
            if (args_null_map[row] || start < 0 || length < 0) {
374
0
                res_offsets.push_back(res_chars.size());
375
0
                args_null_map[row] = 1;
376
0
                continue;
377
0
            }
378
379
0
            const auto [start_byte_len, start_char_len] =
380
0
                    simd::VStringFunctions::iterate_utf8_with_limit_length(origin_str.begin(),
381
0
                                                                           origin_str.end(), start);
382
383
            // start >= orgin.size
384
0
            DCHECK(start_char_len <= start);
385
0
            if (start_byte_len == origin_str.size) {
386
0
                res_offsets.push_back(res_chars.size());
387
0
                args_null_map[row] = 1;
388
0
                continue;
389
0
            }
390
391
0
            auto [end_byte_len, end_char_len] =
392
0
                    simd::VStringFunctions::iterate_utf8_with_limit_length(
393
0
                            origin_str.begin() + start_byte_len, origin_str.end(), length);
394
0
            DCHECK(end_char_len <= length);
395
0
            std::string_view replace_str = new_str.to_string_view();
396
0
            std::string result = origin_str.to_string();
397
0
            result.replace(start_byte_len, end_byte_len, replace_str);
398
0
            result_column->insert_data(result.data(), result.length());
399
0
        }
400
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
401
};
402
403
struct SubReplaceThreeImpl {
404
1
    static DataTypes get_variadic_argument_types() {
405
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
406
1
                std::make_shared<DataTypeInt32>()};
407
1
    }
408
409
    static Status execute_impl(FunctionContext* context, Block& block,
410
                               const ColumnNumbers& arguments, uint32_t result,
411
0
                               size_t input_rows_count) {
412
0
        auto params = ColumnInt32::create(input_rows_count);
413
0
        auto& strlen_data = params->get_data();
414
415
0
        auto str_col =
416
0
                block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
417
0
        if (const auto* nullable = check_and_get_column<const ColumnNullable>(*str_col)) {
418
0
            str_col = nullable->get_nested_column_ptr();
419
0
        }
420
0
        const auto* str_column = assert_cast<const ColumnString*>(str_col.get());
421
        // use utf8 len
422
0
        for (int i = 0; i < input_rows_count; ++i) {
423
0
            StringRef str_ref = str_column->get_data_at(i);
424
0
            strlen_data[i] = simd::VStringFunctions::get_char_len(str_ref.data, str_ref.size);
425
0
        }
426
427
0
        block.insert({std::move(params), std::make_shared<DataTypeInt32>(), "strlen"});
428
0
        ColumnNumbers temp_arguments = {arguments[0], arguments[1], arguments[2],
429
0
                                        block.columns() - 1};
430
0
        return SubReplaceImpl::replace_execute(block, temp_arguments, result, input_rows_count);
431
0
    }
432
};
433
434
struct SubReplaceFourImpl {
435
1
    static DataTypes get_variadic_argument_types() {
436
1
        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
437
1
                std::make_shared<DataTypeInt32>(), std::make_shared<DataTypeInt32>()};
438
1
    }
439
440
    static Status execute_impl(FunctionContext* context, Block& block,
441
                               const ColumnNumbers& arguments, uint32_t result,
442
0
                               size_t input_rows_count) {
443
0
        return SubReplaceImpl::replace_execute(block, arguments, result, input_rows_count);
444
0
    }
445
};
446
447
class FunctionOverlay : public IFunction {
448
public:
449
    static constexpr auto name = "overlay";
450
19
    static FunctionPtr create() { return std::make_shared<FunctionOverlay>(); }
451
1
    String get_name() const override { return name; }
452
17
    size_t get_number_of_arguments() const override { return 4; }
453
454
17
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
455
17
        return std::make_shared<DataTypeString>();
456
17
    }
457
458
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
459
13
                        uint32_t result, size_t input_rows_count) const override {
460
13
        DCHECK_EQ(arguments.size(), 4);
461
462
13
        bool col_const[4];
463
13
        ColumnPtr argument_columns[4];
464
65
        for (int i = 0; i < 4; ++i) {
465
52
            std::tie(argument_columns[i], col_const[i]) =
466
52
                    unpack_if_const(block.get_by_position(arguments[i]).column);
467
52
        }
468
469
13
        const auto* col_origin = assert_cast<const ColumnString*>(argument_columns[0].get());
470
471
13
        const auto* col_pos =
472
13
                assert_cast<const ColumnInt32*>(argument_columns[1].get())->get_data().data();
473
13
        const auto* col_len =
474
13
                assert_cast<const ColumnInt32*>(argument_columns[2].get())->get_data().data();
475
13
        const auto* col_insert = assert_cast<const ColumnString*>(argument_columns[3].get());
476
477
13
        ColumnString::MutablePtr col_res = ColumnString::create();
478
479
        // if all input string is ascii, we can use ascii function to handle it
480
13
        const bool is_all_ascii = col_origin->is_ascii() && col_insert->is_ascii();
481
13
        std::visit(
482
13
                [&](auto origin_const, auto pos_const, auto len_const, auto insert_const) {
483
13
                    if (is_all_ascii) {
484
6
                        vector_ascii<origin_const, pos_const, len_const, insert_const>(
485
6
                                col_origin, col_pos, col_len, col_insert, col_res,
486
6
                                input_rows_count);
487
7
                    } else {
488
7
                        vector_utf8<origin_const, pos_const, len_const, insert_const>(
489
7
                                col_origin, col_pos, col_len, col_insert, col_res,
490
7
                                input_rows_count);
491
7
                    }
492
13
                },
_ZZNK5doris15FunctionOverlay12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_T2_E_clISt17integral_constantIbLb0EESH_SH_SH_EEDaSA_SB_SC_SD_
Line
Count
Source
482
1
                [&](auto origin_const, auto pos_const, auto len_const, auto insert_const) {
483
1
                    if (is_all_ascii) {
484
0
                        vector_ascii<origin_const, pos_const, len_const, insert_const>(
485
0
                                col_origin, col_pos, col_len, col_insert, col_res,
486
0
                                input_rows_count);
487
1
                    } else {
488
1
                        vector_utf8<origin_const, pos_const, len_const, insert_const>(
489
1
                                col_origin, col_pos, col_len, col_insert, col_res,
490
1
                                input_rows_count);
491
1
                    }
492
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
482
12
                [&](auto origin_const, auto pos_const, auto len_const, auto insert_const) {
483
12
                    if (is_all_ascii) {
484
6
                        vector_ascii<origin_const, pos_const, len_const, insert_const>(
485
6
                                col_origin, col_pos, col_len, col_insert, col_res,
486
6
                                input_rows_count);
487
6
                    } else {
488
6
                        vector_utf8<origin_const, pos_const, len_const, insert_const>(
489
6
                                col_origin, col_pos, col_len, col_insert, col_res,
490
6
                                input_rows_count);
491
6
                    }
492
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_
493
13
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
494
13
                make_bool_variant(col_const[2]), make_bool_variant(col_const[3]));
495
13
        block.replace_by_position(result, std::move(col_res));
496
13
        return Status::OK();
497
13
    }
498
499
private:
500
    template <bool origin_const, bool pos_const, bool len_const, bool insert_const>
501
    static void vector_ascii(const ColumnString* col_origin, int const* col_pos, int const* col_len,
502
                             const ColumnString* col_insert, ColumnString::MutablePtr& col_res,
503
6
                             size_t input_rows_count) {
504
6
        auto& col_res_chars = col_res->get_chars();
505
6
        auto& col_res_offsets = col_res->get_offsets();
506
6
        StringRef origin_str, insert_str;
507
12
        for (size_t i = 0; i < input_rows_count; i++) {
508
6
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
509
            // pos is 1-based index,so we need to minus 1
510
6
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
511
6
            const auto len = col_len[index_check_const<len_const>(i)];
512
6
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
513
6
            const auto origin_size = origin_str.size;
514
6
            if (pos >= origin_size || pos < 0) {
515
                // If pos is not within the length of the string, the original string is returned.
516
3
                col_res->insert_data(origin_str.data, origin_str.size);
517
3
                continue;
518
3
            }
519
3
            col_res_chars.insert(origin_str.data,
520
3
                                 origin_str.data + pos); // copy origin_str with index 0 to pos - 1
521
3
            if (pos + len > origin_size || len < 0) {
522
1
                col_res_chars.insert(insert_str.begin(),
523
1
                                     insert_str.end()); // copy all of insert_str.
524
2
            } else {
525
2
                col_res_chars.insert(insert_str.begin(),
526
2
                                     insert_str.end()); // copy all of insert_str.
527
2
                col_res_chars.insert(
528
2
                        origin_str.data + pos + len,
529
2
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
530
2
            }
531
3
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
532
3
            col_res_offsets.push_back(col_res_chars.size());
533
3
        }
534
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
503
6
                             size_t input_rows_count) {
504
6
        auto& col_res_chars = col_res->get_chars();
505
6
        auto& col_res_offsets = col_res->get_offsets();
506
6
        StringRef origin_str, insert_str;
507
12
        for (size_t i = 0; i < input_rows_count; i++) {
508
6
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
509
            // pos is 1-based index,so we need to minus 1
510
6
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
511
6
            const auto len = col_len[index_check_const<len_const>(i)];
512
6
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
513
6
            const auto origin_size = origin_str.size;
514
6
            if (pos >= origin_size || pos < 0) {
515
                // If pos is not within the length of the string, the original string is returned.
516
3
                col_res->insert_data(origin_str.data, origin_str.size);
517
3
                continue;
518
3
            }
519
3
            col_res_chars.insert(origin_str.data,
520
3
                                 origin_str.data + pos); // copy origin_str with index 0 to pos - 1
521
3
            if (pos + len > origin_size || len < 0) {
522
1
                col_res_chars.insert(insert_str.begin(),
523
1
                                     insert_str.end()); // copy all of insert_str.
524
2
            } else {
525
2
                col_res_chars.insert(insert_str.begin(),
526
2
                                     insert_str.end()); // copy all of insert_str.
527
2
                col_res_chars.insert(
528
2
                        origin_str.data + pos + len,
529
2
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
530
2
            }
531
3
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
532
3
            col_res_offsets.push_back(col_res_chars.size());
533
3
        }
534
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
535
536
    template <bool origin_const, bool pos_const, bool len_const, bool insert_const>
537
    NO_SANITIZE_UNDEFINED static void vector_utf8(const ColumnString* col_origin,
538
                                                  int const* col_pos, int const* col_len,
539
                                                  const ColumnString* col_insert,
540
                                                  ColumnString::MutablePtr& col_res,
541
7
                                                  size_t input_rows_count) {
542
7
        auto& col_res_chars = col_res->get_chars();
543
7
        auto& col_res_offsets = col_res->get_offsets();
544
7
        StringRef origin_str, insert_str;
545
        // utf8_origin_offsets is used to store the offset of each utf8 character in the original string.
546
        // for example, if the original string is "丝多a睿", utf8_origin_offsets will be {0, 3, 6, 7}.
547
7
        std::vector<size_t> utf8_origin_offsets;
548
29
        for (size_t i = 0; i < input_rows_count; i++) {
549
22
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
550
            // pos is 1-based index,so we need to minus 1
551
22
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
552
22
            const auto len = col_len[index_check_const<len_const>(i)];
553
22
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
554
22
            utf8_origin_offsets.clear();
555
556
160
            for (size_t ni = 0, char_size = 0; ni < origin_str.size; ni += char_size) {
557
138
                utf8_origin_offsets.push_back(ni);
558
138
                char_size = get_utf8_byte_length(origin_str.data[ni]);
559
138
            }
560
561
22
            const size_t utf8_origin_size = utf8_origin_offsets.size();
562
563
22
            if (pos >= utf8_origin_size || pos < 0) {
564
                // If pos is not within the length of the string, the original string is returned.
565
13
                col_res->insert_data(origin_str.data, origin_str.size);
566
13
                continue;
567
13
            }
568
9
            col_res_chars.insert(
569
9
                    origin_str.data,
570
9
                    origin_str.data +
571
9
                            utf8_origin_offsets[pos]); // copy origin_str with index 0 to pos - 1
572
9
            if (pos + len >= utf8_origin_size || len < 0) {
573
4
                col_res_chars.insert(insert_str.begin(),
574
4
                                     insert_str.end()); // copy all of insert_str.
575
5
            } else {
576
5
                col_res_chars.insert(insert_str.begin(),
577
5
                                     insert_str.end()); // copy all of insert_str.
578
5
                col_res_chars.insert(
579
5
                        origin_str.data + utf8_origin_offsets[pos + len],
580
5
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
581
5
            }
582
9
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
583
9
            col_res_offsets.push_back(col_res_chars.size());
584
9
        }
585
7
    }
_ZN5doris15FunctionOverlay11vector_utf8ILb0ELb0ELb0ELb0EEEvPKNS_9ColumnStrIjEEPKiS7_S5_RNS_3COWINS_7IColumnEE11mutable_ptrIS3_EEm
Line
Count
Source
541
1
                                                  size_t input_rows_count) {
542
1
        auto& col_res_chars = col_res->get_chars();
543
1
        auto& col_res_offsets = col_res->get_offsets();
544
1
        StringRef origin_str, insert_str;
545
        // utf8_origin_offsets is used to store the offset of each utf8 character in the original string.
546
        // for example, if the original string is "丝多a睿", utf8_origin_offsets will be {0, 3, 6, 7}.
547
1
        std::vector<size_t> utf8_origin_offsets;
548
17
        for (size_t i = 0; i < input_rows_count; i++) {
549
16
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
550
            // pos is 1-based index,so we need to minus 1
551
16
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
552
16
            const auto len = col_len[index_check_const<len_const>(i)];
553
16
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
554
16
            utf8_origin_offsets.clear();
555
556
116
            for (size_t ni = 0, char_size = 0; ni < origin_str.size; ni += char_size) {
557
100
                utf8_origin_offsets.push_back(ni);
558
100
                char_size = get_utf8_byte_length(origin_str.data[ni]);
559
100
            }
560
561
16
            const size_t utf8_origin_size = utf8_origin_offsets.size();
562
563
16
            if (pos >= utf8_origin_size || pos < 0) {
564
                // If pos is not within the length of the string, the original string is returned.
565
10
                col_res->insert_data(origin_str.data, origin_str.size);
566
10
                continue;
567
10
            }
568
6
            col_res_chars.insert(
569
6
                    origin_str.data,
570
6
                    origin_str.data +
571
6
                            utf8_origin_offsets[pos]); // copy origin_str with index 0 to pos - 1
572
6
            if (pos + len >= utf8_origin_size || len < 0) {
573
3
                col_res_chars.insert(insert_str.begin(),
574
3
                                     insert_str.end()); // copy all of insert_str.
575
3
            } else {
576
3
                col_res_chars.insert(insert_str.begin(),
577
3
                                     insert_str.end()); // copy all of insert_str.
578
3
                col_res_chars.insert(
579
3
                        origin_str.data + utf8_origin_offsets[pos + len],
580
3
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
581
3
            }
582
6
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
583
6
            col_res_offsets.push_back(col_res_chars.size());
584
6
        }
585
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
541
6
                                                  size_t input_rows_count) {
542
6
        auto& col_res_chars = col_res->get_chars();
543
6
        auto& col_res_offsets = col_res->get_offsets();
544
6
        StringRef origin_str, insert_str;
545
        // utf8_origin_offsets is used to store the offset of each utf8 character in the original string.
546
        // for example, if the original string is "丝多a睿", utf8_origin_offsets will be {0, 3, 6, 7}.
547
6
        std::vector<size_t> utf8_origin_offsets;
548
12
        for (size_t i = 0; i < input_rows_count; i++) {
549
6
            origin_str = col_origin->get_data_at(index_check_const<origin_const>(i));
550
            // pos is 1-based index,so we need to minus 1
551
6
            const auto pos = col_pos[index_check_const<pos_const>(i)] - 1;
552
6
            const auto len = col_len[index_check_const<len_const>(i)];
553
6
            insert_str = col_insert->get_data_at(index_check_const<insert_const>(i));
554
6
            utf8_origin_offsets.clear();
555
556
44
            for (size_t ni = 0, char_size = 0; ni < origin_str.size; ni += char_size) {
557
38
                utf8_origin_offsets.push_back(ni);
558
38
                char_size = get_utf8_byte_length(origin_str.data[ni]);
559
38
            }
560
561
6
            const size_t utf8_origin_size = utf8_origin_offsets.size();
562
563
6
            if (pos >= utf8_origin_size || pos < 0) {
564
                // If pos is not within the length of the string, the original string is returned.
565
3
                col_res->insert_data(origin_str.data, origin_str.size);
566
3
                continue;
567
3
            }
568
3
            col_res_chars.insert(
569
3
                    origin_str.data,
570
3
                    origin_str.data +
571
3
                            utf8_origin_offsets[pos]); // copy origin_str with index 0 to pos - 1
572
3
            if (pos + len >= utf8_origin_size || len < 0) {
573
1
                col_res_chars.insert(insert_str.begin(),
574
1
                                     insert_str.end()); // copy all of insert_str.
575
2
            } else {
576
2
                col_res_chars.insert(insert_str.begin(),
577
2
                                     insert_str.end()); // copy all of insert_str.
578
2
                col_res_chars.insert(
579
2
                        origin_str.data + utf8_origin_offsets[pos + len],
580
2
                        origin_str.end()); // copy origin_str from pos+len-1 to the end of the line.
581
2
            }
582
3
            ColumnString::check_chars_length(col_res_chars.size(), col_res_offsets.size());
583
3
            col_res_offsets.push_back(col_res_chars.size());
584
3
        }
585
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
586
};
587
588
#include "common/compile_check_avoid_end.h"
589
} // namespace doris