Coverage Report

Created: 2026-02-28 19:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/vec/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 "vec/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 "olap/inverted_index_parser.h"
38
#include "olap/rowset/segment_v2/ann_index/ann_search_params.h"
39
#include "olap/rowset/segment_v2/ann_index/ann_topn_runtime.h"
40
#include "olap/rowset/segment_v2/column_reader.h"
41
#include "pipeline/pipeline_task.h"
42
#include "runtime/define_primitive_type.h"
43
#include "vec/columns/column_vector.h"
44
#include "vec/core/field.h"
45
#include "vec/data_types/data_type_array.h"
46
#include "vec/data_types/data_type_decimal.h"
47
#include "vec/data_types/data_type_factory.hpp"
48
#include "vec/data_types/data_type_nullable.h"
49
#include "vec/data_types/data_type_number.h"
50
#include "vec/exprs/short_circuit_evaluation_expr.h"
51
#include "vec/exprs/varray_literal.h"
52
#include "vec/exprs/vcase_expr.h"
53
#include "vec/exprs/vcast_expr.h"
54
#include "vec/exprs/vcolumn_ref.h"
55
#include "vec/exprs/vcompound_pred.h"
56
#include "vec/exprs/vcondition_expr.h"
57
#include "vec/exprs/vectorized_fn_call.h"
58
#include "vec/exprs/vexpr_context.h"
59
#include "vec/exprs/vexpr_fwd.h"
60
#include "vec/exprs/vin_predicate.h"
61
#include "vec/exprs/vinfo_func.h"
62
#include "vec/exprs/virtual_slot_ref.h"
63
#include "vec/exprs/vlambda_function_call_expr.h"
64
#include "vec/exprs/vlambda_function_expr.h"
65
#include "vec/exprs/vliteral.h"
66
#include "vec/exprs/vmap_literal.h"
67
#include "vec/exprs/vmatch_predicate.h"
68
#include "vec/exprs/vsearch.h"
69
#include "vec/exprs/vslot_ref.h"
70
#include "vec/exprs/vstruct_literal.h"
71
#include "vec/runtime/timestamptz_value.h"
72
#include "vec/utils/util.hpp"
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
17
                                 int scale) {
84
17
    TExprNode node;
85
86
17
    switch (type) {
87
0
    case TYPE_BOOLEAN: {
88
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BOOLEAN>(data, &node));
89
0
        break;
90
0
    }
91
0
    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
5
    case TYPE_INT: {
100
5
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_INT>(data, &node));
101
5
        break;
102
5
    }
103
11
    case TYPE_BIGINT: {
104
11
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BIGINT>(data, &node));
105
11
        break;
106
11
    }
107
11
    case TYPE_LARGEINT: {
108
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_LARGEINT>(data, &node));
109
0
        break;
110
0
    }
111
0
    case TYPE_FLOAT: {
112
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_FLOAT>(data, &node));
113
0
        break;
114
0
    }
115
0
    case TYPE_DOUBLE: {
116
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DOUBLE>(data, &node));
117
0
        break;
118
0
    }
119
0
    case TYPE_DATEV2: {
120
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATEV2>(data, &node));
121
0
        break;
122
0
    }
123
0
    case TYPE_DATETIMEV2: {
124
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATETIMEV2>(data, &node, precision, scale));
125
0
        break;
126
0
    }
127
0
    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
0
    case TYPE_DECIMAL64: {
144
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL64>(data, &node, precision, scale));
145
0
        break;
146
0
    }
147
0
    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
0
    case TYPE_VARCHAR: {
160
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_VARCHAR>(data, &node));
161
0
        break;
162
0
    }
163
0
    case TYPE_STRING: {
164
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_STRING>(data, &node));
165
0
        break;
166
0
    }
167
0
    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
17
    }
187
17
    return node;
188
17
}
189
190
TExprNode create_texpr_node_from(const vectorized::Field& field, const PrimitiveType& type,
191
23
                                 int precision, int scale) {
192
23
    TExprNode node;
193
23
    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
1
    case TYPE_INT: {
210
1
        const auto& storage = static_cast<int32_t>(field.get<TYPE_INT>());
211
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_INT>(&storage, &node));
212
1
        break;
213
1
    }
