Coverage Report

Created: 2026-04-09 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vexpr.cpp
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
#include "exprs/vexpr.h"
19
20
#include <fmt/format.h>
21
#include <gen_cpp/Exprs_types.h>
22
#include <gen_cpp/FrontendService_types.h>
23
#include <thrift/protocol/TDebugProtocol.h>
24
25
#include <algorithm>
26
#include <boost/algorithm/string/split.hpp>
27
#include <boost/iterator/iterator_facade.hpp>
28
#include <cstdint>
29
#include <memory>
30
#include <stack>
31
#include <string_view>
32
#include <utility>
33
34
#include "common/config.h"
35
#include "common/exception.h"
36
#include "common/status.h"
37
#include "core/column/column_vector.h"
38
#include "core/data_type/data_type_array.h"
39
#include "core/data_type/data_type_decimal.h"
40
#include "core/data_type/data_type_factory.hpp"
41
#include "core/data_type/data_type_nullable.h"
42
#include "core/data_type/data_type_number.h"
43
#include "core/data_type/define_primitive_type.h"
44
#include "core/field.h"
45
#include "core/value/timestamptz_value.h"
46
#include "exec/common/util.hpp"
47
#include "exec/pipeline/pipeline_task.h"
48
#include "exprs/short_circuit_evaluation_expr.h"
49
#include "exprs/varray_literal.h"
50
#include "exprs/vcase_expr.h"
51
#include "exprs/vcast_expr.h"
52
#include "exprs/vcolumn_ref.h"
53
#include "exprs/vcompound_pred.h"
54
#include "exprs/vcondition_expr.h"
55
#include "exprs/vectorized_fn_call.h"
56
#include "exprs/vexpr_context.h"
57
#include "exprs/vexpr_fwd.h"
58
#include "exprs/vin_predicate.h"
59
#include "exprs/vinfo_func.h"
60
#include "exprs/virtual_slot_ref.h"
61
#include "exprs/vlambda_function_call_expr.h"
62
#include "exprs/vlambda_function_expr.h"
63
#include "exprs/vliteral.h"
64
#include "exprs/vmap_literal.h"
65
#include "exprs/vmatch_predicate.h"
66
#include "exprs/vsearch.h"
67
#include "exprs/vslot_ref.h"
68
#include "exprs/vstruct_literal.h"
69
#include "storage/index/ann/ann_search_params.h"
70
#include "storage/index/ann/ann_topn_runtime.h"
71
#include "storage/index/inverted/inverted_index_parser.h"
72
#include "storage/segment/column_reader.h"
73
74
namespace doris {
75
#include "common/compile_check_begin.h"
76
77
class RowDescriptor;
78
class RuntimeState;
79
80
// NOLINTBEGIN(readability-function-cognitive-complexity)
81
// NOLINTBEGIN(readability-function-size)
82
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision,
83
4.25k
                                 int scale) {
84
4.25k
    TExprNode node;
85
86
4.25k
    switch (type) {
87
48
    case TYPE_BOOLEAN: {
88
48
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BOOLEAN>(data, &node));
89
48
        break;
90
48
    }
91
48
    case TYPE_TINYINT: {
92
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TINYINT>(data, &node));
93
0
        break;
94
0
    }
95
0
    case TYPE_SMALLINT: {
96
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_SMALLINT>(data, &node));
97
0
        break;
98
0
    }
99
2.24k
    case TYPE_INT: {
100
2.24k
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_INT>(data, &node));
101
2.24k
        break;
102
2.24k
    }
103
2.24k
    case TYPE_BIGINT: {
104
696
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BIGINT>(data, &node));
105
696
        break;
106
696
    }
107
696
    case TYPE_LARGEINT: {
108
8
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_LARGEINT>(data, &node));
109
8
        break;
110
8
    }
111
64
    case TYPE_FLOAT: {
112
64
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_FLOAT>(data, &node));
113
64
        break;
114
64
    }
115
64
    case TYPE_DOUBLE: {
116
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DOUBLE>(data, &node));
117
0
        break;
118
0
    }
119
72
    case TYPE_DATEV2: {
120
72
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATEV2>(data, &node));
121
72
        break;
122
72
    }
123
168
    case TYPE_DATETIMEV2: {
124
168
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATETIMEV2>(data, &node, precision, scale));
125
168
        break;
126
168
    }
127
168
    case TYPE_DATE: {
128
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATE>(data, &node));
129
0
        break;
130
0
    }
131
0
    case TYPE_DATETIME: {
132
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATETIME>(data, &node));
133
0
        break;
134
0
    }
135
0
    case TYPE_DECIMALV2: {
136
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMALV2>(data, &node, precision, scale));
137
0
        break;
138
0
    }
139
0
    case TYPE_DECIMAL32: {
140
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL32>(data, &node, precision, scale));
141
0
        break;
142
0
    }
143
204
    case TYPE_DECIMAL64: {
144
204
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL64>(data, &node, precision, scale));
145
204
        break;
146
204
    }
147
204
    case TYPE_DECIMAL128I: {
148
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL128I>(data, &node, precision, scale));
149
0
        break;
150
0
    }
151
0
    case TYPE_DECIMAL256: {
152
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL256>(data, &node, precision, scale));
153
0
        break;
154
0
    }
155
0
    case TYPE_CHAR: {
156
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_CHAR>(data, &node));
157
0
        break;
158
0
    }
159
16
    case TYPE_VARCHAR: {
160
16
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_VARCHAR>(data, &node));
161
16
        break;
162
16
    }
163
747
    case TYPE_STRING: {
164
747
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_STRING>(data, &node));
165
747
        break;
166
747
    }
167
747
    case TYPE_IPV4: {
168
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_IPV4>(data, &node));
169
0
        break;
170
0
    }
171
0
    case TYPE_IPV6: {
172
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_IPV6>(data, &node));
173
0
        break;
174
0
    }
175
0
    case TYPE_TIMEV2: {
176
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TIMEV2>(data, &node, precision, scale));
177
0
        break;
178
0
    }
179
1
    case TYPE_TIMESTAMPTZ: {
180
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TIMESTAMPTZ>(data, &node, precision, scale));
181
1
        break;
182
1
    }
183
1
    default:
184
0
        throw Exception(ErrorCode::INTERNAL_ERROR, "runtime filter meet invalid type {}",
185
0
                        int(type));
