Coverage Report

Created: 2026-07-07 17:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/common/join_utils.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 <algorithm>
21
#include <variant>
22
23
#include "exec/common/hash_table/hash_crc32_return32.h"
24
#include "exec/common/hash_table/hash_key_type.h"
25
#include "exec/common/hash_table/hash_map_context.h"
26
#include "exec/common/hash_table/join_hash_table.h"
27
28
namespace doris {
29
30
// Devirtualize compare_at for ASOF JOIN supported column types.
31
// ASOF JOIN only supports DateV2, DateTimeV2, and TimestampTZ.
32
// Dispatches to the concrete ColumnVector<T> once so that all compare_at
33
// calls inside `func` are direct (non-virtual) calls.
34
// `func` receives a single argument: a const pointer to the concrete column
35
// (or const IColumn* as fallback for unexpected types).
36
template <typename Func>
37
8
decltype(auto) asof_column_dispatch(const IColumn* col, Func&& func) {
38
8
    if (const auto* c_dv2 = check_and_get_column<ColumnDateV2>(col)) {
39
2
        return std::forward<Func>(func)(c_dv2);
40
6
    } else if (const auto* c_dtv2 = check_and_get_column<ColumnDateTimeV2>(col)) {
41
2
        return std::forward<Func>(func)(c_dtv2);
42
4
    } else if (const auto* c_tstz = check_and_get_column<ColumnTimeStampTz>(col)) {
43
2
        return std::forward<Func>(func)(c_tstz);
44
2
    } else {
45
2
        return std::forward<Func>(func)(col);
46
2
    }
47
8
}
asof_join_test.cpp:_ZN5doris20asof_column_dispatchIZNS_42AsofColumnDispatchTest_DateV2Dispatch_Test8TestBodyEvE3$_0EEDcPKNS_7IColumnEOT_
Line
Count
Source
37
2
decltype(auto) asof_column_dispatch(const IColumn* col, Func&& func) {
38
2
    if (const auto* c_dv2 = check_and_get_column<ColumnDateV2>(col)) {
39
2
        return std::forward<Func>(func)(c_dv2);
40
2
    } else if (const auto* c_dtv2 = check_and_get_column<ColumnDateTimeV2>(col)) {
41
0
        return std::forward<Func>(func)(c_dtv2);
42
0
    } else if (const auto* c_tstz = check_and_get_column<ColumnTimeStampTz>(col)) {
43
0
        return std::forward<Func>(func)(c_tstz);
44
0
    } else {
45
0
        return std::forward<Func>(func)(col);
46
0
    }
47
2
}
asof_join_test.cpp:_ZN5doris20asof_column_dispatchIZNS_46AsofColumnDispatchTest_DateTimeV2Dispatch_Test8TestBodyEvE3$_0EEDcPKNS_7IColumnEOT_
Line
Count
Source
37
2
decltype(auto) asof_column_dispatch(const IColumn* col, Func&& func) {
38
2
    if (const auto* c_dv2 = check_and_get_column<ColumnDateV2>(col)) {
39
0
        return std::forward<Func>(func)(c_dv2);
40
2
    } else if (const auto* c_dtv2 = check_and_get_column<ColumnDateTimeV2>(col)) {
41
2
        return std::forward<Func>(func)(c_dtv2);
42
2
    } else if (const auto* c_tstz = check_and_get_column<ColumnTimeStampTz>(col)) {
43
0
        return std::forward<Func>(func)(c_tstz);
44
0
    } else {
45
0
        return std::forward<Func>(func)(col);
46
0
    }
47
2
}
asof_join_test.cpp:_ZN5doris20asof_column_dispatchIZNS_47AsofColumnDispatchTest_TimestampTZDispatch_Test8TestBodyEvE3$_0EEDcPKNS_7IColumnEOT_
Line
Count
Source
37
2
decltype(auto) asof_column_dispatch(const IColumn* col, Func&& func) {
38
2
    if (const auto* c_dv2 = check_and_get_column<ColumnDateV2>(col)) {
39
0
        return std::forward<Func>(func)(c_dv2);
40
2
    } else if (const auto* c_dtv2 = check_and_get_column<ColumnDateTimeV2>(col)) {
41
0
        return std::forward<Func>(func)(c_dtv2);
42
2
    } else if (const auto* c_tstz = check_and_get_column<ColumnTimeStampTz>(col)) {
43
2
        return std::forward<Func>(func)(c_tstz);
44
2
    } else {
45
0
        return std::forward<Func>(func)(col);
46
0
    }
47
2
}
asof_join_test.cpp:_ZN5doris20asof_column_dispatchIZNS_44AsofColumnDispatchTest_FallbackDispatch_Test8TestBodyEvE3$_0EEDcPKNS_7IColumnEOT_
Line
Count
Source
37
2
decltype(auto) asof_column_dispatch(const IColumn* col, Func&& func) {
38
2
    if (const auto* c_dv2 = check_and_get_column<ColumnDateV2>(col)) {
39
0
        return std::forward<Func>(func)(c_dv2);
40
2
    } else if (const auto* c_dtv2 = check_and_get_column<ColumnDateTimeV2>(col)) {
41
0
        return std::forward<Func>(func)(c_dtv2);
42
2
    } else if (const auto* c_tstz = check_and_get_column<ColumnTimeStampTz>(col)) {
43
0
        return std::forward<Func>(func)(c_tstz);
44
2
    } else {
45
2
        return std::forward<Func>(func)(col);
46
2
    }
47
2
}
Unexecuted instantiation: hashjoin_build_sink.cpp:_ZN5doris20asof_column_dispatchIZNS_27HashJoinBuildSinkLocalState16build_asof_indexERNS_5BlockEE3$_2EEDcPKNS_7IColumnEOT_
48
using JoinOpVariants =
49
        std::variant<std::integral_constant<TJoinOp::type, TJoinOp::INNER_JOIN>,
50
                     std::integral_constant<TJoinOp::type, TJoinOp::LEFT_SEMI_JOIN>,
51
                     std::integral_constant<TJoinOp::type, TJoinOp::LEFT_ANTI_JOIN>,
52
                     std::integral_constant<TJoinOp::type, TJoinOp::LEFT_OUTER_JOIN>,
53
                     std::integral_constant<TJoinOp::type, TJoinOp::FULL_OUTER_JOIN>,
54
                     std::integral_constant<TJoinOp::type, TJoinOp::RIGHT_OUTER_JOIN>,
55
                     std::integral_constant<TJoinOp::type, TJoinOp::CROSS_JOIN>,
56
                     std::integral_constant<TJoinOp::type, TJoinOp::RIGHT_SEMI_JOIN>,
57
                     std::integral_constant<TJoinOp::type, TJoinOp::RIGHT_ANTI_JOIN>,
58
                     std::integral_constant<TJoinOp::type, TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN>,
59
                     std::integral_constant<TJoinOp::type, TJoinOp::NULL_AWARE_LEFT_SEMI_JOIN>,
60
                     std::integral_constant<TJoinOp::type, TJoinOp::ASOF_LEFT_INNER_JOIN>,
61
                     std::integral_constant<TJoinOp::type, TJoinOp::ASOF_LEFT_OUTER_JOIN>>;
62
63
672k
inline bool is_asof_join(TJoinOp::type join_op) {
64
672k
    return join_op == TJoinOp::ASOF_LEFT_INNER_JOIN || join_op == TJoinOp::ASOF_LEFT_OUTER_JOIN;
65
672k
}
66
67
template <int JoinOpType>
68
inline constexpr bool is_asof_join_op_v =
69
        JoinOpType == TJoinOp::ASOF_LEFT_INNER_JOIN || JoinOpType == TJoinOp::ASOF_LEFT_OUTER_JOIN;
70
71
template <int JoinOpType>
72
inline constexpr bool is_asof_outer_join_op_v = JoinOpType == TJoinOp::ASOF_LEFT_OUTER_JOIN;
73
74
template <class T>
75
using PrimaryTypeHashTableContext = MethodOneNumber<T, JoinHashMap<T, HashCRC32Return32<T>, false>>;
76
77
template <class T>
78
using DirectPrimaryTypeHashTableContext =
79
        MethodOneNumberDirect<T, JoinHashMap<T, HashCRC32Return32<T>, true>>;
80
81
template <class Key>
82
using FixedKeyHashTableContext = MethodKeysFixed<JoinHashMap<Key, HashCRC32Return32<Key>, false>>;
83
84
using SerializedHashTableContext =
85
        MethodSerialized<JoinHashMap<StringRef, HashCRC32Return32<StringRef>, false>>;
86
using MethodOneString =
87
        MethodStringNoCache<JoinHashMap<StringRef, HashCRC32Return32<StringRef>, false>>;
88
89
using HashTableVariants = std::variant<
90
        std::monostate, SerializedHashTableContext, PrimaryTypeHashTableContext<UInt8>,
91
        PrimaryTypeHashTableContext<UInt16>, PrimaryTypeHashTableContext<UInt32>,
92
        PrimaryTypeHashTableContext<UInt64>, PrimaryTypeHashTableContext<UInt128>,
93
        PrimaryTypeHashTableContext<UInt256>, DirectPrimaryTypeHashTableContext<UInt8>,
94
        DirectPrimaryTypeHashTableContext<UInt16>, DirectPrimaryTypeHashTableContext<UInt32>,
95
        DirectPrimaryTypeHashTableContext<UInt64>, DirectPrimaryTypeHashTableContext<UInt128>,
96
        FixedKeyHashTableContext<UInt64>, FixedKeyHashTableContext<UInt72>,
97
        FixedKeyHashTableContext<UInt96>, FixedKeyHashTableContext<UInt104>,
98
        FixedKeyHashTableContext<UInt128>, FixedKeyHashTableContext<UInt136>,
99
        FixedKeyHashTableContext<UInt256>, MethodOneString>;
100
101
struct JoinDataVariants {
102
    HashTableVariants method_variant;
103
104
96.0k
    void init(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
105
96.0k
        switch (type) {
106
28.2k
        case HashKeyType::serialized:
107
28.2k
            method_variant.emplace<SerializedHashTableContext>();
108
28.2k
            break;
109
320
        case HashKeyType::int8_key:
110
320
            method_variant.emplace<PrimaryTypeHashTableContext<UInt8>>();
111
320
            break;
112
160
        case HashKeyType::int16_key:
113
160
            method_variant.emplace<PrimaryTypeHashTableContext<UInt16>>();
114
160
            break;
115
648
        case HashKeyType::int32_key:
116
648
            method_variant.emplace<PrimaryTypeHashTableContext<UInt32>>();
117
648
            break;
118
1.60k
        case HashKeyType::int64_key:
119
1.60k
            method_variant.emplace<PrimaryTypeHashTableContext<UInt64>>();
120
1.60k
            break;
121
480
        case HashKeyType::int128_key:
122
480
            method_variant.emplace<PrimaryTypeHashTableContext<UInt128>>();
123
480
            break;
124
0
        case HashKeyType::int256_key:
125
0
            method_variant.emplace<PrimaryTypeHashTableContext<UInt256>>();
126
0
            break;
127
648
        case HashKeyType::string_key:
128
648
            method_variant.emplace<MethodOneString>();
129
648
            break;
130
7.84k
        case HashKeyType::fixed64:
131
7.84k
            method_variant.emplace<FixedKeyHashTableContext<UInt64>>(get_key_sizes(data_types));
132
7.84k
            break;
133
6.40k
        case HashKeyType::fixed72:
134
6.40k
            method_variant.emplace<FixedKeyHashTableContext<UInt72>>(get_key_sizes(data_types));
135
6.40k
            break;
136
16.0k
        case HashKeyType::fixed96:
137
16.0k
            method_variant.emplace<FixedKeyHashTableContext<UInt96>>(get_key_sizes(data_types));
138
16.0k
            break;
139
0
        case HashKeyType::fixed104:
140
0
            method_variant.emplace<FixedKeyHashTableContext<UInt104>>(get_key_sizes(data_types));
141
0
            break;
142
16.0k
        case HashKeyType::fixed128:
143
16.0k
            method_variant.emplace<FixedKeyHashTableContext<UInt128>>(get_key_sizes(data_types));
144
16.0k
            break;
145
1.92k
        case HashKeyType::fixed136:
146
1.92k
            method_variant.emplace<FixedKeyHashTableContext<UInt136>>(get_key_sizes(data_types));
147
1.92k
            break;
148
15.8k
        case HashKeyType::fixed256:
149
15.8k
            method_variant.emplace<FixedKeyHashTableContext<UInt256>>(get_key_sizes(data_types));
150
15.8k
            break;
151
0
        default:
152
0
            throw Exception(ErrorCode::INTERNAL_ERROR,
153
0
                            "JoinDataVariants meet invalid key type, type={}", type);
154
96.0k
        }
155
96.0k
    }
156
};
157
158
template <typename Method>
159
void primary_to_direct_mapping(Method* context, const ColumnRawPtrs& key_columns,
160
3.20k
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
3.20k
    using FieldType = typename Method::Base::Key;
162
3.20k
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
3.20k
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
3.20k
    size_t num_rows = key_columns[0]->size();
166
3.20k
    if (is_column_nullable(*key_columns[0])) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
3.20k
    } else {
182
3.20k
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
9.66k
        for (size_t i = 1; i < num_rows; i++) {
185
6.45k
            max_key = std::max(max_key, input_keys[i]);
186
6.45k
            min_key = std::min(min_key, input_keys[i]);
187
6.45k
        }
188
3.20k
    }
189
190
3.20k
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
3.20k
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
3.20k
    if (allow_direct_mapping) {
193
3.20k
        for (const auto& variant_ptr : variant_ptrs) {
194
3.20k
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
3.20k
                    max_key, min_key);
196
3.20k
        }
197
3.20k
    }