214
1
    case TYPE_BIGINT: {
215
1
        const auto& storage = static_cast<int64_t>(field.get<TYPE_BIGINT>());
216
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BIGINT>(&storage, &node));
217
1
        break;
218
1
    }
219
1
    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
2
    case TYPE_DECIMAL64: {
277
2
        const auto& storage = field.get<TYPE_DECIMAL64>();
278
2
        THROW_IF_ERROR(
279
2
                create_texpr_literal_node<TYPE_DECIMAL64>(&storage, &node, precision, scale));
280
2
        break;
281
2
    }
282
2
    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
2
    case TYPE_CHAR: {
295
0
        const auto& storage = field.get<TYPE_CHAR>();
296
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_CHAR>(&storage, &node));
297
0
        break;
298
0
    }
299
0
    case TYPE_VARCHAR: {
300
0
        const auto& storage = field.get<TYPE_VARCHAR>();
301
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_VARCHAR>(&storage, &node));
302
0
        break;
303
0
    }
304
1
    case TYPE_STRING: {
305
1
        const auto& storage = field.get<TYPE_STRING>();
306
1
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_STRING>(&storage, &node));
307
1
        break;
308
1
    }
309
1
    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
23
    }
333
23
    return node;
334
23
}
335
336
// NOLINTEND(readability-function-size)
337
// NOLINTEND(readability-function-cognitive-complexity)
338
} // namespace doris
339
340
namespace doris::vectorized {
341
342
0
bool VExpr::is_acting_on_a_slot(const VExpr& expr) {
343
0
    if (expr.node_type() == TExprNodeType::SEARCH_EXPR) {
344
0
        return true;
345
0
    }
346
0
    const auto& children = expr.children();
347
348
0
    auto is_a_slot = std::any_of(children.begin(), children.end(),
349
0
                                 [](const auto& child) { return is_acting_on_a_slot(*child); });
350
351
0
    return is_a_slot ? true
352
0
                     : (expr.node_type() == TExprNodeType::SLOT_REF ||
353
0
                        expr.node_type() == TExprNodeType::VIRTUAL_SLOT_REF);
354
0
}
355
356
VExpr::VExpr(const TExprNode& node)
357
400k
        : _node_type(node.node_type),
358
400k
          _opcode(node.__isset.opcode ? node.opcode : TExprOpcode::INVALID_OPCODE) {
359
400k
    if (node.__isset.fn) {
360
76
        _fn = node.fn;
361
76
    }
362
363
400k
    bool is_nullable = true;
364
400k
    if (node.__isset.is_nullable) {
365
396k
        is_nullable = node.is_nullable;
366
396k
    }
367
    // If we define null literal ,should make nullable data type to get correct field instead of undefined ptr
368
400k
    if (node.node_type == TExprNodeType::NULL_LITERAL) {
369
1
        CHECK(is_nullable);
370
1
    }
371
400k
    _data_type = get_data_type_with_default_argument(
372
400k
            DataTypeFactory::instance().create_data_type(node.type, is_nullable));
373
400k
}
374
375
0
VExpr::VExpr(const VExpr& vexpr) = default;
376
377
VExpr::VExpr(DataTypePtr type, bool is_slotref)
378
9
        : _opcode(TExprOpcode::INVALID_OPCODE),
379
9
          _data_type(get_data_type_with_default_argument(type)) {
380
9
    if (is_slotref) {
381
0
        _node_type = TExprNodeType::SLOT_REF;
382
0
    }
383
9
}
384
385
258k
Status VExpr::prepare(RuntimeState* state, const RowDescriptor& row_desc, VExprContext* context) {
386
258k
    ++context->_depth_num;
387
258k
    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
258k
    for (auto& i : _children) {
394
238
        RETURN_IF_ERROR(i->prepare(state, row_desc, context));
395
238
    }
396
258k
    --context->_depth_num;
397
#ifndef BE_TEST
398
    _enable_inverted_index_query = state->query_options().enable_inverted_index_query;
399
#endif
400
258k
    return Status::OK();
401
258k
}
402
403
Status VExpr::open(RuntimeState* state, VExprContext* context,
404
512k
                   FunctionContext::FunctionStateScope scope) {
405
512k
    for (auto& i : _children) {
406
66
        RETURN_IF_ERROR(i->open(state, context, scope));
407
66
    }
408
512k
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
409
258k
        RETURN_IF_ERROR(VExpr::get_const_col(context, nullptr));
410
258k
    }
411
512k
    return Status::OK();
412
512k
}
413
414
514k
void VExpr::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
415
514k
    for (auto& i : _children) {
416
285
        i->close(context, scope);
417
285
    }