186
4.25k
    }
187
4.25k
    return node;
188
4.25k
}
189
190
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
191
1.64k
                                 int scale) {
192
1.64k
    TExprNode node;
193
1.64k
    switch (type) {
194
1
    case TYPE_BOOLEAN: {
195
1
        const auto& storage = static_cast<bool>(field.get<TYPE_BOOLEAN>());
196
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BOOLEAN>(&storage, &node));
197
1
        break;
198
1
    }
199
1
    case TYPE_TINYINT: {
200
0
        const auto& storage = static_cast<int8_t>(field.get<TYPE_TINYINT>());
201
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TINYINT>(&storage, &node));
202
0
        break;
203
0
    }
204
1
    case TYPE_SMALLINT: {
205
1
        const auto& storage = static_cast<int16_t>(field.get<TYPE_SMALLINT>());
206
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_SMALLINT>(&storage, &node));
207
1
        break;
208
1
    }
209
131
    case TYPE_INT: {
210
131
        const auto& storage = static_cast<int32_t>(field.get<TYPE_INT>());
211
131
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_INT>(&storage, &node));
212
131
        break;
213
131
    }
214
131
    case TYPE_BIGINT: {
215
61
        const auto& storage = static_cast<int64_t>(field.get<TYPE_BIGINT>());
216
61
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BIGINT>(&storage, &node));
217
61
        break;
218
61
    }
219
61
    case TYPE_LARGEINT: {
220
1
        const auto& storage = static_cast<int128_t>(field.get<TYPE_LARGEINT>());
221
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_LARGEINT>(&storage, &node));
222
1
        break;
223
1
    }
224
1
    case TYPE_FLOAT: {
225
1
        const auto& storage = static_cast<float>(field.get<TYPE_FLOAT>());
226
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_FLOAT>(&storage, &node));
227
1
        break;
228
1
    }
229
1
    case TYPE_DOUBLE: {
230
1
        const auto& storage = static_cast<double>(field.get<TYPE_DOUBLE>());
231
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DOUBLE>(&storage, &node));
232
1
        break;
233
1
    }
234
1
    case TYPE_DATEV2: {
235
1
        const auto& storage = field.get<TYPE_DATEV2>();
236
237
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATEV2>(&storage, &node));
238
1
        break;
239
1
    }
240
1
    case TYPE_DATETIMEV2: {
241
1
        const auto& storage = field.get<TYPE_DATETIMEV2>();
242
1
        THROW_IF_ERROR(
243
1
                create_texpr_literal_node<TYPE_DATETIMEV2>(&storage, &node, precision, scale));
244
1
        break;
245
1
    }
246
1
    case TYPE_TIMESTAMPTZ: {
247
1
        const auto& storage = field.get<TYPE_TIMESTAMPTZ>();
248
249
1
        THROW_IF_ERROR(
250
1
                create_texpr_literal_node<TYPE_TIMESTAMPTZ>(&storage, &node, precision, scale));
251
1
        break;
252
1
    }
253
1
    case TYPE_DATE: {
254
1
        const auto& storage = field.get<TYPE_DATE>();
255
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATE>(&storage, &node));
256
1
        break;
257
1
    }
258
1
    case TYPE_DATETIME: {
259
1
        const auto& storage = field.get<TYPE_DATETIME>();
260
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATETIME>(&storage, &node));
261
1
        break;
262
1
    }
263
1
    case TYPE_DECIMALV2: {
264
1
        const auto& storage = field.get<TYPE_DECIMALV2>();
265
266
1
        THROW_IF_ERROR(
267
1
                create_texpr_literal_node<TYPE_DECIMALV2>(&storage, &node, precision, scale));
268
1
        break;
269
1
    }
270
2
    case TYPE_DECIMAL32: {
271
2
        const auto& storage = field.get<TYPE_DECIMAL32>();
272
2
        THROW_IF_ERROR(
273
2
                create_texpr_literal_node<TYPE_DECIMAL32>(&storage, &node, precision, scale));
274
2
        break;
275
2
    }
276
1.34k
    case TYPE_DECIMAL64: {
277
1.34k
        const auto& storage = field.get<TYPE_DECIMAL64>();
278
1.34k
        THROW_IF_ERROR(
279
1.34k
                create_texpr_literal_node<TYPE_DECIMAL64>(&storage, &node, precision, scale));
280
1.34k
        break;
281
1.34k
    }
282
1.34k
    case TYPE_DECIMAL128I: {
283
2
        const auto& storage = field.get<TYPE_DECIMAL128I>();
284
2
        THROW_IF_ERROR(
285
2
                create_texpr_literal_node<TYPE_DECIMAL128I>(&storage, &node, precision, scale));
286
2
        break;
287
2
    }
288
2
    case TYPE_DECIMAL256: {
289
2
        const auto& storage = field.get<TYPE_DECIMAL256>();
290
2
        THROW_IF_ERROR(
291
2
                create_texpr_literal_node<TYPE_DECIMAL256>(&storage, &node, precision, scale));
292
2
        break;
293
2
    }
294
34
    case TYPE_CHAR: {
295
34
        const auto& storage = field.get<TYPE_CHAR>();
296
34
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_CHAR>(&storage, &node));
297
34
        break;
298
34
    }
299
34
    case TYPE_VARCHAR: {
300
34
        const auto& storage = field.get<TYPE_VARCHAR>();
301
34
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_VARCHAR>(&storage, &node));
302
34
        break;
303
34
    }
304
34
    case TYPE_STRING: {
305
23
        const auto& storage = field.get<TYPE_STRING>();
306
23
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_STRING>(&storage, &node));
307
23
        break;
308
23
    }
309
23
    case TYPE_IPV4: {
310
0
        const auto& storage = field.get<TYPE_IPV4>();
311
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_IPV4>(&storage, &node));
312
0
        break;
313
0
    }
314
0
    case TYPE_IPV6: {
315
0
        const auto& storage = field.get<TYPE_IPV6>();
316
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_IPV6>(&storage, &node));
317
0
        break;
318
0
    }
319
1
    case TYPE_TIMEV2: {
320
1
        const auto& storage = field.get<TYPE_TIMEV2>();
321
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TIMEV2>(&storage, &node));
322
1
        break;
323
1
    }
