Coverage Report

Created: 2026-03-11 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/exprs/vexpr.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "exprs/vexpr.h"
19
20
#include <fmt/format.h>
21
#include <gen_cpp/Exprs_types.h>
22
#include <gen_cpp/FrontendService_types.h>
23
#include <thrift/protocol/TDebugProtocol.h>
24
25
#include <algorithm>
26
#include <boost/algorithm/string/split.hpp>
27
#include <boost/iterator/iterator_facade.hpp>
28
#include <cstdint>
29
#include <memory>
30
#include <stack>
31
#include <string_view>
32
#include <utility>
33
34
#include "common/config.h"
35
#include "common/exception.h"
36
#include "common/status.h"
37
#include "core/column/column_vector.h"
38
#include "core/data_type/data_type_array.h"
39
#include "core/data_type/data_type_decimal.h"
40
#include "core/data_type/data_type_factory.hpp"
41
#include "core/data_type/data_type_nullable.h"
42
#include "core/data_type/data_type_number.h"
43
#include "core/data_type/define_primitive_type.h"
44
#include "core/field.h"
45
#include "core/value/timestamptz_value.h"
46
#include "exec/common/util.hpp"
47
#include "exec/pipeline/pipeline_task.h"
48
#include "exprs/short_circuit_evaluation_expr.h"
49
#include "exprs/varray_literal.h"
50
#include "exprs/vcase_expr.h"
51
#include "exprs/vcast_expr.h"
52
#include "exprs/vcolumn_ref.h"
53
#include "exprs/vcompound_pred.h"
54
#include "exprs/vcondition_expr.h"
55
#include "exprs/vectorized_fn_call.h"
56
#include "exprs/vexpr_context.h"
57
#include "exprs/vexpr_fwd.h"
58
#include "exprs/vin_predicate.h"
59
#include "exprs/vinfo_func.h"
60
#include "exprs/virtual_slot_ref.h"
61
#include "exprs/vlambda_function_call_expr.h"
62
#include "exprs/vlambda_function_expr.h"
63
#include "exprs/vliteral.h"
64
#include "exprs/vmap_literal.h"
65
#include "exprs/vmatch_predicate.h"
66
#include "exprs/vsearch.h"
67
#include "exprs/vslot_ref.h"
68
#include "exprs/vstruct_literal.h"
69
#include "storage/index/ann/ann_search_params.h"
70
#include "storage/index/ann/ann_topn_runtime.h"
71
#include "storage/index/inverted/inverted_index_parser.h"
72
#include "storage/segment/column_reader.h"
73
74
namespace doris {
75
#include "common/compile_check_begin.h"
76
77
class RowDescriptor;
78
class RuntimeState;
79
80
// NOLINTBEGIN(readability-function-cognitive-complexity)
81
// NOLINTBEGIN(readability-function-size)
82
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision,
83
58.1k
                                 int scale) {
84
58.1k
    TExprNode node;
85
86
58.1k
    switch (type) {
87
2
    case TYPE_BOOLEAN: {
88
2
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BOOLEAN>(data, &node));
89
2
        break;
90
2
    }
91
1.76k
    case TYPE_TINYINT: {
92
1.76k
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TINYINT>(data, &node));
93
1.76k
        break;
94
1.76k
    }
95
1.76k
    case TYPE_SMALLINT: {
96
929
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_SMALLINT>(data, &node));
97
929
        break;
98
929
    }
99
5.94k
    case TYPE_INT: {
100
5.94k
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_INT>(data, &node));
101
5.94k
        break;
102
5.94k
    }
103
48.2k
    case TYPE_BIGINT: {
104
48.2k
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_BIGINT>(data, &node));
105
48.2k
        break;
106
48.2k
    }
107
48.2k
    case TYPE_LARGEINT: {
108
119
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_LARGEINT>(data, &node));
109
119
        break;
110
119
    }
111
119
    case TYPE_FLOAT: {
112
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_FLOAT>(data, &node));
113
0
        break;
114
0
    }
115
6
    case TYPE_DOUBLE: {
116
6
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DOUBLE>(data, &node));
117
6
        break;
118
6
    }
119
407
    case TYPE_DATEV2: {
120
407
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATEV2>(data, &node));
121
407
        break;
122
407
    }
123
407
    case TYPE_DATETIMEV2: {
124
249
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATETIMEV2>(data, &node, precision, scale));
125
249
        break;
126
249
    }
127
249
    case TYPE_DATE: {
128
4
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATE>(data, &node));
129
4
        break;
130
4
    }
131
6
    case TYPE_DATETIME: {
132
6
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DATETIME>(data, &node));
133
6
        break;
134
6
    }
135
6
    case TYPE_DECIMALV2: {
136
0
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMALV2>(data, &node, precision, scale));
137
0
        break;
138
0
    }