198
3.20k
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberIhNS_13JoinHashTableIhNS_17HashCRC32Return32IhEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
320
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
320
    using FieldType = typename Method::Base::Key;
162
320
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
320
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
320
    size_t num_rows = key_columns[0]->size();
166
320
    if (is_column_nullable(*key_columns[0])) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
320
    } else {
182
320
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
960
        for (size_t i = 1; i < num_rows; i++) {
185
640
            max_key = std::max(max_key, input_keys[i]);
186
640
            min_key = std::min(min_key, input_keys[i]);
187
640
        }
188
320
    }
189
190
320
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
320
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
320
    if (allow_direct_mapping) {
193
320
        for (const auto& variant_ptr : variant_ptrs) {
194
320
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
320
                    max_key, min_key);
196
320
        }
197
320
    }
198
320
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberItNS_13JoinHashTableItNS_17HashCRC32Return32ItEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
160
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
160
    using FieldType = typename Method::Base::Key;
162
160
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
160
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
160
    size_t num_rows = key_columns[0]->size();
166
160
    if (is_column_nullable(*key_columns[0])) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
160
    } else {
182
160
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
480
        for (size_t i = 1; i < num_rows; i++) {
185
320
            max_key = std::max(max_key, input_keys[i]);
186
320
            min_key = std::min(min_key, input_keys[i]);
187
320
        }
188
160
    }