324
1
    case TYPE_VARBINARY: {
325
0
        const auto& svf = field.get<TYPE_VARBINARY>();
326
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_VARBINARY>(&svf, &node));
327
0
        break;
328
0
    }
329
0
    default:
330
0
        throw Exception(ErrorCode::INTERNAL_ERROR, "runtime filter meet invalid type {}",
331
0
                        int(type));
332
1.64k
    }
333
1.64k
    return node;
334
1.64k
}
335
336
// NOLINTEND(readability-function-size)
337
// NOLINTEND(readability-function-cognitive-complexity)
338
} // namespace doris
339
340
namespace doris {
341
342
66
bool VExpr::is_acting_on_a_slot(const VExpr& expr) {
343
66
    if (expr.node_type() == TExprNodeType::SEARCH_EXPR) {
344
0
        return true;
345
0
    }
346
66
    const auto& children = expr.children();
347
348
66
    auto is_a_slot = std::any_of(children.begin(), children.end(),
349
66
                                 [](const auto& child) { return is_acting_on_a_slot(*child); });
350
351
66
    return is_a_slot ? true
352
66
                     : (expr.node_type() == TExprNodeType::SLOT_REF ||
353
22
                        expr.node_type() == TExprNodeType::VIRTUAL_SLOT_REF);
354
66
}
355
356
VExpr::VExpr(const TExprNode& node)
357
3.26M
        : _node_type(node.node_type),
358
3.26M
          _opcode(node.__isset.opcode ? node.opcode : TExprOpcode::INVALID_OPCODE) {
359
3.26M
    if (node.__isset.fn) {
360
235k
        _fn = node.fn;
361
235k
    }
362
363
3.26M
    bool is_nullable = true;
364
3.26M
    if (node.__isset.is_nullable) {
365
3.25M
        is_nullable = node.is_nullable;
366
3.25M
    }
367
    // If we define null literal ,should make nullable data type to get correct field instead of undefined ptr
368
3.26M
    if (node.node_type == TExprNodeType::NULL_LITERAL) {
369
293k
        CHECK(is_nullable);
370
293k
    }
371
3.26M
    _data_type = get_data_type_with_default_argument(
372
3.26M
            DataTypeFactory::instance().create_data_type(node.type, is_nullable));
373
3.26M
}
374
375
0
VExpr::VExpr(const VExpr& vexpr) = default;
376
377
VExpr::VExpr(DataTypePtr type, bool is_slotref)
378
534
        : _opcode(TExprOpcode::INVALID_OPCODE),
379
534
          _data_type(get_data_type_with_default_argument(type)) {
380
534
    if (is_slotref) {
381
525
        _node_type = TExprNodeType::SLOT_REF;
382
525
    }
383
534
}
384
385
3.10M
Status VExpr::prepare(RuntimeState* state, const RowDescriptor& row_desc, VExprContext* context) {
386
3.10M
    ++context->_depth_num;
387
3.10M
    if (context->_depth_num > config::max_depth_of_expr_tree) {
388
0
        return Status::Error<ErrorCode::EXCEEDED_LIMIT>(
389
0
                "The depth of the expression tree is too big, make it less than {}",
390
0
                config::max_depth_of_expr_tree);
391
0
    }
392
393
3.10M
    for (auto& i : _children) {
394
507k
        RETURN_IF_ERROR(i->prepare(state, row_desc, context));
395
507k
    }
396
3.10M
    --context->_depth_num;
397
3.10M
#ifndef BE_TEST
398
3.10M
    _enable_inverted_index_query = state->query_options().enable_inverted_index_query;
399
3.10M
#endif
400
3.10M
    return Status::OK();
401
3.10M
}
402
403
Status VExpr::open(RuntimeState* state, VExprContext* context,
404
10.7M
                   FunctionContext::FunctionStateScope scope) {
405
10.7M
    for (auto& i : _children) {
406
71.6k
        RETURN_IF_ERROR(i->open(state, context, scope));
407
71.6k
    }
408
10.7M
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
409
2.84M
        RETURN_IF_ERROR(VExpr::get_const_col(context, nullptr));
410
2.84M
    }
411
10.7M
    return Status::OK();
412
10.7M
}
413
414
11.3M
void VExpr::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
415
11.3M
    for (auto& i : _children) {
416
1.19M
        i->close(context, scope);
417
1.19M
    }