139
141
    case TYPE_DECIMAL32: {
140
141
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL32>(data, &node, precision, scale));
141
141
        break;
142
141
    }
143
141
    case TYPE_DECIMAL64: {
144
20
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL64>(data, &node, precision, scale));
145
20
        break;
146
20
    }
147
92
    case TYPE_DECIMAL128I: {
148
92
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL128I>(data, &node, precision, scale));
149
92
        break;
150
92
    }
151
92
    case TYPE_DECIMAL256: {
152
37
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_DECIMAL256>(data, &node, precision, scale));
153
37
        break;
154
37
    }
155
92
    case TYPE_CHAR: {
156
92
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_CHAR>(data, &node));
157
92
        break;
158
92
    }
159
176
    case TYPE_VARCHAR: {
160
176
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_VARCHAR>(data, &node));
161
176
        break;
162
176
    }
163
176
    case TYPE_STRING: {
164
22
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_STRING>(data, &node));
165
22
        break;
166
22
    }
167
22
    case TYPE_IPV4: {
168
14
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_IPV4>(data, &node));
169
14
        break;
170
14
    }
171
14
    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
3
    case TYPE_TIMESTAMPTZ: {
180
3
        THROW_IF_ERROR(create_texpr_literal_node<TYPE_TIMESTAMPTZ>(data, &node, precision, scale));
181
3
        break;
182
3
    }
183
3
    default:
184
0
        throw Exception(ErrorCode::INTERNAL_ERROR, "runtime filter meet invalid type {}",
185
0
                        int(type));
186
58.1k
    }
187
58.0k
    return node;
188
58.1k
}
189
190
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
191
23
                                 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 {
341
342
13.6k
bool VExpr::is_acting_on_a_slot(const VExpr& expr) {
343
13.6k
    if (expr.node_type() == TExprNodeType::SEARCH_EXPR) {
344
578
        return true;
345
578
    }
346
13.0k
    const auto& children = expr.children();
347
348
13.0k
    auto is_a_slot = std::any_of(children.begin(), children.end(),
349
13.0k
                                 [](const auto& child) { return is_acting_on_a_slot(*child); });
350
351
13.0k
    return is_a_slot ? true
352
13.0k
                     : (expr.node_type() == TExprNodeType::SLOT_REF ||
353
4.80k
                        expr.node_type() == TExprNodeType::VIRTUAL_SLOT_REF);
354
13.6k
}
355
356
VExpr::VExpr(const TExprNode& node)
357
7.24M
        : _node_type(node.node_type),
358
7.24M
          _opcode(node.__isset.opcode ? node.opcode : TExprOpcode::INVALID_OPCODE) {
359
7.24M
    if (node.__isset.fn) {
360
586k
        _fn = node.fn;
361
586k
    }
362
363
7.24M
    bool is_nullable = true;
364
7.24M
    if (node.__isset.is_nullable) {
365
7.08M
        is_nullable = node.is_nullable;
366
7.08M
    }
367
    // If we define null literal ,should make nullable data type to get correct field instead of undefined ptr
368
7.24M
    if (node.node_type == TExprNodeType::NULL_LITERAL) {
369
118k
        CHECK(is_nullable);
370
118k
    }
371
7.24M
    _data_type = get_data_type_with_default_argument(
372
7.24M
            DataTypeFactory::instance().create_data_type(node.type, is_nullable));
373
7.24M
}
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
6.79M
Status VExpr::prepare(RuntimeState* state, const RowDescriptor& row_desc, VExprContext* context) {
386
6.79M
    ++context->_depth_num;
387
6.79M
    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
6.79M
    for (auto& i : _children) {
394
1.34M
        RETURN_IF_ERROR(i->prepare(state, row_desc, context));
395
1.34M
    }
396
6.79M
    --context->_depth_num;
397
6.79M
#ifndef BE_TEST
398
6.79M
    _enable_inverted_index_query = state->query_options().enable_inverted_index_query;
399
6.79M
#endif
400
6.79M
    return Status::OK();
401
6.79M
}
402
403
Status VExpr::open(RuntimeState* state, VExprContext* context,
404
23.3M
                   FunctionContext::FunctionStateScope scope) {
405
23.3M
    for (auto& i : _children) {
406
426k
        RETURN_IF_ERROR(i->open(state, context, scope));
407
426k
    }
408
23.3M
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
409
6.15M
        RETURN_IF_ERROR(VExpr::get_const_col(context, nullptr));
410
6.15M
    }
411
23.3M
    return Status::OK();
412
23.3M
}
413
414
25.2M
void VExpr::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
415
25.2M
    for (auto& i : _children) {
416
3.52M
        i->close(context, scope);
417
3.52M
    }
