Coverage Report

Created: 2026-03-19 11:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/common/varbinaryop_subbinary.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 "core/block/block.h"
21
#include "core/column/column_const.h"
22
#include "core/column/column_varbinary.h"
23
#include "core/data_type/data_type_number.h"
24
#include "core/data_type/data_type_varbinary.h"
25
#include "core/types.h"
26
27
namespace doris {
28
#include "common/compile_check_begin.h"
29
30
constexpr auto SIZE_OF_UINT = sizeof(uint32_t);
31
32
struct VarBinaryOP {
33
    static void check_and_insert_data(doris::StringView& sView, const char* data, uint32_t len,
34
49
                                      bool before_is_inline) {
35
49
        if (before_is_inline) {
36
37
            sView.set_size(len);
37
37
        } else {
38
12
            sView = doris::StringView(data, len);
39
12
        }
40
49
    }
41
42
97
    static std::pair<bool, char*> alloc(ColumnVarbinary* res_col, size_t index, uint32_t len) {
43
97
        bool is_inline = StringView::isInline(len);
44
97
        char* dst = nullptr;
45
97
        if (is_inline) {
46
85
            dst = reinterpret_cast<char*>(&(res_col->get_data()[index])) + SIZE_OF_UINT;
47
85
        } else {
48
12
            dst = res_col->alloc(len);
49
12
        }
50
97
        return {is_inline, dst};
51
97
    }
52
};
53
54
struct SubBinaryUtil {
55
    static void sub_binary_execute(Block& block, const ColumnNumbers& arguments, uint32_t result,
56
2.01k
                                   size_t input_rows_count) {
57
2.01k
        DCHECK_EQ(arguments.size(), 3);
58
2.01k
        auto res = ColumnVarbinary::create();
59
60
2.01k
        bool col_const[3];
61
2.01k
        ColumnPtr argument_columns[3];
62
8.07k
        for (int i = 0; i < 3; ++i) {
63
6.05k
            std::tie(argument_columns[i], col_const[i]) =
64
6.05k
                    unpack_if_const(block.get_by_position(arguments[i]).column);
65
6.05k
        }
66
67
2.01k
        const auto* specific_binary_column =
68
2.01k
                assert_cast<const ColumnVarbinary*>(argument_columns[0].get());
69
2.01k
        const auto* specific_start_column =
70
2.01k
                assert_cast<const ColumnInt32*>(argument_columns[1].get());
71
2.01k
        const auto* specific_len_column =
72
2.01k
                assert_cast<const ColumnInt32*>(argument_columns[2].get());
73
74
2.01k
        std::visit(
75
2.01k
                [&](auto binary_const, auto start_const, auto len_const) {
76
2.01k
                    vectors<binary_const, start_const, len_const>(
77
2.01k
                            specific_binary_column, specific_start_column, specific_len_column,
78
2.01k
                            res.get(), input_rows_count);
79
2.01k
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESE_SE_EEDaS8_S9_SA_
Line
Count
Source
75
290
                [&](auto binary_const, auto start_const, auto len_const) {
76
290
                    vectors<binary_const, start_const, len_const>(
77
290
                            specific_binary_column, specific_start_column, specific_len_column,
78
290
                            res.get(), input_rows_count);
79
290
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESE_SD_IbLb1EEEEDaS8_S9_SA_
Line
Count
Source
75
288
                [&](auto binary_const, auto start_const, auto len_const) {
76
288
                    vectors<binary_const, start_const, len_const>(
77
288
                            specific_binary_column, specific_start_column, specific_len_column,
78
288
                            res.get(), input_rows_count);
79
288
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESD_IbLb1EESE_EEDaS8_S9_SA_
Line
Count
Source
75
288
                [&](auto binary_const, auto start_const, auto len_const) {
76
288
                    vectors<binary_const, start_const, len_const>(
77
288
                            specific_binary_column, specific_start_column, specific_len_column,
78
288
                            res.get(), input_rows_count);
79
288
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb0EESD_IbLb1EESF_EEDaS8_S9_SA_
Line
Count
Source
75
288
                [&](auto binary_const, auto start_const, auto len_const) {
76
288
                    vectors<binary_const, start_const, len_const>(
77
288
                            specific_binary_column, specific_start_column, specific_len_column,
78
288
                            res.get(), input_rows_count);
79
288
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESD_IbLb0EESF_EEDaS8_S9_SA_
Line
Count
Source
75
288
                [&](auto binary_const, auto start_const, auto len_const) {
76
288
                    vectors<binary_const, start_const, len_const>(
77
288
                            specific_binary_column, specific_start_column, specific_len_column,
78
288
                            res.get(), input_rows_count);
79
288
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESD_IbLb0EESE_EEDaS8_S9_SA_
Line
Count
Source
75
288
                [&](auto binary_const, auto start_const, auto len_const) {
76
288
                    vectors<binary_const, start_const, len_const>(
77
288
                            specific_binary_column, specific_start_column, specific_len_column,
78
288
                            res.get(), input_rows_count);
79
288
                },
_ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESE_SD_IbLb0EEEEDaS8_S9_SA_
Line
Count
Source
75
288
                [&](auto binary_const, auto start_const, auto len_const) {
76
288
                    vectors<binary_const, start_const, len_const>(
77
288
                            specific_binary_column, specific_start_column, specific_len_column,
78
288
                            res.get(), input_rows_count);
79
288
                },
Unexecuted instantiation: _ZZN5doris13SubBinaryUtil18sub_binary_executeERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_T0_T1_E_clISt17integral_constantIbLb1EESE_SE_EEDaS8_S9_SA_
80
2.01k
                make_bool_variant(col_const[0]), make_bool_variant(col_const[1]),
81
2.01k
                make_bool_variant(col_const[2]));
82
2.01k
        block.get_by_position(result).column = std::move(res);
83
2.01k
    }
84
85
private:
86
    template <bool binary_const, bool start_const, bool len_const>
87
    static void vectors(const ColumnVarbinary* binarys, const ColumnInt32* start,
88
2.01k
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
2.01k
        res->get_data().reserve(size);
90
91
4.53k
        for (size_t i = 0; i < size; ++i) {
92
2.51k
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
2.51k
            int binary_size = static_cast<int>(binary.size());
94
95
2.51k
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
2.51k
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
2.51k
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
2.51k
            bool len_non_positive = len_value <= 0;
100
2.51k
            bool input_empty = binary_size == 0;
101
102
2.51k
            if (start_out_of_range || len_non_positive || input_empty) {
103
1.31k
                res->insert_default();
104
1.31k
                continue;
105
1.31k
            }
106
1.20k
            int fixed_pos = start_value - 1;
107
1.20k
            if (fixed_pos < 0) {
108
432
                fixed_pos = binary_size + fixed_pos + 1;
109
432
            }
110
1.20k
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
1.20k
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
1.20k
        }
114
2.01k
    }
_ZN5doris13SubBinaryUtil7vectorsILb0ELb0ELb0EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
290
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
290
        res->get_data().reserve(size);
90
91
1.07k
        for (size_t i = 0; i < size; ++i) {
92
788
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
788
            int binary_size = static_cast<int>(binary.size());
94
95
788
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
788
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
788
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
788
            bool len_non_positive = len_value <= 0;
100
788
            bool input_empty = binary_size == 0;
101
102
788
            if (start_out_of_range || len_non_positive || input_empty) {
103
452
                res->insert_default();
104
452
                continue;
105
452
            }
106
336
            int fixed_pos = start_value - 1;
107
336
            if (fixed_pos < 0) {
108
144
                fixed_pos = binary_size + fixed_pos + 1;
109
144
            }
110
336
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
336
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
336
        }
114
290
    }
_ZN5doris13SubBinaryUtil7vectorsILb0ELb0ELb1EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
288
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
288
        res->get_data().reserve(size);
90
91
576
        for (size_t i = 0; i < size; ++i) {
92
288
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
288
            int binary_size = static_cast<int>(binary.size());
94
95
288
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
288
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
288
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
288
            bool len_non_positive = len_value <= 0;
100
288
            bool input_empty = binary_size == 0;
101
102
288
            if (start_out_of_range || len_non_positive || input_empty) {
103
144
                res->insert_default();
104
144
                continue;
105
144
            }
106
144
            int fixed_pos = start_value - 1;
107
144
            if (fixed_pos < 0) {
108
48
                fixed_pos = binary_size + fixed_pos + 1;
109
48
            }
110
144
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
144
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
144
        }
114
288
    }
_ZN5doris13SubBinaryUtil7vectorsILb0ELb1ELb0EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
288
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
288
        res->get_data().reserve(size);
90
91
576
        for (size_t i = 0; i < size; ++i) {
92
288
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
288
            int binary_size = static_cast<int>(binary.size());
94
95
288
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
288
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
288
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
288
            bool len_non_positive = len_value <= 0;
100
288
            bool input_empty = binary_size == 0;
101
102
288
            if (start_out_of_range || len_non_positive || input_empty) {
103
144
                res->insert_default();
104
144
                continue;
105
144
            }
106
144
            int fixed_pos = start_value - 1;
107
144
            if (fixed_pos < 0) {
108
48
                fixed_pos = binary_size + fixed_pos + 1;
109
48
            }
110
144
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
144
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
144
        }
114
288
    }
_ZN5doris13SubBinaryUtil7vectorsILb0ELb1ELb1EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
288
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
288
        res->get_data().reserve(size);
90
91
576
        for (size_t i = 0; i < size; ++i) {
92
288
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
288
            int binary_size = static_cast<int>(binary.size());
94
95
288
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
288
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
288
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
288
            bool len_non_positive = len_value <= 0;
100
288
            bool input_empty = binary_size == 0;
101
102
288
            if (start_out_of_range || len_non_positive || input_empty) {
103
144
                res->insert_default();
104
144
                continue;
105
144
            }
106
144
            int fixed_pos = start_value - 1;
107
144
            if (fixed_pos < 0) {
108
48
                fixed_pos = binary_size + fixed_pos + 1;
109
48
            }
110
144
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
144
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
144
        }
114
288
    }
_ZN5doris13SubBinaryUtil7vectorsILb1ELb0ELb0EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
288
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
288
        res->get_data().reserve(size);
90
91
576
        for (size_t i = 0; i < size; ++i) {
92
288
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
288
            int binary_size = static_cast<int>(binary.size());
94
95
288
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
288
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
288
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
288
            bool len_non_positive = len_value <= 0;
100
288
            bool input_empty = binary_size == 0;
101
102
288
            if (start_out_of_range || len_non_positive || input_empty) {
103
144
                res->insert_default();
104
144
                continue;
105
144
            }
106
144
            int fixed_pos = start_value - 1;
107
144
            if (fixed_pos < 0) {
108
48
                fixed_pos = binary_size + fixed_pos + 1;
109
48
            }
110
144
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
144
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
144
        }
114
288
    }
_ZN5doris13SubBinaryUtil7vectorsILb1ELb0ELb1EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
288
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
288
        res->get_data().reserve(size);
90
91
576
        for (size_t i = 0; i < size; ++i) {
92
288
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
288
            int binary_size = static_cast<int>(binary.size());
94
95
288
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
288
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
288
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
288
            bool len_non_positive = len_value <= 0;
100
288
            bool input_empty = binary_size == 0;
101
102
288
            if (start_out_of_range || len_non_positive || input_empty) {
103
144
                res->insert_default();
104
144
                continue;
105
144
            }
106
144
            int fixed_pos = start_value - 1;
107
144
            if (fixed_pos < 0) {
108
48
                fixed_pos = binary_size + fixed_pos + 1;
109
48
            }
110
144
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
144
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
144
        }
114
288
    }
_ZN5doris13SubBinaryUtil7vectorsILb1ELb1ELb0EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
Line
Count
Source
88
288
                        const ColumnInt32* len, ColumnVarbinary* res, size_t size) {
89
288
        res->get_data().reserve(size);
90
91
576
        for (size_t i = 0; i < size; ++i) {
92
288
            doris::StringView binary = binarys->get_data()[index_check_const<binary_const>(i)];
93
288
            int binary_size = static_cast<int>(binary.size());
94
95
288
            int start_value = start->get_data()[index_check_const<start_const>(i)];
96
288
            int len_value = len->get_data()[index_check_const<len_const>(i)];
97
98
288
            bool start_out_of_range = (start_value > binary_size) || (start_value < -binary_size);
99
288
            bool len_non_positive = len_value <= 0;
100
288
            bool input_empty = binary_size == 0;
101
102
288
            if (start_out_of_range || len_non_positive || input_empty) {
103
144
                res->insert_default();
104
144
                continue;
105
144
            }
106
144
            int fixed_pos = start_value - 1;
107
144
            if (fixed_pos < 0) {
108
48
                fixed_pos = binary_size + fixed_pos + 1;
109
48
            }
110
144
            int fixed_len = std::min(binary_size - fixed_pos, len_value);
111
112
144
            res->insert_data(binary.data() + fixed_pos, fixed_len);
113
144
        }
114
288
    }
Unexecuted instantiation: _ZN5doris13SubBinaryUtil7vectorsILb1ELb1ELb1EEEvPKNS_15ColumnVarbinaryEPKNS_12ColumnVectorILNS_13PrimitiveTypeE5EEES9_PS2_m
115
};
116
117
#include "common/compile_check_end.h"
118
} // namespace doris