189
190
160
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
160
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
160
    if (allow_direct_mapping) {
193
160
        for (const auto& variant_ptr : variant_ptrs) {
194
160
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
160
                    max_key, min_key);
196
160
        }
197
160
    }
198
160
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberIjNS_13JoinHashTableIjNS_17HashCRC32Return32IjEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
646
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
646
    using FieldType = typename Method::Base::Key;
162
646
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
646
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
646
    size_t num_rows = key_columns[0]->size();
166
646
    if (is_column_nullable(*key_columns[0])) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
646
    } else {
182
646
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
1.98k
        for (size_t i = 1; i < num_rows; i++) {
185
1.33k
            max_key = std::max(max_key, input_keys[i]);
186
1.33k
            min_key = std::min(min_key, input_keys[i]);
187
1.33k
        }
188
646
    }
189
190
646
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
646
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
646
    if (allow_direct_mapping) {
193
648
        for (const auto& variant_ptr : variant_ptrs) {
194
648
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
648
                    max_key, min_key);
196
648
        }
197
646
    }
198
646
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberImNS_13JoinHashTableImNS_17HashCRC32Return32ImEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
1.60k
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
1.60k
    using FieldType = typename Method::Base::Key;
162
1.60k
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
1.60k
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
1.60k
    size_t num_rows = key_columns[0]->size();