418
11.3M
}
419
420
// NOLINTBEGIN(readability-function-size)
421
3.24M
Status VExpr::create_expr(const TExprNode& expr_node, VExprSPtr& expr) {
422
3.24M
    try {
423
3.24M
        switch (expr_node.node_type) {
424
1.97k
        case TExprNodeType::BOOL_LITERAL:
425
112k
        case TExprNodeType::INT_LITERAL:
426
112k
        case TExprNodeType::LARGE_INT_LITERAL:
427
112k
        case TExprNodeType::IPV4_LITERAL:
428
112k
        case TExprNodeType::IPV6_LITERAL:
429
117k
        case TExprNodeType::FLOAT_LITERAL:
430
126k
        case TExprNodeType::DECIMAL_LITERAL:
431
135k
        case TExprNodeType::DATE_LITERAL:
432
135k
        case TExprNodeType::TIMEV2_LITERAL:
433
328k
        case TExprNodeType::STRING_LITERAL:
434
328k
        case TExprNodeType::JSON_LITERAL:
435
328k
        case TExprNodeType::VARBINARY_LITERAL:
436
622k
        case TExprNodeType::NULL_LITERAL: {
437
622k
            expr = VLiteral::create_shared(expr_node);
438
622k
            break;
439
328k
        }
440
6.35k
        case TExprNodeType::ARRAY_LITERAL: {
441
6.35k
            expr = VArrayLiteral::create_shared(expr_node);
442
6.35k
            break;
443
328k
        }
444
94
        case TExprNodeType::MAP_LITERAL: {
445
94
            expr = VMapLiteral::create_shared(expr_node);
446
94
            break;
447
328k
        }
448
142
        case TExprNodeType::STRUCT_LITERAL: {
449
142
            expr = VStructLiteral::create_shared(expr_node);
450
142
            break;
451
328k
        }
452
2.36M
        case TExprNodeType::SLOT_REF: {
453
2.36M
            if (expr_node.slot_ref.__isset.is_virtual_slot && expr_node.slot_ref.is_virtual_slot) {
454
11
                expr = VirtualSlotRef::create_shared(expr_node);
455
11
                expr->_node_type = TExprNodeType::VIRTUAL_SLOT_REF;
456
2.36M
            } else {
457
2.36M
                expr = VSlotRef::create_shared(expr_node);
458
2.36M
            }
459
2.36M
            break;
460
328k
        }
461
0
        case TExprNodeType::COLUMN_REF: {
462
0
            expr = VColumnRef::create_shared(expr_node);
463
0
            break;
464
328k
        }
465
467
        case TExprNodeType::COMPOUND_PRED: {
466
467
            expr = VCompoundPred::create_shared(expr_node);
467
467
            break;
468
328k
        }
469
0
        case TExprNodeType::LAMBDA_FUNCTION_EXPR: {
470
0
            expr = VLambdaFunctionExpr::create_shared(expr_node);
471
0
            break;
472
328k
        }
473
0
        case TExprNodeType::LAMBDA_FUNCTION_CALL_EXPR: {
474
0
            expr = VLambdaFunctionCallExpr::create_shared(expr_node);
475
0
            break;
476
328k
        }
477
8.32k
        case TExprNodeType::ARITHMETIC_EXPR:
478
196k
        case TExprNodeType::BINARY_PRED:
479
196k
        case TExprNodeType::NULL_AWARE_BINARY_PRED:
480
196k
        case TExprNodeType::COMPUTE_FUNCTION_CALL: {
481
196k
            expr = VectorizedFnCall::create_shared(expr_node);
482
196k
            break;
483
196k
        }
484
33.5k
        case TExprNodeType::FUNCTION_CALL: {
485
33.5k
            if (expr_node.fn.name.function_name == "if") {
486
2.00k
                if (expr_node.__isset.short_circuit_evaluation &&
487
2.00k
                    expr_node.short_circuit_evaluation) {
488
0
                    expr = ShortCircuitIfExpr::create_shared(expr_node);
489
2.00k
                } else {
490
2.00k
                    expr = VectorizedIfExpr::create_shared(expr_node);
491
2.00k
                }
492
2.00k
                break;
493
31.5k
            } else if (expr_node.fn.name.function_name == "ifnull" ||
494
31.5k
                       expr_node.fn.name.function_name == "nvl") {
495
46
                if (expr_node.__isset.short_circuit_evaluation &&
496
46
                    expr_node.short_circuit_evaluation) {
497
0
                    expr = ShortCircuitIfNullExpr::create_shared(expr_node);
498
46
                } else {
499
46
                    expr = VectorizedIfNullExpr::create_shared(expr_node);
500
46
                }
501
46
                break;
502
31.5k
            } else if (expr_node.fn.name.function_name == "coalesce") {
503
14
                if (expr_node.__isset.short_circuit_evaluation &&
504
14
                    expr_node.short_circuit_evaluation) {
505
0
                    expr = ShortCircuitCoalesceExpr::create_shared(expr_node);
506
14
                } else {
507
14
                    expr = VectorizedCoalesceExpr::create_shared(expr_node);
508
14
                }
509
14
                break;
510
14
            }
511
31.4k
            expr = VectorizedFnCall::create_shared(expr_node);
512
31.4k
            break;
513
33.5k
        }
514
0
        case TExprNodeType::MATCH_PRED: {
515
0
            expr = VMatchPredicate::create_shared(expr_node);
516
0
            break;
517
33.5k
        }
518
19.4k
        case TExprNodeType::CAST_EXPR: {
519
19.4k
            expr = VCastExpr::create_shared(expr_node);
520
19.4k
            break;
521
33.5k
        }
522
0
        case TExprNodeType::TRY_CAST_EXPR: {
523
0
            expr = TryCastExpr::create_shared(expr_node);
524
0
            break;
525
33.5k
        }
526
645
        case TExprNodeType::IN_PRED: {
527
645
            expr = VInPredicate::create_shared(expr_node);
528
645
            break;
529
33.5k
        }
530
18
        case TExprNodeType::CASE_EXPR: {
531
18
            if (!expr_node.__isset.case_expr) {
532
0
                return Status::InternalError("Case expression not set in thrift node");
533
0
            }
534
18
            if (expr_node.__isset.short_circuit_evaluation && expr_node.short_circuit_evaluation) {
535
0
                expr = ShortCircuitCaseExpr::create_shared(expr_node);
536
18
            } else {
537
18
                expr = VCaseExpr::create_shared(expr_node);
538
18
            }
539
18
            break;
540
18
        }
541
0
        case TExprNodeType::INFO_FUNC: {
542
0
            expr = VInfoFunc::create_shared(expr_node);
543
0
            break;
544
18
        }
545
0
        case TExprNodeType::SEARCH_EXPR: {
546
0
            expr = VSearchExpr::create_shared(expr_node);
547
0
            break;
548
18
        }
549
0
        default:
550
0
            return Status::InternalError("Unknown expr node type: {}", expr_node.node_type);
551
3.24M
        }
552
3.24M
    } catch (const Exception& e) {
553
0
        if (e.code() == ErrorCode::INTERNAL_ERROR) {
554
0
            return Status::InternalError("Create Expr failed because {}\nTExprNode={}", e.what(),
555
0
                                         apache::thrift::ThriftDebugString(expr_node));
556
0
        }
557
0
        return Status::Error<false>(e.code(), "Create Expr failed because {}", e.what());
558
0
        LOG(WARNING) << "create expr failed, TExprNode={}, reason={}"
559
0
                     << apache::thrift::ThriftDebugString(expr_node) << e.what();
560
0
    }
561
3.25M
    if (!expr->data_type()) {
562
0
        return Status::InvalidArgument("Unknown expr type: {}", expr_node.node_type);
563
0
    }
564
3.25M
    return Status::OK();
565
3.25M
}
566
// NOLINTEND(readability-function-size)
567
568
Status VExpr::create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
569
2.74M
                                      VExprSPtr& root_expr, VExprContextSPtr& ctx) {
570
    // propagate error case
571
2.74M
    if (*node_idx >= nodes.size()) {
572
0
        return Status::InternalError("Failed to reconstruct expression tree from thrift.");
573
0
    }
574
575
    // create root expr
576
2.74M
    int root_children = nodes[*node_idx].num_children;
577
2.74M
    VExprSPtr root;
578
2.74M
    RETURN_IF_ERROR(create_expr(nodes[*node_idx], root));
579
2.74M
    DCHECK(root != nullptr);
580
2.74M
    root_expr = root;
581
2.74M
    ctx = std::make_shared<VExprContext>(root);
582
    // short path for leaf node
583
2.74M
    if (root_children <= 0) {
584
2.52M
        return Status::OK();
585
2.52M
    }
586
587
    // non-recursive traversal
588
223k
    using VExprSPtrCountPair = std::pair<VExprSPtr, int>;
589
223k
    std::stack<std::shared_ptr<VExprSPtrCountPair>> s;
590
223k
    s.emplace(std::make_shared<VExprSPtrCountPair>(root, root_children));
591
723k
    while (!s.empty()) {
592
        // copy the shared ptr resource to avoid dangling reference
593
499k
        auto parent = s.top();
594
        // Decrement or pop
595
499k
        if (parent->second > 1) {
596
243k
            parent->second -= 1;
597
255k
        } else {
598
255k
            s.pop();
599
255k
        }
600
601
499k
        DCHECK(parent->first != nullptr);
602
499k
        if (++*node_idx >= nodes.size()) {
603
0
            return Status::InternalError("Failed to reconstruct expression tree from thrift.");
604
0
        }
605
606
499k
        VExprSPtr expr;
607
499k
        RETURN_IF_ERROR(create_expr(nodes[*node_idx], expr));
608
499k
        DCHECK(expr != nullptr);
609
499k
        parent->first->add_child(expr);
610
        // push to stack if has children
611
499k
        int num_children = nodes[*node_idx].num_children;
612
499k
        if (num_children > 0) {
613
29.9k
            s.emplace(std::make_shared<VExprSPtrCountPair>(expr, num_children));
614
29.9k
        }
615
499k
    }
616
223k
    return Status::OK();
617
223k
}
618
619
2.70M
Status VExpr::create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx) {
620
2.70M
    if (texpr.nodes.empty()) {
621
7
        ctx = nullptr;
622
7
        return Status::OK();
623
7
    }
624
2.70M
    int node_idx = 0;
625
2.70M
    VExprSPtr e;
626
2.70M
    Status status = create_tree_from_thrift(texpr.nodes, &node_idx, e, ctx);
627
2.71M
    if (status.ok() && node_idx + 1 != texpr.nodes.size()) {
628
0
        status = Status::InternalError(
629
0
                "Expression tree only partially reconstructed. Not all thrift nodes were "
630
0
                "used.");
631
0
    }
632
2.70M
    if (!status.ok()) {
633
0
        LOG(ERROR) << "Could not construct expr tree.\n"
634
0
                   << status << "\n"
635
0
                   << apache::thrift::ThriftDebugString(texpr);
636
0
    }
637
2.70M
    return status;
638
2.70M
}
639
640
263k
Status VExpr::create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs) {
641
263k
    ctxs.clear();
642
1.89M
    for (const auto& texpr : texprs) {
643
1.89M
        VExprContextSPtr ctx;
644
1.89M
        RETURN_IF_ERROR(create_expr_tree(texpr, ctx));
645
1.89M
        ctxs.push_back(ctx);
646
1.89M
    }
647
263k
    return Status::OK();
648
263k
}
649
650
Status VExpr::check_expr_output_type(const VExprContextSPtrs& ctxs,
651
98.5k
                                     const RowDescriptor& output_row_desc) {
652
98.5k
    if (ctxs.empty()) {
653
6
        return Status::OK();
654
6
    }
655
98.5k
    auto name_and_types = VectorizedUtils::create_name_and_data_types(output_row_desc);
656
98.5k
    if (ctxs.size() != name_and_types.size()) {
657
0
        return Status::InternalError(
658
0
                "output type size not match expr size {} , expected output size {} ", ctxs.size(),
659
0
                name_and_types.size());
660
0
    }
661
858k
    auto check_type_can_be_converted = [](DataTypePtr& from, DataTypePtr& to) -> bool {
662
858k
        if (to->equals(*from)) {
663
858k
            return true;
664
858k
        }
665
484
        if (to->is_nullable() && !from->is_nullable()) {
666
0
            return remove_nullable(to)->equals(*from);
667
0
        }
668
484
        return false;
669
484
    };
670
957k
    for (int i = 0; i < ctxs.size(); i++) {
671
858k
        auto real_expr_type = get_data_type_with_default_argument(ctxs[i]->root()->data_type());
672
858k
        auto&& [name, expected_type] = name_and_types[i];
673
858k
        if (!check_type_can_be_converted(real_expr_type, expected_type)) {
674
0
            return Status::InternalError(
675
0
                    "output type not match expr type, col name {} , expected type {} , real type "
676
0
                    "{}",
677
0
                    name, expected_type->get_name(), real_expr_type->get_name());
678
0
        }
679
858k
    }
680
98.5k
    return Status::OK();
681
98.5k
}
682
683
Status VExpr::prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
684
517k
                      const RowDescriptor& row_desc) {
685
2.12M
    for (auto ctx : ctxs) {
686
2.12M
        RETURN_IF_ERROR(ctx->prepare(state, row_desc));
687
2.12M
    }
688
517k
    return Status::OK();
689
517k
}
690
691
520k
Status VExpr::open(const VExprContextSPtrs& ctxs, RuntimeState* state) {
692
2.11M
    for (const auto& ctx : ctxs) {
693
2.11M
        RETURN_IF_ERROR(ctx->open(state));
694
2.11M
    }
695
520k
    return Status::OK();
696
520k
}
697
698
414k
bool VExpr::contains_blockable_function(const VExprContextSPtrs& ctxs) {
699
1.04M
    return std::any_of(ctxs.begin(), ctxs.end(), [](const VExprContextSPtr& ctx) {
700
1.04M
        return ctx != nullptr && ctx->root() != nullptr && ctx->root()->is_blockable();
701
1.04M
    });
702
414k
}
703
704
Status VExpr::clone_if_not_exists(const VExprContextSPtrs& ctxs, RuntimeState* state,
705
0
                                  VExprContextSPtrs& new_ctxs) {
706
0
    if (!new_ctxs.empty()) {
707
        // 'ctxs' was already cloned into '*new_ctxs', nothing to do.
708
0
        DCHECK_EQ(new_ctxs.size(), ctxs.size());
709
0
        for (auto& new_ctx : new_ctxs) {
710
0
            DCHECK(new_ctx->_is_clone);
711
0
        }
712
0
        return Status::OK();
713
0
    }
714
0
    new_ctxs.resize(ctxs.size());
715
0
    for (int i = 0; i < ctxs.size(); ++i) {
716
0
        RETURN_IF_ERROR(ctxs[i]->clone(state, new_ctxs[i]));
717
0
    }
718
0
    return Status::OK();
719
0
}
720
721
811
std::string VExpr::debug_string() const {
722
    // TODO: implement partial debug string for member vars
723
811
    std::stringstream out;
724
811
    out << " type=" << _data_type->get_name();
725
726
811
    if (!_children.empty()) {
727
152
        out << " children=" << debug_string(_children);
728
152
    }
729
730
811
    return out.str();
731
811
}
732
733
152
std::string VExpr::debug_string(const VExprSPtrs& exprs) {
734
152
    std::stringstream out;
735
152
    out << "[";
736
737
304
    for (int i = 0; i < exprs.size(); ++i) {
738
152
        out << (i == 0 ? "" : " ") << exprs[i]->debug_string();
739
152
    }
740
741
152
    out << "]";
742
152
    return out.str();
743
152
}
744
745
0
std::string VExpr::debug_string(const VExprContextSPtrs& ctxs) {
746
0
    VExprSPtrs exprs;
747
0
    for (const auto& ctx : ctxs) {
748
0
        exprs.push_back(ctx->root());
749
0
    }
750
0
    return debug_string(exprs);
751
0
}
752
753
2.11M
bool VExpr::is_constant() const {
754
2.11M
    return std::all_of(_children.begin(), _children.end(),
755
2.11M
                       [](const VExprSPtr& expr) { return expr->is_constant(); });
756
2.11M
}
757
758
Status VExpr::get_const_col(VExprContext* context,
759
3.75M
                            std::shared_ptr<ColumnPtrWrapper>* column_wrapper) {
760
3.75M
    if (!is_constant()) {
761
2.70M
        return Status::OK();
762
2.70M
    }
763
764
1.05M
    if (_constant_col != nullptr) {
765
421k
        DCHECK(column_wrapper != nullptr);
766
421k
        *column_wrapper = _constant_col;
767
421k
        return Status::OK();
768
421k
    }
769
770
637k
    ColumnPtr result;
771
637k
    RETURN_IF_ERROR(execute_column(context, nullptr, nullptr, 1, result));
772
637k
    _constant_col = std::make_shared<ColumnPtrWrapper>(result);
773
637k
    if (column_wrapper != nullptr) {
774
0
        *column_wrapper = _constant_col;
775
0
    }
776
777
637k
    return Status::OK();
778
637k
}
779
780
248k
void VExpr::register_function_context(RuntimeState* state, VExprContext* context) {
781
248k
    std::vector<DataTypePtr> arg_types;
782
482k
    for (auto& i : _children) {
783
482k
        arg_types.push_back(i->data_type());
784
482k
    }
785
786
248k
    _fn_context_index = context->register_function_context(state, _data_type, arg_types);
787
248k
}
788
789
Status VExpr::init_function_context(RuntimeState* state, VExprContext* context,
790
                                    FunctionContext::FunctionStateScope scope,
791
585k
                                    const FunctionBasePtr& function) const {
792
585k
    FunctionContext* fn_ctx = context->fn_context(_fn_context_index);
793
585k
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
794
249k
        std::vector<std::shared_ptr<ColumnPtrWrapper>> constant_cols;
795
482k
        for (auto c : _children) {
796
482k
            std::shared_ptr<ColumnPtrWrapper> const_col;
797
482k
            RETURN_IF_ERROR(c->get_const_col(context, &const_col));
798
482k
            constant_cols.push_back(const_col);
799
482k
        }
800
249k
        fn_ctx->set_constant_cols(constant_cols);
801
249k
    }
