Coverage Report

Created: 2026-03-15 08:11

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