166
1.60k
    if (is_column_nullable(*key_columns[0])) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
1.60k
    } else {
182
1.60k
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
4.80k
        for (size_t i = 1; i < num_rows; i++) {
185
3.20k
            max_key = std::max(max_key, input_keys[i]);
186
3.20k
            min_key = std::min(min_key, input_keys[i]);
187
3.20k
        }
188
1.60k
    }
189
190
1.60k
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
1.60k
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
1.60k
    if (allow_direct_mapping) {
193
1.60k
        for (const auto& variant_ptr : variant_ptrs) {
194
1.60k
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
1.60k
                    max_key, min_key);
196
1.60k
        }
197
1.60k
    }
198
1.60k
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberIN4wide7integerILm128EjEENS_13JoinHashTableIS4_NS_17HashCRC32Return32IS4_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
160
480
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
480
    using FieldType = typename Method::Base::Key;
162
480
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
480
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
480
    size_t num_rows = key_columns[0]->size();
166
480
    if (is_column_nullable(*key_columns[0])) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
480
    } else {
182
480
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
1.44k
        for (size_t i = 1; i < num_rows; i++) {
185
960
            max_key = std::max(max_key, input_keys[i]);
186
960
            min_key = std::min(min_key, input_keys[i]);
187
960
        }
188
480
    }