418
25.2M
}
419
420
// NOLINTBEGIN(readability-function-size)
421
7.03M
Status VExpr::create_expr(const TExprNode& expr_node, VExprSPtr& expr) {
422
7.03M
    try {
423
7.03M
        switch (expr_node.node_type) {
424
22.1k
        case TExprNodeType::BOOL_LITERAL:
425
698k
        case TExprNodeType::INT_LITERAL:
426
745k
        case TExprNodeType::LARGE_INT_LITERAL:
427
747k
        case TExprNodeType::IPV4_LITERAL:
428
749k
        case TExprNodeType::IPV6_LITERAL:
429
791k
        case TExprNodeType::FLOAT_LITERAL:
430
847k
        case TExprNodeType::DECIMAL_LITERAL:
431
1.01M
        case TExprNodeType::DATE_LITERAL:
432
1.01M
        case TExprNodeType::TIMEV2_LITERAL:
433
1.64M
        case TExprNodeType::STRING_LITERAL:
434
1.64M
        case TExprNodeType::JSON_LITERAL:
435
1.64M
        case TExprNodeType::VARBINARY_LITERAL:
436
1.75M
        case TExprNodeType::NULL_LITERAL: {
437
1.75M
            expr = VLiteral::create_shared(expr_node);
438
1.75M
            break;
439
1.64M
        }
440
11.5k
        case TExprNodeType::ARRAY_LITERAL: {
441
11.5k
            expr = VArrayLiteral::create_shared(expr_node);
442
11.5k
            break;
443
1.64M
        }
444
11.8k
        case TExprNodeType::MAP_LITERAL: {
445
11.8k
            expr = VMapLiteral::create_shared(expr_node);
446
11.8k
            break;
447
1.64M
        }
448
1.45k
        case TExprNodeType::STRUCT_LITERAL: {
449
1.45k
            expr = VStructLiteral::create_shared(expr_node);
450
1.45k
            break;
451
1.64M
        }
452
4.61M
        case TExprNodeType::SLOT_REF: {
453
4.61M
            if (expr_node.slot_ref.__isset.is_virtual_slot && expr_node.slot_ref.is_virtual_slot) {
454
235
                expr = VirtualSlotRef::create_shared(expr_node);
455
235
                expr->_node_type = TExprNodeType::VIRTUAL_SLOT_REF;
456
4.61M
            } else {
457
4.61M
                expr = VSlotRef::create_shared(expr_node);
458
4.61M
            }
459
4.61M
            break;
460
1.64M
        }
461
1.29k
        case TExprNodeType::COLUMN_REF: {
462
1.29k
            expr = VColumnRef::create_shared(expr_node);
463
1.29k
            break;
464
1.64M
        }
465
3.01k
        case TExprNodeType::COMPOUND_PRED: {
466
3.01k
            expr = VCompoundPred::create_shared(expr_node);
467
3.01k
            break;
468
1.64M
        }
469
975
        case TExprNodeType::LAMBDA_FUNCTION_EXPR: {
470
975
            expr = VLambdaFunctionExpr::create_shared(expr_node);
471
975
            break;
472
1.64M
        }
473
975
        case TExprNodeType::LAMBDA_FUNCTION_CALL_EXPR: {
474
975
            expr = VLambdaFunctionCallExpr::create_shared(expr_node);
475
975
            break;
476
1.64M
        }
477
86.4k
        case TExprNodeType::ARITHMETIC_EXPR:
478
401k
        case TExprNodeType::BINARY_PRED:
479
401k
        case TExprNodeType::NULL_AWARE_BINARY_PRED:
480
401k
        case TExprNodeType::COMPUTE_FUNCTION_CALL: {
481
401k
            expr = VectorizedFnCall::create_shared(expr_node);
482
401k
            break;
483
401k
        }
484
123k
        case TExprNodeType::FUNCTION_CALL: {
485
123k
            if (expr_node.fn.name.function_name == "if") {
486
1.55k
                if (expr_node.__isset.short_circuit_evaluation &&
487
1.55k
                    expr_node.short_circuit_evaluation) {
488
700
                    expr = ShortCircuitIfExpr::create_shared(expr_node);
489
850
                } else {
490
850
                    expr = VectorizedIfExpr::create_shared(expr_node);
491
850
                }
492
1.55k
                break;
493
122k
            } else if (expr_node.fn.name.function_name == "ifnull" ||
494
122k
                       expr_node.fn.name.function_name == "nvl") {
495
201
                if (expr_node.__isset.short_circuit_evaluation &&
496
201
                    expr_node.short_circuit_evaluation) {
497
60
                    expr = ShortCircuitIfNullExpr::create_shared(expr_node);
498
141
                } else {
499
141
                    expr = VectorizedIfNullExpr::create_shared(expr_node);
500
141
                }
501
201
                break;
502
121k
            } else if (expr_node.fn.name.function_name == "coalesce") {
503
172
                if (expr_node.__isset.short_circuit_evaluation &&
504
172
                    expr_node.short_circuit_evaluation) {
505
33
                    expr = ShortCircuitCoalesceExpr::create_shared(expr_node);
506
139
                } else {
507
139
                    expr = VectorizedCoalesceExpr::create_shared(expr_node);
508
139
                }
509
172
                break;
510
172
            }
511
121k
            expr = VectorizedFnCall::create_shared(expr_node);
512
121k
            break;
513
123k
        }
514
1.57k
        case TExprNodeType::MATCH_PRED: {
515
1.57k
            expr = VMatchPredicate::create_shared(expr_node);
516
1.57k
            break;
517
123k
        }
518
114k
        case TExprNodeType::CAST_EXPR: {
519
114k
            expr = VCastExpr::create_shared(expr_node);
520
114k
            break;
521
123k
        }
522
7
        case TExprNodeType::TRY_CAST_EXPR: {
523
7
            expr = TryCastExpr::create_shared(expr_node);
524
7
            break;
525
123k
        }
526
1.30k
        case TExprNodeType::IN_PRED: {
527
1.30k
            expr = VInPredicate::create_shared(expr_node);
528
1.30k
            break;
529
123k
        }
530
286
        case TExprNodeType::CASE_EXPR: {
531
286
            if (!expr_node.__isset.case_expr) {
532
0
                return Status::InternalError("Case expression not set in thrift node");
533
0
            }
534
286
            if (expr_node.__isset.short_circuit_evaluation && expr_node.short_circuit_evaluation) {
535
89
                expr = ShortCircuitCaseExpr::create_shared(expr_node);
536
197
            } else {
537
197
                expr = VCaseExpr::create_shared(expr_node);
538
197
            }
539
286
            break;
540
286
        }
541
0
        case TExprNodeType::INFO_FUNC: {
542
0
            expr = VInfoFunc::create_shared(expr_node);
543
0
            break;
544
286
        }
545
440
        case TExprNodeType::SEARCH_EXPR: {
546
440
            expr = VSearchExpr::create_shared(expr_node);
547
440
            break;
548
286
        }
549
0
        default:
550
0
            return Status::InternalError("Unknown expr node type: {}", expr_node.node_type);
551
7.03M
        }
552
7.03M
    } 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
7.05M
    if (!expr->data_type()) {
562
0
        return Status::InvalidArgument("Unknown expr type: {}", expr_node.node_type);
563
0
    }
564
7.05M
    return Status::OK();
565
7.05M
}
566
// NOLINTEND(readability-function-size)
567
568
Status VExpr::create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
569
5.80M
                                      VExprSPtr& root_expr, VExprContextSPtr& ctx) {
570
    // propagate error case
571
5.80M
    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
5.80M
    int root_children = nodes[*node_idx].num_children;
577
5.80M
    VExprSPtr root;
578
5.80M
    RETURN_IF_ERROR(create_expr(nodes[*node_idx], root));
579
5.80M
    DCHECK(root != nullptr);
580
5.80M
    root_expr = root;
581
5.80M
    ctx = std::make_shared<VExprContext>(root);
582
    // short path for leaf node
583
5.80M
    if (root_children <= 0) {
584
5.31M
        return Status::OK();
585
5.31M
    }
586
587
    // non-recursive traversal
588
484k
    using VExprSPtrCountPair = std::pair<VExprSPtr, int>;
589
484k
    std::stack<std::shared_ptr<VExprSPtrCountPair>> s;
590
484k
    s.emplace(std::make_shared<VExprSPtrCountPair>(root, root_children));
591
1.66M
    while (!s.empty()) {
592
        // copy the shared ptr resource to avoid dangling reference
593
1.18M
        auto parent = s.top();
594
        // Decrement or pop
595
1.18M
        if (parent->second > 1) {
596
569k
            parent->second -= 1;
597
612k
        } else {
598
612k
            s.pop();
599
612k
        }
600
601
1.18M
        DCHECK(parent->first != nullptr);
602
1.18M
        if (++*node_idx >= nodes.size()) {
603
0
            return Status::InternalError("Failed to reconstruct expression tree from thrift.");
604
0
        }
605
606
1.18M
        VExprSPtr expr;
607
1.18M
        RETURN_IF_ERROR(create_expr(nodes[*node_idx], expr));
608
1.18M
        DCHECK(expr != nullptr);
609
1.18M
        parent->first->add_child(expr);
610
        // push to stack if has children
611
1.18M
        int num_children = nodes[*node_idx].num_children;
612
1.18M
        if (num_children > 0) {
613
120k
            s.emplace(std::make_shared<VExprSPtrCountPair>(expr, num_children));
614
120k
        }
615
1.18M
    }
616
484k
    return Status::OK();
617
484k
}
618
619
5.64M
Status VExpr::create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx) {
620
5.64M
    if (texpr.nodes.empty()) {
621
7
        ctx = nullptr;
622
7
        return Status::OK();
623
7
    }
624
5.64M
    int node_idx = 0;
625
5.64M
    VExprSPtr e;
626
5.64M
    Status status = create_tree_from_thrift(texpr.nodes, &node_idx, e, ctx);
627
5.65M
    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
5.64M
    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
5.64M
    return status;
638
5.64M
}
639
640
1.19M
Status VExpr::create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs) {
641
1.19M
    ctxs.clear();
642
4.68M
    for (const auto& texpr : texprs) {
643
4.68M
        VExprContextSPtr ctx;
644
4.68M
        RETURN_IF_ERROR(create_expr_tree(texpr, ctx));
645
4.68M
        ctxs.push_back(ctx);
646
4.68M
    }
647
1.19M
    return Status::OK();
648
1.19M
}
649
650
Status VExpr::check_expr_output_type(const VExprContextSPtrs& ctxs,
651
244k
                                     const RowDescriptor& output_row_desc) {
652
244k
    if (ctxs.empty()) {
653
2
        return Status::OK();
654
2
    }
655
244k
    auto name_and_types = VectorizedUtils::create_name_and_data_types(output_row_desc);
656
244k
    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
1.48M
    auto check_type_can_be_converted = [](DataTypePtr& from, DataTypePtr& to) -> bool {
662
1.48M
        if (to->equals(*from)) {
663
1.48M
            return true;
664
1.48M
        }
665
914
        if (to->is_nullable() && !from->is_nullable()) {
666
93
            return remove_nullable(to)->equals(*from);
667
93
        }
668
821
        return false;
669
914
    };
670
1.73M
    for (int i = 0; i < ctxs.size(); i++) {
671
1.48M
        auto real_expr_type = get_data_type_with_default_argument(ctxs[i]->root()->data_type());
672
1.48M
        auto&& [name, expected_type] = name_and_types[i];
673
1.48M
        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
1.48M
    }
680
244k
    return Status::OK();
681
244k
}
682
683
Status VExpr::prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
684
1.83M
                      const RowDescriptor& row_desc) {
685
5.05M
    for (auto ctx : ctxs) {
686
5.05M
        RETURN_IF_ERROR(ctx->prepare(state, row_desc));
687
5.05M
    }
688
1.83M
    return Status::OK();
689
1.83M
}
690
691
1.83M
Status VExpr::open(const VExprContextSPtrs& ctxs, RuntimeState* state) {
692
5.04M
    for (const auto& ctx : ctxs) {
693
5.04M
        RETURN_IF_ERROR(ctx->open(state));
694
5.04M
    }
695
1.83M
    return Status::OK();
696
1.83M
}
697
698
1.18M
bool VExpr::contains_blockable_function(const VExprContextSPtrs& ctxs) {
699
1.73M
    return std::any_of(ctxs.begin(), ctxs.end(), [](const VExprContextSPtr& ctx) {
700
1.73M
        return ctx != nullptr && ctx->root() != nullptr && ctx->root()->is_blockable();
701
1.73M
    });
702
1.18M
}
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
396
std::string VExpr::debug_string() const {
722
    // TODO: implement partial debug string for member vars
723
396
    std::stringstream out;
724
396
    out << " type=" << _data_type->get_name();
725
726
396
    if (!_children.empty()) {
727
0
        out << " children=" << debug_string(_children);
728
0
    }
729
730
396
    return out.str();
731
396
}
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
5.39M
bool VExpr::is_constant() const {
754
5.39M
    return std::all_of(_children.begin(), _children.end(),
755
5.39M
                       [](const VExprSPtr& expr) { return expr->is_constant(); });
756
5.39M
}
757
758
Status VExpr::get_const_col(VExprContext* context,
759
8.28M
                            std::shared_ptr<ColumnPtrWrapper>* column_wrapper) {
760
8.28M
    if (!is_constant()) {
761
5.49M
        return Status::OK();
762
5.49M
    }
763
764
2.78M
    if (_constant_col != nullptr) {
765
891k
        DCHECK(column_wrapper != nullptr);
766
891k
        *column_wrapper = _constant_col;
767
891k
        return Status::OK();
768
891k
    }
769
770
1.89M
    ColumnPtr result;
771
1.89M
    RETURN_IF_ERROR(execute_column(context, nullptr, nullptr, 1, result));
772
1.89M
    _constant_col = std::make_shared<ColumnPtrWrapper>(result);
773
1.89M
    if (column_wrapper != nullptr) {
774
0
        *column_wrapper = _constant_col;
775
0
    }
776
777
1.89M
    return Status::OK();
778
1.89M
}
779
780
642k
void VExpr::register_function_context(RuntimeState* state, VExprContext* context) {
781
642k
    std::vector<DataTypePtr> arg_types;
782
1.14M
    for (auto& i : _children) {
783
1.14M
        arg_types.push_back(i->data_type());
784
1.14M
    }
785
786
642k
    _fn_context_index = context->register_function_context(state, _data_type, arg_types);
787
642k
}
788
789
Status VExpr::init_function_context(RuntimeState* state, VExprContext* context,
790
                                    FunctionContext::FunctionStateScope scope,
791
1.76M
                                    const FunctionBasePtr& function) const {
792
1.76M
    FunctionContext* fn_ctx = context->fn_context(_fn_context_index);
793
1.76M
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
794
643k
        std::vector<std::shared_ptr<ColumnPtrWrapper>> constant_cols;
795
1.14M
        for (auto c : _children) {
796
1.14M
            std::shared_ptr<ColumnPtrWrapper> const_col;
797
1.14M
            RETURN_IF_ERROR(c->get_const_col(context, &const_col));
798
1.14M
            constant_cols.push_back(const_col);
799
1.14M
        }
800
643k
        fn_ctx->set_constant_cols(constant_cols);
801
643k
    }
