Coverage Report

Created: 2026-01-16 00:19

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