189
190
480
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
480
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
480
    if (allow_direct_mapping) {
193
480
        for (const auto& variant_ptr : variant_ptrs) {
194
480
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
480
                    max_key, min_key);
196
480
        }
197
480
    }
198
480
}
199
200
template <typename Method>
201
void try_convert_to_direct_mapping(
202
        Method* method, const ColumnRawPtrs& key_columns,
203
92.8k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingISt9monostateEEvPT_RKSt6vectorIPKNS_7IColumnESaIS7_EERKS4_ISt10shared_ptrINS_16JoinDataVariantsEESaISE_EE
_ZN5doris29try_convert_to_direct_mappingINS_16MethodSerializedINS_13JoinHashTableINS_9StringRefENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
28.2k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_15MethodOneNumberIN4wide7integerILm256EjEENS_13JoinHashTableIS4_NS_17HashCRC32Return32IS4_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectIhNS_13JoinHashTableIhNS_17HashCRC32Return32IhEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectItNS_13JoinHashTableItNS_17HashCRC32Return32ItEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectIjNS_13JoinHashTableIjNS_17HashCRC32Return32IjEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectImNS_13JoinHashTableImNS_17HashCRC32Return32ImEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectIN4wide7integerILm128EjEENS_13JoinHashTableIS4_NS_17HashCRC32Return32IS4_EELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableImNS_17HashCRC32Return32ImEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
203
7.84k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_6UInt72ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
6.40k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_6UInt96ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
16.0k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_7UInt104ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableIN4wide7integerILm128EjEENS_17HashCRC32Return32IS5_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
203
16.0k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_7UInt136ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
1.92k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableIN4wide7integerILm256EjEENS_17HashCRC32Return32IS5_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
203
15.8k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_19MethodStringNoCacheINS_13JoinHashTableINS_9StringRefENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
648
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
204
205
inline void try_convert_to_direct_mapping(
206
        PrimaryTypeHashTableContext<UInt8>* context, const ColumnRawPtrs& key_columns,
207
320
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
208
320
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
209
320
}
210
211
inline void try_convert_to_direct_mapping(
212
        PrimaryTypeHashTableContext<UInt16>* context, const ColumnRawPtrs& key_columns,
213
160
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
214
160
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
215
160
}
216
217
inline void try_convert_to_direct_mapping(
218
        PrimaryTypeHashTableContext<UInt32>* context, const ColumnRawPtrs& key_columns,
219
646
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
220
646
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
221
646
}
222
223
inline void try_convert_to_direct_mapping(
224
        PrimaryTypeHashTableContext<UInt64>* context, const ColumnRawPtrs& key_columns,
225
1.60k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
226
1.60k
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
227
1.60k
}
228
229
inline void try_convert_to_direct_mapping(
230
        PrimaryTypeHashTableContext<UInt128>* context, const ColumnRawPtrs& key_columns,
231
480
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
232
480
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
233
480
}
234
235
// ASOF JOIN index with inline values for cache-friendly branchless binary search.
236
// IntType is the integer representation of the ASOF column value:
237
//   uint32_t for DateV2, uint64_t for DateTimeV2 and TimestampTZ.
238
// Rows are sorted by asof_value during build, then materialized into SoA arrays
239
// so probe-side binary search only touches the ASOF values hot path.
240
template <typename IntType>
241
struct AsofIndexGroup {
242
    using int_type = IntType;
243
244
    struct Entry {
245
        IntType asof_value;
246
        uint32_t row_index; // 1-based, 0 = invalid/padding
247
    };
248
249
    std::vector<Entry> entries;
250
    std::vector<IntType> asof_values;
251
    std::vector<uint32_t> row_indexes;
252
253
2.12k
    void add_row(IntType value, uint32_t row_idx) { entries.push_back({value, row_idx}); }
_ZN5doris14AsofIndexGroupIjE7add_rowEjj
Line
Count
Source
253
2.10k
    void add_row(IntType value, uint32_t row_idx) { entries.push_back({value, row_idx}); }
_ZN5doris14AsofIndexGroupImE7add_rowEmj
Line
Count
Source
253
24
    void add_row(IntType value, uint32_t row_idx) { entries.push_back({value, row_idx}); }
254
255
46
    void sort_and_finalize() {
256
46
        if (entries.empty()) {
257
8
            return;
258
8
        }
259
38
        if (entries.size() > 1) {
260
30
            pdqsort(entries.begin(), entries.end(),
261
4.13k
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
_ZZN5doris14AsofIndexGroupIjE17sort_and_finalizeEvENKUlRKNS1_5EntryES4_E_clES4_S4_
Line
Count
Source
261
4.11k
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
_ZZN5doris14AsofIndexGroupImE17sort_and_finalizeEvENKUlRKNS1_5EntryES4_E_clES4_S4_
Line
Count
Source
261
18
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
262
30
        }
263
264
38
        asof_values.resize(entries.size());
265
38
        row_indexes.resize(entries.size());
266
2.16k
        for (size_t i = 0; i < entries.size(); ++i) {
267
2.12k
            asof_values[i] = entries[i].asof_value;
268
2.12k
            row_indexes[i] = entries[i].row_index;
269
2.12k
        }
270
271
38
        std::vector<Entry>().swap(entries);
272
38
    }
_ZN5doris14AsofIndexGroupIjE17sort_and_finalizeEv
Line
Count
Source
255
38
    void sort_and_finalize() {
256
38
        if (entries.empty()) {
257
8
            return;
258
8
        }
259
30
        if (entries.size() > 1) {
260
24
            pdqsort(entries.begin(), entries.end(),
261
24
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
262
24
        }
263
264
30
        asof_values.resize(entries.size());
265
30
        row_indexes.resize(entries.size());
266
2.13k
        for (size_t i = 0; i < entries.size(); ++i) {
267
2.10k
            asof_values[i] = entries[i].asof_value;
268
2.10k
            row_indexes[i] = entries[i].row_index;
269
2.10k
        }
270
271
30
        std::vector<Entry>().swap(entries);
272
30
    }
_ZN5doris14AsofIndexGroupImE17sort_and_finalizeEv
Line
Count
Source
255
8
    void sort_and_finalize() {
256
8
        if (entries.empty()) {
257
0
            return;
258
0
        }
259
8
        if (entries.size() > 1) {
260
6
            pdqsort(entries.begin(), entries.end(),
261
6
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
262
6
        }
263
264
8
        asof_values.resize(entries.size());
265
8
        row_indexes.resize(entries.size());
266
32
        for (size_t i = 0; i < entries.size(); ++i) {
267
24
            asof_values[i] = entries[i].asof_value;
268
24
            row_indexes[i] = entries[i].row_index;
269
24
        }
270
271
8
        std::vector<Entry>().swap(entries);
272
8
    }
273
274
2
    const IntType* values_data() const { return asof_values.data(); }
_ZNK5doris14AsofIndexGroupIjE11values_dataEv
Line
Count
Source
274
2
    const IntType* values_data() const { return asof_values.data(); }
Unexecuted instantiation: _ZNK5doris14AsofIndexGroupImE11values_dataEv
275
276
    // Branchless lower_bound: first i where asof_values[i] >= target
277
78
    ALWAYS_INLINE size_t lower_bound(IntType target) const {
278
78
        size_t lo = 0, n = asof_values.size();
279
362
        while (n > 1) {
280
284
            size_t half = n / 2;
281
284
            lo += half * (asof_values[lo + half] < target);
282
284
            n -= half;
283
284
        }
284
78
        if (lo < asof_values.size()) {
285
76
            lo += (asof_values[lo] < target);
286
76
        }
287
78
        return lo;
288
78
    }
_ZNK5doris14AsofIndexGroupIjE11lower_boundEj
Line
Count
Source
277
66
    ALWAYS_INLINE size_t lower_bound(IntType target) const {
278
66
        size_t lo = 0, n = asof_values.size();
279
326
        while (n > 1) {
280
260
            size_t half = n / 2;
281
260
            lo += half * (asof_values[lo + half] < target);
282
260
            n -= half;
283
260
        }
284
66
        if (lo < asof_values.size()) {
285
64
            lo += (asof_values[lo] < target);
286
64
        }
287
66
        return lo;
288
66
    }
_ZNK5doris14AsofIndexGroupImE11lower_boundEm
Line
Count
Source
277
12
    ALWAYS_INLINE size_t lower_bound(IntType target) const {
278
12
        size_t lo = 0, n = asof_values.size();
279
36
        while (n > 1) {
280
24
            size_t half = n / 2;
281
24
            lo += half * (asof_values[lo + half] < target);
282
24
            n -= half;
283
24
        }
284
12
        if (lo < asof_values.size()) {
285
12
            lo += (asof_values[lo] < target);
286
12
        }
287
12
        return lo;
288
12
    }
289
290
    // Branchless upper_bound: first i where asof_values[i] > target
291
88
    ALWAYS_INLINE size_t upper_bound(IntType target) const {
292
88
        size_t lo = 0, n = asof_values.size();
293
452
        while (n > 1) {
294
364
            size_t half = n / 2;
295
364
            lo += half * (asof_values[lo + half] <= target);
296
364
            n -= half;
297
364
        }
298
88
        if (lo < asof_values.size()) {
299
86
            lo += (asof_values[lo] <= target);
300
86
        }
301
88
        return lo;
302
88
    }
_ZNK5doris14AsofIndexGroupIjE11upper_boundEj
Line
Count
Source
291
76
    ALWAYS_INLINE size_t upper_bound(IntType target) const {
292
76
        size_t lo = 0, n = asof_values.size();
293
416
        while (n > 1) {
294
340
            size_t half = n / 2;
295
340
            lo += half * (asof_values[lo + half] <= target);
296
340
            n -= half;
297
340
        }
298
76
        if (lo < asof_values.size()) {
299
74
            lo += (asof_values[lo] <= target);
300
74
        }
301
76
        return lo;
302
76
    }
_ZNK5doris14AsofIndexGroupImE11upper_boundEm
Line
Count
Source
291
12
    ALWAYS_INLINE size_t upper_bound(IntType target) const {
292
12
        size_t lo = 0, n = asof_values.size();
293
36
        while (n > 1) {
294
24
            size_t half = n / 2;
295
24
            lo += half * (asof_values[lo + half] <= target);
296
24
            n -= half;
297
24
        }
298
12
        if (lo < asof_values.size()) {
299
12
            lo += (asof_values[lo] <= target);
300
12
        }
301
12
        return lo;
302
12
    }
303
304
    // Semantics by (is_greater, is_strict):
305
    //   (true,  false): probe >= build  ->  find largest  build value <= probe
306
    //   (true,  true):  probe >  build  ->  find largest  build value <  probe
307
    //   (false, false): probe <= build  ->  find smallest build value >= probe
308
    //   (false, true):  probe <  build  ->  find smallest build value >  probe
309
    // Returns the build row index of the best match, or 0 if no match.
310
    template <bool IsGreater, bool IsStrict>
311
138
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
138
        if (asof_values.empty()) {
313
8
            return 0;
314
8
        }
315
130
        if constexpr (IsGreater) {
316
68
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
68
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
68
        } else {
319
62
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
62
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
62
        }
322
130
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb1ELb0EEEjj
Line
Count
Source
311
38
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
38
        if (asof_values.empty()) {
313
2
            return 0;
314
2
        }
315
36
        if constexpr (IsGreater) {
316
36
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
36
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
36
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb1ELb1EEEjj
Line
Count
Source
311
30
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
30
        if (asof_values.empty()) {
313
2
            return 0;
314
2
        }
315
28
        if constexpr (IsGreater) {
316
28
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
28
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
28
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb0ELb0EEEjj
Line
Count
Source
311
30
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
30
        if (asof_values.empty()) {
313
2
            return 0;
314
2
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
28
        } else {
319
28
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
28
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
28
        }
322
28
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb0ELb1EEEjj
Line
Count
Source
311
32
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
32
        if (asof_values.empty()) {
313
2
            return 0;
314
2
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
30
        } else {
319
30
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
30
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
30
        }
322
30
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb1ELb0EEEjm
Line
Count
Source
311
2
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
2
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
2
        if constexpr (IsGreater) {
316
2
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
2
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
2
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb1ELb1EEEjm
Line
Count
Source
311
2
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
2
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
2
        if constexpr (IsGreater) {
316
2
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
2
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
2
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb0ELb0EEEjm
Line
Count
Source
311
2
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
2
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
2
        } else {
319
2
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
2
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
2
        }
322
2
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb0ELb1EEEjm
Line
Count
Source
311
2
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
2
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
2
        } else {
319
2
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
2
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
2
        }
322
2
    }
323
};
324
325
// Type-erased container for all ASOF index groups.
326
// DateV2 -> uint32_t, DateTimeV2/TimestampTZ -> uint64_t.
327
using AsofIndexVariant = std::variant<std::monostate, std::vector<AsofIndexGroup<uint32_t>>,
328
                                      std::vector<AsofIndexGroup<uint64_t>>>;
329
330
} // namespace doris