418
514k
}
419
420
// NOLINTBEGIN(readability-function-size)
421
400k
Status VExpr::create_expr(const TExprNode& expr_node, VExprSPtr& expr) {
422
400k
    try {
423
400k
        switch (expr_node.node_type) {
424
1
        case TExprNodeType::BOOL_LITERAL:
425
32
        case TExprNodeType::INT_LITERAL:
426
32
        case TExprNodeType::LARGE_INT_LITERAL:
427
33
        case TExprNodeType::IPV4_LITERAL:
428
33
        case TExprNodeType::IPV6_LITERAL:
429
144
        case TExprNodeType::FLOAT_LITERAL:
430
145
        case TExprNodeType::DECIMAL_LITERAL:
431
148
        case TExprNodeType::DATE_LITERAL:
432
148
        case TExprNodeType::TIMEV2_LITERAL:
433
154
        case TExprNodeType::STRING_LITERAL:
434
154
        case TExprNodeType::JSON_LITERAL:
435
154
        case TExprNodeType::VARBINARY_LITERAL:
436
155
        case TExprNodeType::NULL_LITERAL: {
437
155
            expr = VLiteral::create_shared(expr_node);
438
155
            break;
439
154
        }
440
13
        case TExprNodeType::ARRAY_LITERAL: {
441
13
            expr = VArrayLiteral::create_shared(expr_node);
442
13
            break;
443
154
        }
444
0
        case TExprNodeType::MAP_LITERAL: {
445
0
            expr = VMapLiteral::create_shared(expr_node);
446
0
            break;
447
154
        }
448
0
        case TExprNodeType::STRUCT_LITERAL: {
449
0
            expr = VStructLiteral::create_shared(expr_node);
450
0
            break;
451
154
        }
452
400k
        case TExprNodeType::SLOT_REF: {
453
400k
            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
400k
            } else {
457
400k
                expr = VSlotRef::create_shared(expr_node);
458
400k
            }
459
400k
            break;
460
154
        }
461
0
        case TExprNodeType::COLUMN_REF: {
462
0
            expr = VColumnRef::create_shared(expr_node);
463
0
            break;
464
154
        }
465
17
        case TExprNodeType::COMPOUND_PRED: {
466
17
            expr = VCompoundPred::create_shared(expr_node);
467
17
            break;
468
154
        }
469
0
        case TExprNodeType::LAMBDA_FUNCTION_EXPR: {
470
0
            expr = VLambdaFunctionExpr::create_shared(expr_node);
471
0
            break;
472
154
        }
473
0
        case TExprNodeType::LAMBDA_FUNCTION_CALL_EXPR: {
474
0
            expr = VLambdaFunctionCallExpr::create_shared(expr_node);
475
0
            break;
476
154
        }
477
0
        case TExprNodeType::ARITHMETIC_EXPR:
478
46
        case TExprNodeType::BINARY_PRED:
479
47
        case TExprNodeType::NULL_AWARE_BINARY_PRED:
480
47
        case TExprNodeType::COMPUTE_FUNCTION_CALL: {
481
47
            expr = VectorizedFnCall::create_shared(expr_node);
482
47
            break;
483
47
        }
484
23
        case TExprNodeType::FUNCTION_CALL: {
485
23
            if (expr_node.fn.name.function_name == "if") {
486
0
                if (expr_node.__isset.short_circuit_evaluation &&
487
0
                    expr_node.short_circuit_evaluation) {
488
0
                    expr = ShortCircuitIfExpr::create_shared(expr_node);
489
0
                } else {
490
0
                    expr = VectorizedIfExpr::create_shared(expr_node);
491
0
                }
492
0
                break;
493
23
            } else if (expr_node.fn.name.function_name == "ifnull" ||
494
23
                       expr_node.fn.name.function_name == "nvl") {
495
0
                if (expr_node.__isset.short_circuit_evaluation &&
496
0
                    expr_node.short_circuit_evaluation) {
497
0
                    expr = ShortCircuitIfNullExpr::create_shared(expr_node);
498
0
                } else {
499
0
                    expr = VectorizedIfNullExpr::create_shared(expr_node);
500
0
                }
501
0
                break;
502
23
            } else if (expr_node.fn.name.function_name == "coalesce") {
503
0
                if (expr_node.__isset.short_circuit_evaluation &&
504
0
                    expr_node.short_circuit_evaluation) {
505
0
                    expr = ShortCircuitCoalesceExpr::create_shared(expr_node);
506
0
                } else {
507
0
                    expr = VectorizedCoalesceExpr::create_shared(expr_node);
508
0
                }
509
0
                break;
510
0
            }
511
23
            expr = VectorizedFnCall::create_shared(expr_node);
512
23
            break;
513
23
        }
514
0
        case TExprNodeType::MATCH_PRED: {
515
0
            expr = VMatchPredicate::create_shared(expr_node);
516
0
            break;
517
23
        }
518
2
        case TExprNodeType::CAST_EXPR: {
519
2
            expr = VCastExpr::create_shared(expr_node);
520
2
            break;
521
23
        }
522
0
        case TExprNodeType::TRY_CAST_EXPR: {
523
0
            expr = TryCastExpr::create_shared(expr_node);
524
0
            break;
525
23
        }
526
5
        case TExprNodeType::IN_PRED: {
527
5
            expr = VInPredicate::create_shared(expr_node);
528
5
            break;
529
23
        }
530
0
        case TExprNodeType::CASE_EXPR: {
531
0
            if (!expr_node.__isset.case_expr) {
532
0
                return Status::InternalError("Case expression not set in thrift node");
533
0
            }
534
0
            if (expr_node.__isset.short_circuit_evaluation && expr_node.short_circuit_evaluation) {
535
0
                expr = ShortCircuitCaseExpr::create_shared(expr_node);
536
0
            } else {
537
0
                expr = VCaseExpr::create_shared(expr_node);
538
0
            }
539
0
            break;
540
0
        }
541
0
        case TExprNodeType::INFO_FUNC: {
542
0
            expr = VInfoFunc::create_shared(expr_node);
543
0
            break;
544
0
        }
545
0
        case TExprNodeType::SEARCH_EXPR: {
546
0
            expr = VSearchExpr::create_shared(expr_node);
547
0
            break;
548
0
        }
549
0
        default:
550
0
            return Status::InternalError("Unknown expr node type: {}", expr_node.node_type);
551
400k
        }
552
400k
    } 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
