Coverage Report

Created: 2026-07-01 01:01

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