802
803
1.76M
    if (scope == FunctionContext::FRAGMENT_LOCAL) {
804
643k
        RETURN_IF_ERROR(function->open(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
805
643k
    }
806
1.76M
    RETURN_IF_ERROR(function->open(fn_ctx, FunctionContext::THREAD_LOCAL));
807
1.76M
    return Status::OK();
808
1.76M
}
809
810
void VExpr::close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
811
1.77M
                                   const FunctionBasePtr& function) const {
812
1.77M
    if (_fn_context_index != -1) {
813
1.77M
        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
1.77M
        static_cast<void>(function->close(fn_ctx, FunctionContext::THREAD_LOCAL));
816
1.77M
        if (scope == FunctionContext::FRAGMENT_LOCAL) {
817
643k
            static_cast<void>(function->close(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
818
643k
        }
819
1.77M
    }
820
1.77M
}
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
381k
uint64_t VExpr::get_digest(uint64_t seed) const {
830
381k
    auto digest = seed;
831
755k
    for (auto child : _children) {
832
755k
        digest = child->get_digest(digest);
833
755k
        if (digest == 0) {
834
320
            return 0;
835
320
        }
836
755k
    }
837
838
381k
    auto& fn_name = _fn.name.function_name;
839
381k
    if (!fn_name.empty()) {
840
377k
        digest = HashUtil::hash64(fn_name.c_str(), fn_name.size(), digest);
841
377k
    } else {
842
3.52k
        digest = HashUtil::hash64((const char*)&_node_type, sizeof(_node_type), digest);
843
3.52k
        digest = HashUtil::hash64((const char*)&_opcode, sizeof(_opcode), digest);
844
3.52k
    }
845
381k
    return digest;
846
381k
}
847
848
63.4k
ColumnPtr VExpr::get_result_from_const(size_t count) const {
849
63.4k
    return ColumnConst::create(_constant_col->column_ptr, count);
850
63.4k
}
851
852
Status VExpr::_evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
853
13.6k
                                       uint32_t segment_num_rows) {
854
    // Pre-allocate vectors based on an estimated or known size
855
13.6k
    std::vector<segment_v2::IndexIterator*> iterators;
856
13.6k
    std::vector<IndexFieldNameAndTypePair> data_type_with_names;
857
13.6k
    std::vector<int> column_ids;
858
13.6k
    ColumnsWithTypeAndName arguments;
859
13.6k
    VExprSPtrs children_exprs;
860
861
    // Reserve space to avoid multiple reallocations
862
13.6k
    const size_t estimated_size = get_num_children();
863
13.6k
    iterators.reserve(estimated_size);
864
13.6k
    data_type_with_names.reserve(estimated_size);
865
13.6k
    column_ids.reserve(estimated_size);
866
13.6k
    children_exprs.reserve(estimated_size);
867
868
13.6k
    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
28.3k
    for (const auto& child : children()) {
874
28.3k
        if (child->node_type() == TExprNodeType::CAST_EXPR) {
875
2.47k
            auto* cast_expr = assert_cast<VCastExpr*>(child.get());
876
2.47k
            DCHECK_EQ(cast_expr->get_num_children(), 1);
877
2.47k
            if (cast_expr->get_child(0)->is_slot_ref()) {
878
2.38k
                auto* column_slot_ref = assert_cast<VSlotRef*>(cast_expr->get_child(0).get());
879
2.38k
                auto column_id = column_slot_ref->column_id();
880
2.38k
                const auto* storage_name_type =
881
2.38k
                        context->get_index_context()->get_storage_name_and_type_by_column_id(
882
2.38k
                                column_id);
883
2.38k
                auto storage_type = remove_nullable(storage_name_type->second);
884
2.38k
                auto target_type = remove_nullable(cast_expr->get_target_type());
885
2.38k
                auto origin_primitive_type = storage_type->get_primitive_type();
886
2.38k
                auto target_primitive_type = target_type->get_primitive_type();
887
2.38k
                if (is_complex_type(storage_type->get_primitive_type())) {
888
421
                    if (storage_type->get_primitive_type() == TYPE_ARRAY &&
889
421
                        target_type->get_primitive_type() == TYPE_ARRAY) {
890
413
                        auto nested_storage_type =
891
413
                                (assert_cast<const DataTypeArray*>(storage_type.get()))
892
413
                                        ->get_nested_type();
893
413
                        origin_primitive_type = nested_storage_type->get_primitive_type();
894
413
                        auto nested_target_type =
895
413
                                (assert_cast<const DataTypeArray*>(target_type.get()))
896
413
                                        ->get_nested_type();
897
413
                        target_primitive_type = nested_target_type->get_primitive_type();
898
413
                    } else {
899
8
                        continue;
900
8
                    }
901
421
                }
902
2.37k
                if (origin_primitive_type != TYPE_VARIANT &&
903
2.37k
                    (storage_type->equals(*target_type) ||
904
1.92k
                     (is_string_type(target_primitive_type) &&
905
1.24k
                      is_string_type(origin_primitive_type)))) {
906
681
                    children_exprs.emplace_back(expr_without_cast(child));
907
681
                }
908
2.37k
            } else {
909
93
                return Status::OK(); // for example: cast("abc") as ipv4 case
910
93
            }
911
25.8k
        } else {
912
25.8k
            children_exprs.emplace_back(child);
913
25.8k
        }
914
28.3k
    }
915
916
13.5k
    if (children_exprs.empty()) {
917
232
        return Status::OK(); // Early exit if no children to process
918
232
    }
919
920
25.5k
    for (const auto& child : children_exprs) {
921
25.5k
        if (child->is_slot_ref()) {
922
11.6k
            auto* column_slot_ref = assert_cast<VSlotRef*>(child.get());
923
11.6k
            auto column_id = column_slot_ref->column_id();
924
11.6k
            auto* iter = context->get_index_context()->get_inverted_index_iterator_by_column_id(
925
11.6k
                    column_id);
926
            //column does not have inverted index
927
11.6k
            if (iter == nullptr) {
928
2.96k
                continue;
929
2.96k
            }
930
8.68k
            const auto* storage_name_type =
931
8.68k
                    context->get_index_context()->get_storage_name_and_type_by_column_id(column_id);
932
8.68k
            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
8.68k
            iterators.emplace_back(iter);
941
8.68k
            data_type_with_names.emplace_back(*storage_name_type);
942
8.68k
            column_ids.emplace_back(column_id);
943
13.8k
        } else if (child->is_literal()) {
944
12.8k
            auto* column_literal = assert_cast<VLiteral*>(child.get());
945
12.8k
            arguments.emplace_back(column_literal->get_column_ptr(),
946
12.8k
                                   column_literal->get_data_type(), column_literal->expr_name());
947
12.8k
        } else if (child->can_push_down_to_index()) {
948
0
            RETURN_IF_ERROR(child->evaluate_inverted_index(context, segment_num_rows));
949
1.06k
        } else {
950
1.06k
            return Status::OK(); // others cases
951
1.06k
        }
952
25.5k
    }
953
954
    // is null or is not null has no arguments
955
12.2k
    if (iterators.empty() || (arguments.empty() && !(function->get_name() == "is_not_null_pred" ||
956
4.03k
                                                     function->get_name() == "is_null_pred"))) {
957
4.03k
        return Status::OK(); // Nothing to evaluate or no literals to compare against
958
4.03k
    }
959
960
8.21k
    const InvertedIndexAnalyzerCtx* analyzer_ctx = nullptr;
961
8.43k
    if (auto index_ctx = context->get_index_context(); index_ctx != nullptr) {
962
8.43k
        analyzer_ctx = index_ctx->get_analyzer_ctx_for_expr(this);
963
8.43k
    }
964
965
8.21k
    auto result_bitmap = segment_v2::InvertedIndexResultBitmap();
966
    // Pass analyzer_key to function (used by match predicates for multi-analyzer index selection)
967
8.21k
    auto res = function->evaluate_inverted_index(arguments, data_type_with_names, iterators,
968
8.21k
                                                 segment_num_rows, analyzer_ctx, result_bitmap);
969
8.21k
    if (!res.ok()) {
970
317
        return res;
971
317
    }
972
7.89k
    if (!result_bitmap.is_empty()) {
973
6.32k
        index_context->set_index_result_for_expr(this, result_bitmap);
974
6.38k
        for (int column_id : column_ids) {
975
6.38k
            index_context->set_true_for_index_status(this, column_id);
976
6.38k
        }
977
6.32k
    }
978
7.89k
    return Status::OK();
979
8.21k
}
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
298k
                         ColumnPtr& result_column) const {
1001
298k
    if (context->get_index_context() &&
1002
298k
        context->get_index_context()->get_index_result_column().contains(this)) {
1003
        // prepare a column to save result
1004
1.02k
        result_column = filter_column_with_selector(
1005
1.02k
                context->get_index_context()->get_index_result_column()[this], selector, count);
1006
1.02k
        if (_data_type->is_nullable()) {
1007
826
            result_column = make_nullable(result_column);
1008
826
        }
1009
1.02k
        return true;
1010
1.02k
    }
1011
297k
    return false;
1012
298k
}
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
4.47k
        roaring::Roaring& row_bitmap, AnnIndexStats& ann_index_stats) {
1024
4.47k
    return Status::OK();
1025
4.47k
}
1026
1027
void VExpr::prepare_ann_range_search(const doris::VectorSearchUserParams& params,
1028
                                     segment_v2::AnnRangeSearchRuntime& range_search_runtime,
1029
13.2k
                                     bool& suitable_for_ann_index) {
1030
13.2k
    if (!suitable_for_ann_index) {
1031
0
        return;
1032
0
    }
1033
13.2k
    for (auto& child : _children) {
1034
8.36k
        child->prepare_ann_range_search(params, range_search_runtime, suitable_for_ann_index);
1035
8.36k
        if (!suitable_for_ann_index) {
1036
29
            return;
1037
29
        }
1038
8.36k
    }
1039
13.2k
}
1040
1041
24.8k
bool VExpr::ann_range_search_executedd() {
1042
24.8k
    return _has_been_executed;
1043
24.8k
}
1044
1045
57
bool VExpr::ann_dist_is_fulfilled() const {
1046
57
    return _virtual_column_is_fulfilled;
1047
57
}
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
47.9k
                             bool* can_filter_all) const {
1052
47.9k
    ColumnPtr filter_column;
1053
47.9k
    RETURN_IF_ERROR(execute_column(context, block, nullptr, rows, filter_column));
1054
47.8k
    if (const auto* const_column = check_and_get_column<ColumnConst>(*filter_column)) {
1055
        // const(nullable) or const(bool)
1056
1.84k
        const bool result = accept_null
1057
1.84k
                                    ? (const_column->is_null_at(0) || const_column->get_bool(0))
1058
1.84k
                                    : (!const_column->is_null_at(0) && const_column->get_bool(0));
1059
1.84k
        if (!result) {
1060
            // filter all
1061
1.10k
            *can_filter_all = true;
1062
1.10k
            memset(result_filter_data, 0, rows);
1063
1.10k
            return Status::OK();
1064
1.10k
        }
1065
46.0k
    } else if (const auto* nullable_column = check_and_get_column<ColumnNullable>(*filter_column)) {
1066
        // nullable(bool)
1067
25.4k
        const ColumnPtr& nested_column = nullable_column->get_nested_column_ptr();
1068
25.4k
        const IColumn::Filter& filter = assert_cast<const ColumnUInt8&>(*nested_column).get_data();
1069
25.4k
        const auto* __restrict filter_data = filter.data();
1070
25.4k
        const auto* __restrict null_map_data = nullable_column->get_null_map_data().data();
1071
1072
25.4k
        if (accept_null) {
1073
1.01k
            for (size_t i = 0; i < rows; ++i) {
1074
1.00k
                result_filter_data[i] &= (null_map_data[i]) || filter_data[i];
1075
1.00k
            }
1076
25.4k
        } else {
1077
23.8M
            for (size_t i = 0; i < rows; ++i) {
1078
23.7M
                result_filter_data[i] &= (!null_map_data[i]) & filter_data[i];
1079
23.7M
            }
1080
25.4k
        }
1081
1082
25.4k
        if (!simd::contain_one(result_filter_data, rows)) {
1083
10.1k
            *can_filter_all = true;
1084
10.1k
            return Status::OK();
1085
10.1k
        }
1086
25.4k
    } else {
1087
        // bool
1088
20.5k
        const IColumn::Filter& filter = assert_cast<const ColumnUInt8&>(*filter_column).get_data();
1089
20.5k
        const auto* __restrict filter_data = filter.data();
1090
1091
50.9M
        for (size_t i = 0; i < rows; ++i) {
1092
50.9M
            result_filter_data[i] &= filter_data[i];
1093
50.9M
        }
1094
1095
20.5k
        if (!simd::contain_one(result_filter_data, rows)) {
1096
3.76k
            *can_filter_all = true;
1097
3.76k
            return Status::OK();
1098
3.76k
        }
1099
20.5k
    }
1100
1101
32.8k
    return Status::OK();
1102
47.8k
}
1103
1104
#include "common/compile_check_end.h"
1105
} // namespace doris