400k
    if (!expr->data_type()) {
562
0
        return Status::InvalidArgument("Unknown expr type: {}", expr_node.node_type);
563
0
    }
564
400k
    return Status::OK();
565
400k
}
566
// NOLINTEND(readability-function-size)
567
568
Status VExpr::create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
569
400k
                                      VExprSPtr& root_expr, VExprContextSPtr& ctx) {
570
    // propagate error case
571
400k
    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
400k
    int root_children = nodes[*node_idx].num_children;
577
400k
    VExprSPtr root;
578
400k
    RETURN_IF_ERROR(create_expr(nodes[*node_idx], root));
579
400k
    DCHECK(root != nullptr);
580
400k
    root_expr = root;
581
400k
    ctx = std::make_shared<VExprContext>(root);
582
    // short path for leaf node
583
400k
    if (root_children <= 0) {
584
399k
        return Status::OK();
585
399k
    }
586
587
    // non-recursive traversal
588
50
    using VExprSPtrCountPair = std::pair<VExprSPtr, int>;
589
50
    std::stack<std::shared_ptr<VExprSPtrCountPair>> s;
590
50
    s.emplace(std::make_shared<VExprSPtrCountPair>(root, root_children));
591
323
    while (!s.empty()) {
592
        // copy the shared ptr resource to avoid dangling reference
593
273
        auto parent = s.top();
594
        // Decrement or pop
595
273
        if (parent->second > 1) {
596
175
            parent->second -= 1;
597
175
        } else {
598
98
            s.pop();
599
98
        }
600
601
273
        DCHECK(parent->first != nullptr);
602
273
        if (++*node_idx >= nodes.size()) {
603
0
            return Status::InternalError("Failed to reconstruct expression tree from thrift.");
604
0
        }
605
606
273
        VExprSPtr expr;
607
273
        RETURN_IF_ERROR(create_expr(nodes[*node_idx], expr));
608
273
        DCHECK(expr != nullptr);
609
273
        parent->first->add_child(expr);
610
        // push to stack if has children
611
273
        int num_children = nodes[*node_idx].num_children;
612
273
        if (num_children > 0) {
613
49
            s.emplace(std::make_shared<VExprSPtrCountPair>(expr, num_children));
614
49
        }
615
273
    }
616
50
    return Status::OK();
617
50
}
618
619
400k
Status VExpr::create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx) {
620
400k
    if (texpr.nodes.empty()) {
621
7
        ctx = nullptr;
622
7
        return Status::OK();
623
7
    }
624
400k
    int node_idx = 0;
625
400k
    VExprSPtr e;
626
400k
    Status status = create_tree_from_thrift(texpr.nodes, &node_idx, e, ctx);
627
400k
    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
400k
    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
400k
    return status;
638
400k
}
639
640
28.1k
Status VExpr::create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs) {
641
28.1k
    ctxs.clear();
642
70.0k
    for (const auto& texpr : texprs) {
643
70.0k
        VExprContextSPtr ctx;
644
70.0k
        RETURN_IF_ERROR(create_expr_tree(texpr, ctx));
645
70.0k
        ctxs.push_back(ctx);
646
70.0k
    }
647
28.1k
    return Status::OK();
648
28.1k
}
649
650
Status VExpr::check_expr_output_type(const VExprContextSPtrs& ctxs,
651
24.0k
                                     const RowDescriptor& output_row_desc) {
652
24.0k
    if (ctxs.empty()) {
653
2
        return Status::OK();
654
2
    }
655
24.0k
    auto name_and_types = VectorizedUtils::create_name_and_data_types(output_row_desc);
656
24.0k
    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
65.9k
    auto check_type_can_be_converted = [](DataTypePtr& from, DataTypePtr& to) -> bool {
662
65.9k
        if (to->equals(*from)) {
663
65.9k
            return true;
664
65.9k
        }
665
0
        if (to->is_nullable() && !from->is_nullable()) {
666
0
            return remove_nullable(to)->equals(*from);
667
0
        }
668
0
        return false;
669
0
    };
670
89.9k
    for (int i = 0; i < ctxs.size(); i++) {
671
65.9k
        auto real_expr_type = get_data_type_with_default_argument(ctxs[i]->root()->data_type());
672
65.9k
        auto&& [name, expected_type] = name_and_types[i];
673
65.9k
        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
65.9k
    }
680
24.0k
    return Status::OK();
681
24.0k
}
682
683
Status VExpr::prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
684
148k
                      const RowDescriptor& row_desc) {
685
258k
    for (auto ctx : ctxs) {
686
258k
        RETURN_IF_ERROR(ctx->prepare(state, row_desc));
687
258k
    }
688
148k
    return Status::OK();
689
148k
}
690
691
148k
Status VExpr::open(const VExprContextSPtrs& ctxs, RuntimeState* state) {
692
258k
    for (const auto& ctx : ctxs) {
693
258k
        RETURN_IF_ERROR(ctx->open(state));
694
258k
    }
695
148k
    return Status::OK();
696
148k
}
697
698
96.2k
bool VExpr::contains_blockable_function(const VExprContextSPtrs& ctxs) {
699
96.2k
    return std::any_of(ctxs.begin(), ctxs.end(), [](const VExprContextSPtr& ctx) {
700
65.9k
        return ctx != nullptr && ctx->root() != nullptr && ctx->root()->is_blockable();
701
65.9k
    });
702
96.2k
}
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
7
std::string VExpr::debug_string() const {
722
    // TODO: implement partial debug string for member vars
723
7
    std::stringstream out;
724
7
    out << " type=" << _data_type->get_name();
725
726
7
    if (!_children.empty()) {
727
0
        out << " children=" << debug_string(_children);
728
0
    }
729
730
7
    return out.str();
731
7
}
732
733
0
std::string VExpr::debug_string(const VExprSPtrs& exprs) {
734
0
    std::stringstream out;
735
0
    out << "[";
736
737
0
    for (int i = 0; i < exprs.size(); ++i) {
738
0
        out << (i == 0 ? "" : " ") << exprs[i]->debug_string();
739
0
    }
740
741
0
    out << "]";
742
0
    return out.str();
743
0
}
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
558
bool VExpr::is_constant() const {
754
558
    return std::all_of(_children.begin(), _children.end(),
755
558
                       [](const VExprSPtr& expr) { return expr->is_constant(); });
756
558
}
757
758
Status VExpr::get_const_col(VExprContext* context,
759
258k
                            std::shared_ptr<ColumnPtrWrapper>* column_wrapper) {
760
258k
    if (!is_constant()) {
761
258k
        return Status::OK();
762
258k
    }
763
764
117
    if (_constant_col != nullptr) {
765
28
        DCHECK(column_wrapper != nullptr);
766
28
        *column_wrapper = _constant_col;
767
28
        return Status::OK();
768
28
    }
769
770
89
    ColumnPtr result;
771
89
    RETURN_IF_ERROR(execute_column(context, nullptr, nullptr, 1, result));
772
89
    _constant_col = std::make_shared<ColumnPtrWrapper>(result);
773
89
    if (column_wrapper != nullptr) {
774
0
        *column_wrapper = _constant_col;
775
0
    }
776
777
89
    return Status::OK();
778
89
}
779
780
83
void VExpr::register_function_context(RuntimeState* state, VExprContext* context) {
781
83
    std::vector<DataTypePtr> arg_types;
782
162
    for (auto& i : _children) {
783
162
        arg_types.push_back(i->data_type());
784
162
    }
785
786
83
    _fn_context_index = context->register_function_context(state, _data_type, arg_types);
787
83
}
788
789
Status VExpr::init_function_context(RuntimeState* state, VExprContext* context,
790
                                    FunctionContext::FunctionStateScope scope,
791
47
                                    const FunctionBasePtr& function) const {
792
47
    FunctionContext* fn_ctx = context->fn_context(_fn_context_index);
793
47
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
794
31
        std::vector<std::shared_ptr<ColumnPtrWrapper>> constant_cols;
795
58
        for (auto c : _children) {
796
58
            std::shared_ptr<ColumnPtrWrapper> const_col;
797
58
            RETURN_IF_ERROR(c->get_const_col(context, &const_col));
798
58
            constant_cols.push_back(const_col);
799
58
        }
800
31
        fn_ctx->set_constant_cols(constant_cols);
801
31
    }