802
803
585k
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
804
249k
        RETURN_IF_ERROR(function->open(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
805
249k
    }
806
585k
    RETURN_IF_ERROR(function->open(fn_ctx, FunctionContext::THREAD_LOCAL));
807
585k
    return Status::OK();
808
585k
}
809
810
void VExpr::close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
811
586k
                                   const FunctionBasePtr& function) const {
812
586k
    if (_fn_context_index != -1) {
813
586k
        FunctionContext* fn_ctx = context->fn_context(_fn_context_index);
814
        // `close_function_context` is called in VExprContext's destructor so do not throw exceptions here.
815
586k
        static_cast<void>(function->close(fn_ctx, FunctionContext::THREAD_LOCAL));
816
586k
        if (scope == FunctionContext::FRAGMENT_LOCAL) {
817
249k
            static_cast<void>(function->close(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
818
249k
        }
819
586k
    }
820
586k
}
821
822
0
Status VExpr::check_constant(const Block& block, ColumnNumbers arguments) const {
823
0
    if (is_constant() && !VectorizedUtils::all_arguments_are_constant(block, arguments)) {
824
0
        return Status::InternalError("const check failed, expr={}", debug_string());
825
0
    }
826
0
    return Status::OK();
827
0
}
828
829
195k
uint64_t VExpr::get_digest(uint64_t seed) const {
830
195k
    auto digest = seed;
831
388k
    for (auto child : _children) {
832
388k
        digest = child->get_digest(digest);
833
388k
        if (digest == 0) {
834
74
            return 0;
835
74
        }
836
388k
    }
837
838
195k
    auto& fn_name = _fn.name.function_name;
839
195k
    if (!fn_name.empty()) {
840
195k
        digest = HashUtil::hash64(fn_name.c_str(), fn_name.size(), digest);
841
195k
    } else {
842
638
        digest = HashUtil::hash64((const char*)&_node_type, sizeof(_node_type), digest);
843
638
        digest = HashUtil::hash64((const char*)&_opcode, sizeof(_opcode), digest);
844
638
    }
845
195k
    return digest;
846
195k
}
847
848
10.2k
ColumnPtr VExpr::get_result_from_const(size_t count) const {
849
10.2k
    return ColumnConst::create(_constant_col->column_ptr, count);
850
10.2k
}
851
852
Status VExpr::_evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
853
321
                                       uint32_t segment_num_rows) {
854
    // Pre-allocate vectors based on an estimated or known size
855
321
    std::vector<segment_v2::IndexIterator*> iterators;
856
321
    std::vector<IndexFieldNameAndTypePair> data_type_with_names;
857
321
    std::vector<int> column_ids;
858
321
    ColumnsWithTypeAndName arguments;
859
321
    VExprSPtrs children_exprs;
860
861
    // Reserve space to avoid multiple reallocations
862
321
    const size_t estimated_size = get_num_children();
863
321
    iterators.reserve(estimated_size);
864
321
    data_type_with_names.reserve(estimated_size);
865
321
    column_ids.reserve(estimated_size);
866
321
    children_exprs.reserve(estimated_size);
867
868
321
    auto index_context = context->get_index_context();
869
870
    // if child is cast expr, we need to ensure target data type is the same with storage data type.
871
    // or they are all string type
872
    // and if data type is array, we need to get the nested data type to ensure that.
873
650
    for (const auto& child : children()) {
874
650
        if (child->node_type() == TExprNodeType::CAST_EXPR) {
875
319
            auto* cast_expr = assert_cast<VCastExpr*>(child.get());
876
319
            DCHECK_EQ(cast_expr->get_num_children(), 1);
877
330
            if (cast_expr->get_child(0)->is_slot_ref()) {
878
330
                auto* column_slot_ref = assert_cast<VSlotRef*>(cast_expr->get_child(0).get());
879
330
                auto column_id = column_slot_ref->column_id();
880
330
                const auto* storage_name_type =
881
330
                        context->get_index_context()->get_storage_name_and_type_by_column_id(
882
330
                                column_id);
883
330
                auto storage_type = remove_nullable(storage_name_type->second);
884
330
                auto target_type = remove_nullable(cast_expr->get_target_type());
885
330
                auto origin_primitive_type = storage_type->get_primitive_type();
886
330
                auto target_primitive_type = target_type->get_primitive_type();
887
330
                if (is_complex_type(storage_type->get_primitive_type())) {
888
0
                    if (storage_type->get_primitive_type() == TYPE_ARRAY &&
889
0
                        target_type->get_primitive_type() == TYPE_ARRAY) {
890
0
                        auto nested_storage_type =
891
0
                                (assert_cast<const DataTypeArray*>(storage_type.get()))
892
0
                                        ->get_nested_type();
893
0
                        origin_primitive_type = nested_storage_type->get_primitive_type();
894
0
                        auto nested_target_type =
895
0
                                (assert_cast<const DataTypeArray*>(target_type.get()))
896
0
                                        ->get_nested_type();
897
0
                        target_primitive_type = nested_target_type->get_primitive_type();
898
0
                    } else {
899
0
                        continue;
900
0
                    }
901
0
                }
902
330
                if (origin_primitive_type != TYPE_VARIANT &&
903
330
                    (storage_type->equals(*target_type) ||
904
322
                     (is_string_type(target_primitive_type) &&
905
322
                      is_string_type(origin_primitive_type)))) {
906
0
                    children_exprs.emplace_back(expr_without_cast(child));
907
0
                }
908
18.4E
            } else {
909
18.4E
                return Status::OK(); // for example: cast("abc") as ipv4 case
910
18.4E
            }
911
331
        } else {
912
331
            children_exprs.emplace_back(child);
913
331
        }
914
650
    }
915
916
332
    if (children_exprs.empty()) {
917
0
        return Status::OK(); // Early exit if no children to process
918
0
    }
919
920
332
    for (const auto& child : children_exprs) {
921
332
        if (child->is_slot_ref()) {
922
0
            auto* column_slot_ref = assert_cast<VSlotRef*>(child.get());
923
0
            auto column_id = column_slot_ref->column_id();
924
0
            auto* iter = context->get_index_context()->get_inverted_index_iterator_by_column_id(
925
0
                    column_id);
926
            //column does not have inverted index
927
0
            if (iter == nullptr) {
928
0
                continue;
929
0
            }
930
0
            const auto* storage_name_type =
931
0
                    context->get_index_context()->get_storage_name_and_type_by_column_id(column_id);
932
0
            if (storage_name_type == nullptr) {
933
0
                auto err_msg = fmt::format(
934
0
                        "storage_name_type cannot be found for column {} while in {} "
935
0
                        "evaluate_inverted_index",
936
0
                        column_id, expr_name());
937
0
                LOG(ERROR) << err_msg;
938
0
                return Status::InternalError(err_msg);
939
0
            }
940
0
            iterators.emplace_back(iter);
941
0
            data_type_with_names.emplace_back(*storage_name_type);
942
0
            column_ids.emplace_back(column_id);
943
332
        } else if (child->is_literal()) {
944
316
            auto* column_literal = assert_cast<VLiteral*>(child.get());
945
316
            arguments.emplace_back(column_literal->get_column_ptr(),
946
316
                                   column_literal->get_data_type(), column_literal->expr_name());
947
316
        } else if (child->can_push_down_to_index()) {
948
0
            RETURN_IF_ERROR(child->evaluate_inverted_index(context, segment_num_rows));
949
16
        } else {
950
16
            return Status::OK(); // others cases
951
16
        }
952
332
    }
953
954
    // is null or is not null has no arguments
955
316
    if (iterators.empty() || (arguments.empty() && !(function->get_name() == "is_not_null_pred" ||
956
328
                                                     function->get_name() == "is_null_pred"))) {
957
328
        return Status::OK(); // Nothing to evaluate or no literals to compare against
958
328
    }
959
960
18.4E
    const InvertedIndexAnalyzerCtx* analyzer_ctx = nullptr;
961
18.4E
    if (auto index_ctx = context->get_index_context(); index_ctx != nullptr) {
962
0
        analyzer_ctx = index_ctx->get_analyzer_ctx_for_expr(this);
963
0
    }
964
965
18.4E
    auto result_bitmap = segment_v2::InvertedIndexResultBitmap();
966
    // Pass analyzer_key to function (used by match predicates for multi-analyzer index selection)
967
18.4E
    auto res = function->evaluate_inverted_index(arguments, data_type_with_names, iterators,
968
18.4E
                                                 segment_num_rows, analyzer_ctx, result_bitmap);
969
18.4E
    if (!res.ok()) {
970
0
        return res;
971
0
    }
972
18.4E
    if (!result_bitmap.is_empty()) {
973
0
        index_context->set_index_result_for_expr(this, result_bitmap);
974
0
        for (int column_id : column_ids) {
975
0
            index_context->set_true_for_index_status(this, column_id);
976
0
        }
977
0
    }
978
18.4E
    return Status::OK();
979
18.4E
}
980
981
0
size_t VExpr::estimate_memory(const size_t rows) {
982
0
    if (is_const_and_have_executed()) {
983
0
        return 0;
984
0
    }
985
986
0
    size_t estimate_size = 0;
987
0
    for (auto& child : _children) {
988
0
        estimate_size += child->estimate_memory(rows);
989
0
    }
990
991
0
    if (_data_type->have_maximum_size_of_value()) {
992
0
        estimate_size += rows * _data_type->get_size_of_value_in_memory();
993
0
    } else {
994
0
        estimate_size += rows * 64; /// TODO: need a more reasonable value
995
0
    }
996
0
    return estimate_size;
997
0
}
998
999
bool VExpr::fast_execute(VExprContext* context, Selector* selector, size_t count,
1000
203k
                         ColumnPtr& result_column) const {
1001
203k
    if (context->get_index_context() &&
1002
203k
        context->get_index_context()->get_index_result_column().contains(this)) {
1003
        // prepare a column to save result
1004
1
        result_column = filter_column_with_selector(
1005
1
                context->get_index_context()->get_index_result_column()[this], selector, count);
1006
1
        if (_data_type->is_nullable()) {
1007
1
            result_column = make_nullable(result_column);
1008
1
        }
1009
1
        return true;
1010
1
    }
1011
203k
    return false;
1012
203k
}
1013
1014
0
bool VExpr::equals(const VExpr& other) {
1015
0
    return false;
1016
0
}
1017
1018
Status VExpr::evaluate_ann_range_search(
1019
        const segment_v2::AnnRangeSearchRuntime& runtime,
1020
        const std::vector<std::unique_ptr<segment_v2::IndexIterator>>& index_iterators,
1021
        const std::vector<ColumnId>& idx_to_cid,
1022
        const std::vector<std::unique_ptr<segment_v2::ColumnIterator>>& column_iterators,
1023
0
        roaring::Roaring& row_bitmap, AnnIndexStats& ann_index_stats) {
1024
0
    return Status::OK();
1025
0
}
1026
1027
void VExpr::prepare_ann_range_search(const doris::VectorSearchUserParams& params,
1028
                                     segment_v2::AnnRangeSearchRuntime& range_search_runtime,
1029
0
                                     bool& suitable_for_ann_index) {
1030
0
    if (!suitable_for_ann_index) {
1031
0
        return;
1032
0
    }
1033
0
    for (auto& child : _children) {
1034
0
        child->prepare_ann_range_search(params, range_search_runtime, suitable_for_ann_index);
1035
0
        if (!suitable_for_ann_index) {
1036
0
            return;
1037
0
        }
1038
0
    }
1039
0
}
1040
1041
648
bool VExpr::ann_range_search_executedd() {
1042
648
    return _has_been_executed;
1043
648
}
1044
1045
2
bool VExpr::ann_dist_is_fulfilled() const {
1046
2
    return _virtual_column_is_fulfilled;
1047
2
}
1048
1049
Status VExpr::execute_filter(VExprContext* context, const Block* block,
1050
                             uint8_t* __restrict result_filter_data, size_t rows, bool accept_null,
1051
116k
                             bool* can_filter_all) const {
1052
116k
    ColumnPtr filter_column;
1053
116k
    RETURN_IF_ERROR(execute_column(context, block, nullptr, rows, filter_column));
1054
116k
    if (const auto* const_column = check_and_get_column<ColumnConst>(*filter_column)) {
1055
        // const(nullable) or const(bool)
1056
17.5k
        const bool result = accept_null
1057
17.5k
                                    ? (const_column->is_null_at(0) || const_column->get_bool(0))
1058
17.5k
                                    : (!const_column->is_null_at(0) && const_column->get_bool(0));
1059
17.5k
        if (!result) {
1060
            // filter all
1061
1.10k
            *can_filter_all = true;
1062
1.10k
            memset(result_filter_data, 0, rows);
1063
1.10k
            return Status::OK();
1064
1.10k
        }
1065
99.2k
    } else if (const auto* nullable_column = check_and_get_column<ColumnNullable>(*filter_column)) {
1066
        // nullable(bool)
1067
78.2k
        const ColumnPtr& nested_column = nullable_column->get_nested_column_ptr();
1068
78.2k
        const IColumn::Filter& filter = assert_cast<const ColumnUInt8&>(*nested_column).get_data();
1069
78.2k
        const auto* __restrict filter_data = filter.data();
1070
78.2k
        const auto* __restrict null_map_data = nullable_column->get_null_map_data().data();
1071
1072
78.2k
        if (accept_null) {
1073
0
            for (size_t i = 0; i < rows; ++i) {
1074
0
                result_filter_data[i] &= (null_map_data[i]) || filter_data[i];
1075
0
            }
1076
78.2k
        } else {
1077
127M
            for (size_t i = 0; i < rows; ++i) {
1078
126M
                result_filter_data[i] &= (!null_map_data[i]) & filter_data[i];
1079
126M
            }
1080
78.2k
        }
1081
1082
78.2k
        if (!simd::contain_one(result_filter_data, rows)) {
1083
20.8k
            *can_filter_all = true;
1084
20.8k
            return Status::OK();
1085
20.8k
        }
1086
78.2k
    } else {
1087
        // bool
1088
21.0k
        const IColumn::Filter& filter = assert_cast<const ColumnUInt8&>(*filter_column).get_data();
1089
21.0k
        const auto* __restrict filter_data = filter.data();
1090
1091
15.1M
        for (size_t i = 0; i < rows; ++i) {
1092
15.1M
            result_filter_data[i] &= filter_data[i];
1093
15.1M
        }
1094
1095
21.0k
        if (!simd::contain_one(result_filter_data, rows)) {
1096
1.86k
            *can_filter_all = true;
1097
1.86k
            return Status::OK();
1098
1.86k
        }
1099
21.0k
    }
1100
1101
92.9k
    return Status::OK();
1102
116k
}
1103
1104
#include "common/compile_check_end.h"
1105
} // namespace doris