Coverage Report

Created: 2026-04-13 11:49

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