802
803
47
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
804
31
        RETURN_IF_ERROR(function->open(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
805
31
    }
806
47
    RETURN_IF_ERROR(function->open(fn_ctx, FunctionContext::THREAD_LOCAL));
807
47
    return Status::OK();
808
47
}
809
810
void VExpr::close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
811
156
                                   const FunctionBasePtr& function) const {
812
156
    if (_fn_context_index != -1) {
813
49
        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
49
        static_cast<void>(function->close(fn_ctx, FunctionContext::THREAD_LOCAL));
816
49
        if (scope == FunctionContext::FRAGMENT_LOCAL) {
817
33
            static_cast<void>(function->close(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
818
33
        }
819
49
    }
820
156
}
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
0
uint64_t VExpr::get_digest(uint64_t seed) const {
830
0
    auto digest = seed;
831
0
    for (auto child : _children) {
832
0
        digest = child->get_digest(digest);
833
0
        if (digest == 0) {
834
0
            return 0;
835
0
        }
836
0
    }
837
838
0
    auto& fn_name = _fn.name.function_name;
839
0
    if (!fn_name.empty()) {
840
0
        digest = HashUtil::hash64(fn_name.c_str(), fn_name.size(), digest);
841
0
    } else {
842
0
        digest = HashUtil::hash64((const char*)&_node_type, sizeof(_node_type), digest);
843
0
        digest = HashUtil::hash64((const char*)&_opcode, sizeof(_opcode), digest);
844
0
    }
845
0
    return digest;
846
0
}
847
848
0
ColumnPtr VExpr::get_result_from_const(size_t count) const {
849
0
    return ColumnConst::create(_constant_col->column_ptr, count);
850
0
}
851
852
Status VExpr::_evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
853
1
                                       uint32_t segment_num_rows) {
854
    // Pre-allocate vectors based on an estimated or known size
855
1
    std::vector<segment_v2::IndexIterator*> iterators;
856
1
    std::vector<vectorized::IndexFieldNameAndTypePair> data_type_with_names;
857
1
    std::vector<int> column_ids;
858
1
    vectorized::ColumnsWithTypeAndName arguments;
859
1
    VExprSPtrs children_exprs;
860
861
    // Reserve space to avoid multiple reallocations
862
1
    const size_t estimated_size = get_num_children();
863
1
    iterators.reserve(estimated_size);
864
1
    data_type_with_names.reserve(estimated_size);
865
1
    column_ids.reserve(estimated_size);
866
1
    children_exprs.reserve(estimated_size);
867
868
1
    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
2
    for (const auto& child : children()) {
874
2
        if (child->node_type() == TExprNodeType::CAST_EXPR) {
875
1
            auto* cast_expr = assert_cast<VCastExpr*>(child.get());
876
1
            DCHECK_EQ(cast_expr->get_num_children(), 1);
877
1
            if (cast_expr->get_child(0)->is_slot_ref()) {
878
0
                auto* column_slot_ref = assert_cast<VSlotRef*>(cast_expr->get_child(0).get());
879
0
                auto column_id = column_slot_ref->column_id();
880
0
                const auto* storage_name_type =
881
0
                        context->get_index_context()->get_storage_name_and_type_by_column_id(
882
0
                                column_id);
883
0
                auto storage_type = remove_nullable(storage_name_type->second);
884
0
                auto target_type = remove_nullable(cast_expr->get_target_type());
885
0
                auto origin_primitive_type = storage_type->get_primitive_type();
886
0
                auto target_primitive_type = target_type->get_primitive_type();
887
0
                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
0
                if (origin_primitive_type != TYPE_VARIANT &&
903
0
                    (storage_type->equals(*target_type) ||
904
0
                     (is_string_type(target_primitive_type) &&
905
0
                      is_string_type(origin_primitive_type)))) {
906
0
                    children_exprs.emplace_back(expr_without_cast(child));
907
0
                }
908
1
            } else {
909
1
                return Status::OK(); // for example: cast("abc") as ipv4 case
910
1
            }
911
1
        } else {
912
1
            children_exprs.emplace_back(child);
913
1
        }
914
2
    }
915
916
0
    if (children_exprs.empty()) {
917
0
        return Status::OK(); // Early exit if no children to process
918
0
    }
919
920
0
    for (const auto& child : children_exprs) {
921
0
        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
0
        } else if (child->is_literal()) {
944
0
            auto* column_literal = assert_cast<VLiteral*>(child.get());
945
0
            arguments.emplace_back(column_literal->get_column_ptr(),
946
0
                                   column_literal->get_data_type(), column_literal->expr_name());
947
0
        } else if (child->can_push_down_to_index()) {
948
0
            RETURN_IF_ERROR(child->evaluate_inverted_index(context, segment_num_rows));
949
0
        } else {
950
0
            return Status::OK(); // others cases
951
0
        }
952
0
    }
953
954
    // is null or is not null has no arguments
955
0
    if (iterators.empty() || (arguments.empty() && !(function->get_name() == "is_not_null_pred" ||
956
0
                                                     function->get_name() == "is_null_pred"))) {
957
0
        return Status::OK(); // Nothing to evaluate or no literals to compare against
958
0
    }
959
960
0
    const InvertedIndexAnalyzerCtx* analyzer_ctx = nullptr;
961
0
    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
0
    auto result_bitmap = segment_v2::InvertedIndexResultBitmap();
966
    // Pass analyzer_key to function (used by match predicates for multi-analyzer index selection)
967
0
    auto res = function->evaluate_inverted_index(arguments, data_type_with_names, iterators,
968
0
                                                 segment_num_rows, analyzer_ctx, result_bitmap);
969
0
    if (!res.ok()) {
970
0
        return res;
971
0
    }
972
0
    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
0
    return Status::OK();
979
0
}
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
15
                         ColumnPtr& result_column) const {
1001
15
    if (context->get_index_context() &&
1002
15
        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
14
    return false;
1012
15
}
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
2
bool VExpr::ann_range_search_executedd() {
1042
2
    return _has_been_executed;
1043
2
}
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
8
                             bool* can_filter_all) const {
1052
8
    ColumnPtr filter_column;
1053
8
    RETURN_IF_ERROR(execute_column(context, block, nullptr, rows, filter_column));
1054
8
    if (const auto* const_column = check_and_get_column<ColumnConst>(*filter_column)) {
1055
        // const(nullable) or const(bool)
1056
0
        const bool result = accept_null
1057
0
                                    ? (const_column->is_null_at(0) || const_column->get_bool(0))
1058
0
                                    : (!const_column->is_null_at(0) && const_column->get_bool(0));
1059
0
        if (!result) {
1060
            // filter all
1061
0
            *can_filter_all = true;
1062
0
            memset(result_filter_data, 0, rows);
1063
0
            return Status::OK();
1064
0
        }
1065
8
    } else if (const auto* nullable_column = check_and_get_column<ColumnNullable>(*filter_column)) {
1066
        // nullable(bool)
1067
8
        const ColumnPtr& nested_column = nullable_column->get_nested_column_ptr();
1068
8
        const IColumn::Filter& filter = assert_cast<const ColumnUInt8&>(*nested_column).get_data();
1069
8
        const auto* __restrict filter_data = filter.data();
1070
8
        const auto* __restrict null_map_data = nullable_column->get_null_map_data().data();
1071
1072
8
        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
8
        } else {
1077
54
            for (size_t i = 0; i < rows; ++i) {
1078
46
                result_filter_data[i] &= (!null_map_data[i]) & filter_data[i];
1079
46
            }
1080
8
        }
1081
1082
8
        if (!simd::contain_one(result_filter_data, rows)) {
1083
2
            *can_filter_all = true;
1084
2
            return Status::OK();
1085
2
        }
1086
8
    } else {
1087
        // bool
1088
0
        const IColumn::Filter& filter = assert_cast<const ColumnUInt8&>(*filter_column).get_data();
1089
0
        const auto* __restrict filter_data = filter.data();
1090
1091
0
        for (size_t i = 0; i < rows; ++i) {
1092
0
            result_filter_data[i] &= filter_data[i];
1093
0
        }
1094
1095
0
        if (!simd::contain_one(result_filter_data, rows)) {
1096
0
            *can_filter_all = true;
1097
0
            return Status::OK();
1098
0
        }
1099
0
    }
1100
1101
6
    return Status::OK();
1102
8
}
1103
1104
#include "common/compile_check_end.h"
1105
} // namespace doris::vectorized