Coverage Report

Created: 2026-08-01 21:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vcondition_expr.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/vcondition_expr.h"
19
20
#include <glog/logging.h>
21
22
#include "core/column/column.h"
23
#include "core/column/column_const.h"
24
#include "exprs/function_context.h"
25
#include "util/simd/bits.h"
26
27
namespace doris {
28
29
Status VConditionExpr::prepare(RuntimeState* state, const RowDescriptor& desc,
30
5.95k
                               VExprContext* context) {
31
5.95k
    RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
32
5.95k
    _prepare_finished = true;
33
5.95k
    return Status::OK();
34
5.95k
}
35
36
Status VConditionExpr::open(RuntimeState* state, VExprContext* context,
37
24.0k
                            FunctionContext::FunctionStateScope scope) {
38
24.0k
    DCHECK(_prepare_finished);
39
24.0k
    RETURN_IF_ERROR(VExpr::open(state, context, scope));
40
24.0k
    _open_finished = true;
41
24.0k
    return Status::OK();
42
24.0k
}
43
44
24.2k
void VConditionExpr::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
45
24.2k
    DCHECK(_prepare_finished);
46
24.2k
    VExpr::close(context, scope);
47
24.2k
}
48
49
0
std::string VConditionExpr::debug_string() const {
50
0
    std::string result = expr_name() + "(";
51
0
    for (size_t i = 0; i < _children.size(); ++i) {
52
0
        if (i != 0) {
53
0
            result += ", ";
54
0
        }
55
0
        result += _children[i]->debug_string();
56
0
    }
57
0
    result += ")";
58
0
    return result;
59
0
}
60
61
10.3k
size_t VConditionExpr::count_true_with_notnull(const ColumnPtr& col) {
62
10.3k
    if (col->only_null()) {
63
18
        return 0;
64
18
    }
65
66
10.3k
    if (const auto* const_col = check_and_get_column<ColumnConst>(col.get())) {
67
        // if is null , get_bool will return false
68
        // bool get_bool(size_t n) const override {
69
        //     return is_null_at(n) ? false : _nested_column->get_bool(n);
70
        // }
71
2.29k
        bool is_true = const_col->get_bool(0);
72
2.29k
        return is_true ? col->size() : 0;
73
2.29k
    }
74
75
8.03k
    auto count = col->size();
76
8.03k
    if (const auto* nullable = check_and_get_column<ColumnNullable>(col.get())) {
77
616
        const auto* __restrict null_data = nullable->get_null_map_data().data();
78
616
        const auto* __restrict bool_data =
79
616
                ((const ColumnUInt8&)(nullable->get_nested_column())).get_data().data();
80
81
616
        size_t null_count = count - simd::count_zero_num((const int8_t*)null_data, count);
82
83
616
        if (null_count == count) {
84
0
            return 0;
85
616
        } else if (null_count == 0) {
86
588
            size_t true_count = count - simd::count_zero_num((const int8_t*)bool_data, count);
87
588
            return true_count;
88
588
        } else {
89
            // In fact, the null_count maybe is different with true_count, but it's no impact
90
28
            return null_count;
91
28
        }
92
7.41k
    } else {
93
7.41k
        const auto* bool_col = assert_cast<const ColumnUInt8*>(col.get());
94
7.41k
        const auto* __restrict bool_data = bool_col->get_data().data();
95
7.41k
        return count - simd::count_zero_num((const int8_t*)bool_data, count);
96
7.41k
    }
97
8.03k
}
98
99
6.54k
ColumnPtr materialize_column_if_const(const ColumnPtr& column) {
100
6.54k
    return column->convert_to_full_column_if_const();
101
6.54k
}
102
103
0
ColumnPtr make_nullable_column_if_not(const ColumnPtr& column) {
104
0
    if (is_column_nullable(*column)) return column;
105
106
0
    return ColumnNullable::create(materialize_column_if_const(column),
107
0
                                  ColumnUInt8::create(column->size(), 0));
108
0
}
109
110
1.48k
ColumnPtr get_nested_column(const ColumnPtr& column) {
111
1.48k
    if (auto* nullable = check_and_get_column<ColumnNullable>(*column))
112
864
        return nullable->get_nested_column_ptr();
113
618
    else if (const auto* column_const = check_and_get_column<ColumnConst>(*column))
114
150
        return ColumnConst::create(get_nested_column(column_const->get_data_column_ptr()),
115
150
                                   column->size());
116
117
468
    return column;
118
1.48k
}
119
120
Status VectorizedIfExpr::execute_generic(Block& block, const ColumnUInt8* cond_col,
121
                                         const ColumnWithTypeAndName& then_col_type_name,
122
                                         const ColumnWithTypeAndName& else_col_type_name,
123
2.04k
                                         uint32_t result, size_t input_row_count) const {
124
2.04k
    MutableColumnPtr result_column = block.get_by_position(result).type->create_column();
125
2.04k
    result_column->reserve(input_row_count);
126
127
2.04k
    const IColumn& then_col = *then_col_type_name.column;
128
2.04k
    const IColumn& else_col = *else_col_type_name.column;
129
2.04k
    bool then_is_const = is_column_const(then_col);
130
2.04k
    bool else_is_const = is_column_const(else_col);
131
132
2.04k
    const auto& cond_array = cond_col->get_data();
133
134
2.04k
    if (then_is_const && else_is_const) {
135
2
        const IColumn& then_nested_column =
136
2
                assert_cast<const ColumnConst&>(then_col).get_data_column();
137
2
        const IColumn& else_nested_column =
138
2
                assert_cast<const ColumnConst&>(else_col).get_data_column();
139
18
        for (size_t i = 0; i < input_row_count; i++) {
140
16
            if (cond_array[i])
141
8
                result_column->insert_from(then_nested_column, 0);
142
8
            else
143
8
                result_column->insert_from(else_nested_column, 0);
144
16
        }
145
2.04k
    } else if (then_is_const) {
146
1.85k
        const IColumn& then_nested_column =
147
1.85k
                assert_cast<const ColumnConst&>(then_col).get_data_column();
148
149
3.74k
        for (size_t i = 0; i < input_row_count; i++) {
150
1.88k
            if (cond_array[i])
151
14
                result_column->insert_from(then_nested_column, 0);
152
1.87k
            else
153
1.87k
                result_column->insert_from(else_col, i);
154
1.88k
        }
155
1.85k
    } else if (else_is_const) {
156
0
        const IColumn& else_nested_column =
157
0
                assert_cast<const ColumnConst&>(else_col).get_data_column();
158
159
0
        for (size_t i = 0; i < input_row_count; i++) {
160
0
            if (cond_array[i])
161
0
                result_column->insert_from(then_col, i);
162
0
            else
163
0
                result_column->insert_from(else_nested_column, 0);
164
0
        }
165
186
    } else {
166
752
        for (size_t i = 0; i < input_row_count; i++) {
167
566
            result_column->insert_from(cond_array[i] ? then_col : else_col, i);
168
566
        }
169
186
    }
170
2.04k
    block.replace_by_position(result, std::move(result_column));
171
2.04k
    return Status::OK();
172
2.04k
}
173
174
Status VectorizedIfExpr::execute_for_null_then_else(Block& block,
175
                                                    const ColumnWithTypeAndName& arg_cond,
176
                                                    const ColumnWithTypeAndName& arg_then,
177
                                                    const ColumnWithTypeAndName& arg_else,
178
                                                    uint32_t result, size_t input_rows_count,
179
4.90k
                                                    bool& handled) const {
180
4.90k
    bool then_is_null = arg_then.column->only_null();
181
4.90k
    bool else_is_null = arg_else.column->only_null();
182
183
4.90k
    handled = false;
184
4.90k
    if (!then_is_null && !else_is_null) {
185
4.30k
        return Status::OK();
186
4.30k
    }
187
188
604
    if (then_is_null && else_is_null) {
189
48
        block.get_by_position(result).column =
190
48
                block.get_by_position(result).type->create_column_const_with_default_value(
191
48
                        input_rows_count);
192
48
        handled = true;
193
48
        return Status::OK();
194
48
    }
195
196
556
    const auto* cond_col = check_and_get_column<ColumnUInt8>(arg_cond.column.get());
197
556
    const ColumnConst* cond_const_col =
198
556
            check_and_get_column_const<ColumnUInt8>(arg_cond.column.get());
199
200
    /// If then is NULL, we create Nullable column with null mask OR-ed with condition.
201
556
    if (then_is_null) {
202
108
        if (cond_col) {
203
108
            if (is_column_nullable(*arg_else.column)) { // if(cond, null, nullable)
204
108
                auto arg_else_column = arg_else.column;
205
108
                auto result_column = (*std::move(arg_else_column)).mutate();
206
108
                assert_cast<ColumnNullable&>(*result_column)
207
108
                        .apply_null_map(assert_cast<const ColumnUInt8&>(*arg_cond.column));
208
108
                block.replace_by_position(result, std::move(result_column));
209
108
            } else { // if(cond, null, not_nullable)
210
0
                block.replace_by_position(
211
0
                        result, ColumnNullable::create(materialize_column_if_const(arg_else.column),
212
0
                                                       arg_cond.column));
213
0
            }
214
108
        } else if (cond_const_col) {
215
0
            if (cond_const_col->get_value<TYPE_BOOLEAN>()) { // if(true, null, else)
216
0
                block.get_by_position(result).column =
217
0
                        block.get_by_position(result).type->create_column()->clone_resized(
218
0
                                input_rows_count);
219
0
            } else { // if(false, null, else)
220
0
                block.get_by_position(result).column = make_nullable_column_if_not(arg_else.column);
221
0
            }
222
0
        } else {
223
0
            return Status::InternalError(
224
0
                    "Illegal column {} of first argument of function {}. Must be ColumnUInt8 "
225
0
                    "or ColumnConstUInt8.",
226
0
                    arg_cond.column->get_name(), expr_name());
227
0
        }
228
448
    } else { /// If else is NULL, we create Nullable column with null mask OR-ed with negated condition.
229
448
        if (cond_col) {
230
448
            size_t size = input_rows_count;
231
232
448
            if (is_column_nullable(*arg_then.column)) { // if(cond, nullable, NULL)
233
326
                auto arg_then_column = arg_then.column;
234
326
                auto result_column = (*std::move(arg_then_column)).mutate();
235
326
                assert_cast<ColumnNullable&>(*result_column)
236
326
                        .apply_negated_null_map(assert_cast<const ColumnUInt8&>(*arg_cond.column));
237
326
                block.replace_by_position(result, std::move(result_column));
238
326
            } else { // if(cond, not_nullable, NULL)
239
122
                const auto& null_map_data = cond_col->get_data();
240
122
                auto negated_null_map = ColumnUInt8::create();
241
122
                auto& negated_null_map_data = negated_null_map->get_data();
242
122
                negated_null_map_data.resize(size);
243
244
504
                for (size_t i = 0; i < size; ++i) {
245
382
                    negated_null_map_data[i] = !null_map_data[i];
246
382
                }
247
248
122
                block.replace_by_position(
249
122
                        result, ColumnNullable::create(materialize_column_if_const(arg_then.column),
250
122
                                                       std::move(negated_null_map)));
251
122
            }
252
448
        } else if (cond_const_col) {
253
0
            if (cond_const_col->get_value<TYPE_BOOLEAN>()) { // if(true, then, NULL)
254
0
                block.get_by_position(result).column = make_nullable_column_if_not(arg_then.column);
255
0
            } else { // if(false, then, NULL)
256
0
                block.get_by_position(result).column =
257
0
                        block.get_by_position(result).type->create_column()->clone_resized(
258
0
                                input_rows_count);
259
0
            }
260
0
        } else {
261
0
            return Status::InternalError(
262
0
                    "Illegal column {} of first argument of function {}. Must be ColumnUInt8 "
263
0
                    "or ColumnConstUInt8.",
264
0
                    arg_cond.column->get_name(), expr_name());
265
0
        }
266
448
    }
267
556
    handled = true;
268
556
    return Status::OK();
269
556
}
270
271
Status VectorizedIfExpr::execute_for_nullable_then_else(Block& block,
272
                                                        const ColumnWithTypeAndName& arg_cond,
273
                                                        const ColumnWithTypeAndName& arg_then,
274
                                                        const ColumnWithTypeAndName& arg_else,
275
                                                        uint32_t result, size_t input_rows_count,
276
4.30k
                                                        bool& handled) const {
277
4.30k
    auto then_type_is_nullable = arg_then.type->is_nullable();
278
4.30k
    auto else_type_is_nullable = arg_else.type->is_nullable();
279
4.30k
    handled = false;
280
4.30k
    if (!then_type_is_nullable && !else_type_is_nullable) {
281
3.63k
        return Status::OK();
282
3.63k
    }
283
284
666
    const auto* then_is_nullable = check_and_get_column<ColumnNullable>(*arg_then.column);
285
666
    const auto* else_is_nullable = check_and_get_column<ColumnNullable>(*arg_else.column);
286
666
    bool then_column_is_const_nullable = false;
287
666
    bool else_column_is_const_nullable = false;
288
666
    if (then_type_is_nullable && then_is_nullable == nullptr) {
289
        //this case is a const(nullable column)
290
0
        const auto& const_column = assert_cast<const ColumnConst&>(*arg_then.column);
291
0
        then_is_nullable =
292
0
                assert_cast<const ColumnNullable*>(const_column.get_data_column_ptr().get());
293
0
        then_column_is_const_nullable = true;
294
0
    }
295
296
666
    if (else_type_is_nullable && else_is_nullable == nullptr) {
297
        //this case is a const(nullable column)
298
0
        const auto& const_column = assert_cast<const ColumnConst&>(*arg_else.column);
299
0
        else_is_nullable =
300
0
                assert_cast<const ColumnNullable*>(const_column.get_data_column_ptr().get());
301
0
        else_column_is_const_nullable = true;
302
0
    }
303
304
    /** Calculate null mask of result and nested column separately.
305
      */
306
666
    ColumnPtr result_null_mask;
307
666
    {
308
        // get null map from column:
309
        // a. get_null_map_column_ptr() : it's a real nullable column, so could get it from nullable column
310
        // b. create a const_nullmap_column: it's a not nullable column or a const nullable column, contain a const value
311
666
        Block temporary_block;
312
666
        temporary_block.insert(arg_cond);
313
666
        ColumnPtr then_nested_null_map;
314
666
        if (then_type_is_nullable && !then_column_is_const_nullable) {
315
200
            then_nested_null_map = then_is_nullable->get_null_map_column_ptr();
316
466
        } else {
317
466
            then_nested_null_map =
318
466
                    DataTypeUInt8().create_column_const_with_default_value(input_rows_count);
319
466
        }
320
666
        temporary_block.insert(
321
666
                {then_nested_null_map, std::make_shared<DataTypeUInt8>(), "then_column_null_map"});
322
323
666
        ColumnPtr else_nested_null_map;
324
666
        if (else_type_is_nullable && !else_column_is_const_nullable) {
325
664
            else_nested_null_map = else_is_nullable->get_null_map_column_ptr();
326
664
        } else {
327
2
            else_nested_null_map =
328
2
                    DataTypeUInt8().create_column_const_with_default_value(input_rows_count);
329
2
        }
330
666
        temporary_block.insert(
331
666
                {else_nested_null_map, std::make_shared<DataTypeUInt8>(), "else_column_null_map"});
332
666
        temporary_block.insert(
333
666
                {nullptr, std::make_shared<DataTypeUInt8>(), "result_column_null_map"});
334
335
666
        RETURN_IF_ERROR(
336
666
                _execute_impl_internal(temporary_block, {0, 1, 2}, 3, temporary_block.rows()));
337
338
666
        result_null_mask = temporary_block.get_by_position(3).column;
339
666
    }
340
341
0
    ColumnPtr result_nested_column;
342
343
666
    {
344
666
        Block temporary_block(
345
666
                {arg_cond,
346
666
                 {get_nested_column(arg_then.column), remove_nullable(arg_then.type), ""},
347
666
                 {get_nested_column(arg_else.column), remove_nullable(arg_else.type), ""},
348
666
                 {nullptr, remove_nullable(block.get_by_position(result).type), ""}});
349
350
666
        RETURN_IF_ERROR(
351
666
                _execute_impl_internal(temporary_block, {0, 1, 2}, 3, temporary_block.rows()));
352
353
666
        result_nested_column = temporary_block.get_by_position(3).column;
354
666
    }
355
356
0
    auto column = ColumnNullable::create(materialize_column_if_const(result_nested_column),
357
666
                                         materialize_column_if_const(result_null_mask));
358
666
    block.replace_by_position(result, std::move(column));
359
666
    handled = true;
360
666
    return Status::OK();
361
666
}
362
363
Status VectorizedIfExpr::execute_for_null_condition(Block& block, const ColumnNumbers& arguments,
364
                                                    const ColumnWithTypeAndName& arg_cond,
365
                                                    const ColumnWithTypeAndName& arg_then,
366
                                                    const ColumnWithTypeAndName& arg_else,
367
5.09k
                                                    uint32_t result, bool& handled) const {
368
5.09k
    bool cond_is_null = arg_cond.column->only_null();
369
5.09k
    handled = false;
370
371
5.09k
    if (cond_is_null) {
372
0
        block.replace_by_position(result, arg_else.column->clone_resized(arg_cond.column->size()));
373
0
        handled = true;
374
0
        return Status::OK();
375
0
    }
376
377
5.09k
    if (const auto* nullable = check_and_get_column<ColumnNullable>(*arg_cond.column)) {
378
182
        DCHECK(remove_nullable(arg_cond.type)->get_primitive_type() == PrimitiveType::TYPE_BOOLEAN);
379
380
        // update nested column by null map
381
182
        const auto* __restrict null_map = nullable->get_null_map_data().data();
382
182
        auto* __restrict nested_bool_data =
383
182
                ((ColumnUInt8&)(nullable->get_nested_column())).get_data().data();
384
182
        auto rows = nullable->size();
385
24.6k
        for (size_t i = 0; i < rows; i++) {
386
24.4k
            nested_bool_data[i] &= !null_map[i];
387
24.4k
        }
388
182
        auto column_size = block.columns();
389
182
        block.insert(
390
182
                {nullable->get_nested_column_ptr(), remove_nullable(arg_cond.type), arg_cond.name});
391
392
182
        handled = true;
393
182
        return _execute_impl_internal(block, {column_size, arguments[1], arguments[2]}, result,
394
182
                                      rows);
395
182
    }
396
4.90k
    return Status::OK();
397
5.09k
}
398
399
Status VectorizedIfExpr::_execute_impl_internal(Block& block, const ColumnNumbers& arguments,
400
5.09k
                                                uint32_t result, size_t input_rows_count) const {
401
5.09k
    const ColumnWithTypeAndName& arg_then = block.get_by_position(arguments[1]);
402
5.09k
    const ColumnWithTypeAndName& arg_else = block.get_by_position(arguments[2]);
403
5.09k
    ColumnWithTypeAndName& cond_column = block.get_by_position(arguments[0]);
404
5.09k
    cond_column.column = materialize_column_if_const(cond_column.column);
405
5.09k
    const ColumnWithTypeAndName& arg_cond = block.get_by_position(arguments[0]);
406
407
5.09k
    Status ret = Status::OK();
408
5.09k
    bool handled = false;
409
5.09k
    RETURN_IF_ERROR(execute_for_null_condition(block, arguments, arg_cond, arg_then, arg_else,
410
5.09k
                                               result, handled));
411
412
5.09k
    if (!handled) {
413
4.90k
        RETURN_IF_ERROR(execute_for_null_then_else(block, arg_cond, arg_then, arg_else, result,
414
4.90k
                                                   input_rows_count, handled));
415
4.90k
    }
416
417
5.09k
    if (!handled) {
418
4.30k
        RETURN_IF_ERROR(execute_for_nullable_then_else(block, arg_cond, arg_then, arg_else, result,
419
4.30k
                                                       input_rows_count, handled));
420
4.30k
    }
421
422
5.09k
    if (handled) {
423
1.45k
        return Status::OK();
424
1.45k
    }
425
426
3.63k
    const auto* cond_col = assert_cast<const ColumnUInt8*>(arg_cond.column.get());
427
3.63k
    const ColumnConst* cond_const_col =
428
3.63k
            check_and_get_column_const<ColumnUInt8>(arg_cond.column.get());
429
430
3.63k
    if (cond_const_col) {
431
0
        block.get_by_position(result).column =
432
0
                cond_const_col->get_value<TYPE_BOOLEAN>() ? arg_then.column : arg_else.column;
433
0
        return Status::OK();
434
0
    }
435
436
3.63k
    Status vec_exec;
437
438
3.63k
    auto call = [&](const auto& type) -> bool {
439
1.59k
        using DataType = std::decay_t<decltype(type)>;
440
1.59k
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
1.59k
                                                       vec_exec);
442
1.59k
        return true;
443
1.59k
    };
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE2EEEEEbRKT_
Line
Count
Source
438
666
    auto call = [&](const auto& type) -> bool {
439
666
        using DataType = std::decay_t<decltype(type)>;
440
666
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
666
                                                       vec_exec);
442
666
        return true;
443
666
    };
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE3EEEEEbRKT_
Line
Count
Source
438
364
    auto call = [&](const auto& type) -> bool {
439
364
        using DataType = std::decay_t<decltype(type)>;
440
364
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
364
                                                       vec_exec);
442
364
        return true;
443
364
    };
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE4EEEEEbRKT_
Line
Count
Source
438
4
    auto call = [&](const auto& type) -> bool {
439
4
        using DataType = std::decay_t<decltype(type)>;
440
4
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
4
                                                       vec_exec);
442
4
        return true;
443
4
    };
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE5EEEEEbRKT_
Line
Count
Source
438
372
    auto call = [&](const auto& type) -> bool {
439
372
        using DataType = std::decay_t<decltype(type)>;
440
372
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
372
                                                       vec_exec);
442
372
        return true;
443
372
    };
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE6EEEEEbRKT_
Line
Count
Source
438
102
    auto call = [&](const auto& type) -> bool {
439
102
        using DataType = std::decay_t<decltype(type)>;
440
102
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
102
                                                       vec_exec);
442
102
        return true;
443
102
    };
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE7EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE8EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE9EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE28EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE29EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE20EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE30EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE35EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE11EEEEEbRKT_
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE25EEEEEbRKT_
Line
Count
Source
438
80
    auto call = [&](const auto& type) -> bool {
439
80
        using DataType = std::decay_t<decltype(type)>;
440
80
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
80
                                                       vec_exec);
442
80
        return true;
443
80
    };
vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE26EEEEEbRKT_
Line
Count
Source
438
4
    auto call = [&](const auto& type) -> bool {
439
4
        using DataType = std::decay_t<decltype(type)>;
440
4
        vec_exec = execute_basic_type<DataType::PType>(block, cond_col, arg_then, arg_else, result,
441
4
                                                       vec_exec);
442
4
        return true;
443
4
    };
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE43EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE12EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE27EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE42EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE36EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZNK5doris16VectorizedIfExpr22_execute_impl_internalERNS_5BlockERKSt6vectorIjSaIjEEjmENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE37EEEEEbRKT_
444
445
3.63k
    auto can_use_vec_exec = dispatch_switch_scalar(arg_then.type->get_primitive_type(), call);
446
3.63k
    if (can_use_vec_exec) {
447
1.59k
        return vec_exec;
448
2.04k
    } else {
449
2.04k
        return execute_generic(block, cond_col, arg_then, arg_else, result, input_rows_count);
450
2.04k
    }
451
3.63k
}
452
453
Status VectorizedIfExpr::execute_column_impl(VExprContext* context, const Block* block,
454
                                             const Selector* selector, size_t count,
455
10.3k
                                             ColumnPtr& result_column) const {
456
10.3k
    DCHECK(_open_finished || block == nullptr) << debug_string();
457
10.3k
    DCHECK_EQ(_children.size(), 3) << "IF expr must have three children";
458
459
10.3k
    ColumnPtr cond_column;
460
10.3k
    RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, cond_column));
461
462
10.3k
    ColumnPtr then_column;
463
10.3k
    ColumnPtr else_column;
464
465
10.3k
    auto true_count = count_true_with_notnull(cond_column);
466
10.3k
    auto item_count = cond_column->size();
467
10.3k
    if (true_count == item_count) {
468
966
        RETURN_IF_ERROR(_children[1]->execute_column(context, block, selector, count, then_column));
469
966
        result_column = _data_type->is_nullable() ? make_nullable(then_column) : then_column;
470
966
        return Status::OK();
471
9.37k
    } else if (true_count == 0) {
472
7.73k
        RETURN_IF_ERROR(_children[2]->execute_column(context, block, selector, count, else_column));
473
7.73k
        result_column = _data_type->is_nullable() ? make_nullable(else_column) : else_column;
474
7.73k
        return Status::OK();
475
7.73k
    }
476
477
1.64k
    RETURN_IF_ERROR(_children[1]->execute_column(context, block, selector, count, then_column));
478
1.64k
    RETURN_IF_ERROR(_children[2]->execute_column(context, block, selector, count, else_column));
479
480
1.64k
    Block temp_block;
481
482
1.64k
    temp_block.insert({cond_column, _children[0]->execute_type(block), _children[0]->expr_name()});
483
1.64k
    temp_block.insert({then_column, _children[1]->execute_type(block), _children[1]->expr_name()});
484
1.64k
    temp_block.insert({else_column, _children[2]->execute_type(block), _children[2]->expr_name()});
485
486
    // prepare a column to save result
487
1.64k
    temp_block.insert({nullptr, _data_type, IF_NAME});
488
1.64k
    RETURN_IF_ERROR(_execute_impl_internal(temp_block, {0, 1, 2}, 3, temp_block.rows()));
489
1.64k
    result_column = temp_block.get_by_position(3).column;
490
1.64k
    DCHECK_EQ(result_column->size(), count);
491
1.64k
    return Status::OK();
492
1.64k
}
493
494
Status VectorizedIfNullExpr::execute_column_impl(VExprContext* context, const Block* block,
495
                                                 const Selector* selector, size_t count,
496
2.16k
                                                 ColumnPtr& result_column) const {
497
2.16k
    DCHECK(_open_finished || block == nullptr) << debug_string();
498
2.16k
    DCHECK_EQ(_children.size(), 2) << "IFNULL expr must have two children";
499
500
2.16k
    ColumnPtr first_column;
501
2.16k
    RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, first_column));
502
2.16k
    first_column = first_column->convert_to_full_column_if_const();
503
504
2.16k
    if (!is_column_nullable(*first_column)) {
505
0
        result_column = first_column;
506
0
        DCHECK(_data_type->is_nullable() == false);
507
0
        return Status::OK();
508
0
    }
509
510
2.16k
    if (first_column->only_null()) {
511
230
        RETURN_IF_ERROR(
512
230
                _children[1]->execute_column(context, block, selector, count, result_column));
513
230
        return Status::OK();
514
230
    }
515
516
1.93k
    ColumnPtr second_column;
517
1.93k
    RETURN_IF_ERROR(_children[1]->execute_column(context, block, selector, count, second_column));
518
519
1.93k
    const auto& nullable_first_column = assert_cast<const ColumnNullable&>(*first_column);
520
521
1.93k
    ColumnPtr cond_column = nullable_first_column.get_null_map_column_ptr();
522
523
1.93k
    ColumnPtr then_column = second_column;
524
525
1.93k
    ColumnPtr else_column;
526
1.93k
    DataTypePtr else_type;
527
528
1.93k
    if (_data_type->is_nullable()) {
529
0
        else_column = first_column;
530
0
        else_type = _children[0]->execute_type(block);
531
1.93k
    } else {
532
1.93k
        else_column = nullable_first_column.get_nested_column_ptr();
533
1.93k
        else_type = remove_nullable(_children[0]->execute_type(block));
534
1.93k
    }
535
536
1.93k
    Block temp_block;
537
1.93k
    temp_block.insert({cond_column, std::make_shared<DataTypeUInt8>(), "cond column"});
538
1.93k
    temp_block.insert({then_column, _children[1]->execute_type(block), _children[1]->expr_name()});
539
1.93k
    temp_block.insert({else_column, else_type, _children[0]->expr_name()});
540
541
    // prepare a column to save result
542
1.93k
    temp_block.insert({nullptr, _data_type, IF_NULL_NAME});
543
1.93k
    RETURN_IF_ERROR(_execute_impl_internal(temp_block, {0, 1, 2}, 3, temp_block.rows()));
544
1.93k
    result_column = temp_block.get_by_position(3).column;
545
1.93k
    DCHECK_EQ(result_column->size(), count);
546
1.93k
    return Status::OK();
547
1.93k
}
548
549
template <typename ColumnType>
550
void insert_result_data(MutableColumnPtr& result_column, ColumnPtr& argument_column,
551
                        const UInt8* __restrict null_map_data, UInt8* __restrict filled_flag,
552
16
                        const size_t input_rows_count) {
553
16
    if (result_column->size() == 0 && input_rows_count) {
554
10
        result_column->resize(input_rows_count);
555
10
        auto* __restrict result_raw_data =
556
10
                assert_cast<ColumnType*>(result_column.get())->get_data().data();
557
26
        for (int i = 0; i < input_rows_count; i++) {
558
16
            result_raw_data[i] = {};
559
16
        }
560
10
    }
561
16
    auto* __restrict result_raw_data =
562
16
            assert_cast<ColumnType*>(result_column.get())->get_data().data();
563
16
    auto* __restrict column_raw_data =
564
16
            assert_cast<const ColumnType*>(argument_column.get())->get_data().data();
565
566
    // Here it's SIMD thought the compiler automatically also
567
    // true: null_map_data[row]==0 && filled_idx[row]==0
568
    // if true, could filled current row data into result column
569
44
    for (size_t row = 0; row < input_rows_count; ++row) {
570
28
        if constexpr (std::is_same_v<ColumnType, ColumnDateV2>) {
571
0
            result_raw_data[row] = binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(
572
0
                    result_raw_data[row].to_date_int_val() +
573
0
                    column_raw_data[row].to_date_int_val() *
574
0
                            uint32_t(!(null_map_data[row] | filled_flag[row])));
575
0
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2>) {
576
0
            result_raw_data[row] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
577
0
                    result_raw_data[row].to_date_int_val() +
578
0
                    column_raw_data[row].to_date_int_val() *
579
0
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
580
4
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2Nano>) {
581
4
            if (!(null_map_data[row] | filled_flag[row])) {
582
2
                result_raw_data[row] = column_raw_data[row];
583
2
            }
584
4
        } else if constexpr (std::is_same_v<ColumnType, ColumnTimeStampTz>) {
585
0
            result_raw_data[row] = binary_cast<uint64_t, TimestampTzValue>(
586
0
                    result_raw_data[row].to_date_int_val() +
587
0
                    column_raw_data[row].to_date_int_val() *
588
0
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
589
        } else if constexpr (std::is_same_v<ColumnType, ColumnDate> ||
590
0
                             std::is_same_v<ColumnType, ColumnDateTime>) {
591
0
            result_raw_data[row] = binary_cast<int64_t, VecDateTimeValue>(
592
0
                    binary_cast<VecDateTimeValue, int64_t>(result_raw_data[row]) +
593
0
                    binary_cast<VecDateTimeValue, int64_t>(column_raw_data[row]) *
594
0
                            int64_t(!(null_map_data[row] | filled_flag[row])));
595
        } else if constexpr (std::is_same_v<ColumnType, ColumnFloat32> ||
596
16
                             std::is_same_v<ColumnType, ColumnFloat64>) {
597
16
            auto flag = (!(null_map_data[row] | filled_flag[row]));
598
16
            result_raw_data[row] += std::isfinite(column_raw_data[row])
599
16
                                            ? column_raw_data[row] * flag
600
16
                                            : (flag ? column_raw_data[row] : 0);
601
16
        } else {
602
8
            result_raw_data[row] +=
603
8
                    column_raw_data[row] *
604
8
                    typename ColumnType::value_type(!(null_map_data[row] | filled_flag[row]));
605
8
        }
606
607
28
        filled_flag[row] += (!(null_map_data[row] | filled_flag[row]));
608
28
    }
609
16
}
_ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE43EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Line
Count
Source
552
2
                        const size_t input_rows_count) {
553
2
    if (result_column->size() == 0 && input_rows_count) {
554
1
        result_column->resize(input_rows_count);
555
1
        auto* __restrict result_raw_data =
556
1
                assert_cast<ColumnType*>(result_column.get())->get_data().data();
557
3
        for (int i = 0; i < input_rows_count; i++) {
558
2
            result_raw_data[i] = {};
559
2
        }
560
1
    }
561
2
    auto* __restrict result_raw_data =
562
2
            assert_cast<ColumnType*>(result_column.get())->get_data().data();
563
2
    auto* __restrict column_raw_data =
564
2
            assert_cast<const ColumnType*>(argument_column.get())->get_data().data();
565
566
    // Here it's SIMD thought the compiler automatically also
567
    // true: null_map_data[row]==0 && filled_idx[row]==0
568
    // if true, could filled current row data into result column
569
6
    for (size_t row = 0; row < input_rows_count; ++row) {
570
        if constexpr (std::is_same_v<ColumnType, ColumnDateV2>) {
571
            result_raw_data[row] = binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(
572
                    result_raw_data[row].to_date_int_val() +
573
                    column_raw_data[row].to_date_int_val() *
574
                            uint32_t(!(null_map_data[row] | filled_flag[row])));
575
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2>) {
576
            result_raw_data[row] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
577
                    result_raw_data[row].to_date_int_val() +
578
                    column_raw_data[row].to_date_int_val() *
579
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
580
4
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2Nano>) {
581
4
            if (!(null_map_data[row] | filled_flag[row])) {
582
2
                result_raw_data[row] = column_raw_data[row];
583
2
            }
584
        } else if constexpr (std::is_same_v<ColumnType, ColumnTimeStampTz>) {
585
            result_raw_data[row] = binary_cast<uint64_t, TimestampTzValue>(
586
                    result_raw_data[row].to_date_int_val() +
587
                    column_raw_data[row].to_date_int_val() *
588
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
589
        } else if constexpr (std::is_same_v<ColumnType, ColumnDate> ||
590
                             std::is_same_v<ColumnType, ColumnDateTime>) {
591
            result_raw_data[row] = binary_cast<int64_t, VecDateTimeValue>(
592
                    binary_cast<VecDateTimeValue, int64_t>(result_raw_data[row]) +
593
                    binary_cast<VecDateTimeValue, int64_t>(column_raw_data[row]) *
594
                            int64_t(!(null_map_data[row] | filled_flag[row])));
595
        } else if constexpr (std::is_same_v<ColumnType, ColumnFloat32> ||
596
                             std::is_same_v<ColumnType, ColumnFloat64>) {
597
            auto flag = (!(null_map_data[row] | filled_flag[row]));
598
            result_raw_data[row] += std::isfinite(column_raw_data[row])
599
                                            ? column_raw_data[row] * flag
600
                                            : (flag ? column_raw_data[row] : 0);
601
        } else {
602
            result_raw_data[row] +=
603
                    column_raw_data[row] *
604
                    typename ColumnType::value_type(!(null_map_data[row] | filled_flag[row]));
605
        }
606
607
4
        filled_flag[row] += (!(null_map_data[row] | filled_flag[row]));
608
4
    }
609
2
}
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE3EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE4EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
_ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE5EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Line
Count
Source
552
6
                        const size_t input_rows_count) {
553
6
    if (result_column->size() == 0 && input_rows_count) {
554
5
        result_column->resize(input_rows_count);
555
5
        auto* __restrict result_raw_data =
556
5
                assert_cast<ColumnType*>(result_column.get())->get_data().data();
557
11
        for (int i = 0; i < input_rows_count; i++) {
558
6
            result_raw_data[i] = {};
559
6
        }
560
5
    }
561
6
    auto* __restrict result_raw_data =
562
6
            assert_cast<ColumnType*>(result_column.get())->get_data().data();
563
6
    auto* __restrict column_raw_data =
564
6
            assert_cast<const ColumnType*>(argument_column.get())->get_data().data();
565
566
    // Here it's SIMD thought the compiler automatically also
567
    // true: null_map_data[row]==0 && filled_idx[row]==0
568
    // if true, could filled current row data into result column
569
14
    for (size_t row = 0; row < input_rows_count; ++row) {
570
        if constexpr (std::is_same_v<ColumnType, ColumnDateV2>) {
571
            result_raw_data[row] = binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(
572
                    result_raw_data[row].to_date_int_val() +
573
                    column_raw_data[row].to_date_int_val() *
574
                            uint32_t(!(null_map_data[row] | filled_flag[row])));
575
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2>) {
576
            result_raw_data[row] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
577
                    result_raw_data[row].to_date_int_val() +
578
                    column_raw_data[row].to_date_int_val() *
579
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
580
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2Nano>) {
581
            if (!(null_map_data[row] | filled_flag[row])) {
582
                result_raw_data[row] = column_raw_data[row];
583
            }
584
        } else if constexpr (std::is_same_v<ColumnType, ColumnTimeStampTz>) {
585
            result_raw_data[row] = binary_cast<uint64_t, TimestampTzValue>(
586
                    result_raw_data[row].to_date_int_val() +
587
                    column_raw_data[row].to_date_int_val() *
588
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
589
        } else if constexpr (std::is_same_v<ColumnType, ColumnDate> ||
590
                             std::is_same_v<ColumnType, ColumnDateTime>) {
591
            result_raw_data[row] = binary_cast<int64_t, VecDateTimeValue>(
592
                    binary_cast<VecDateTimeValue, int64_t>(result_raw_data[row]) +
593
                    binary_cast<VecDateTimeValue, int64_t>(column_raw_data[row]) *
594
                            int64_t(!(null_map_data[row] | filled_flag[row])));
595
        } else if constexpr (std::is_same_v<ColumnType, ColumnFloat32> ||
596
                             std::is_same_v<ColumnType, ColumnFloat64>) {
597
            auto flag = (!(null_map_data[row] | filled_flag[row]));
598
            result_raw_data[row] += std::isfinite(column_raw_data[row])
599
                                            ? column_raw_data[row] * flag
600
                                            : (flag ? column_raw_data[row] : 0);
601
8
        } else {
602
8
            result_raw_data[row] +=
603
8
                    column_raw_data[row] *
604
8
                    typename ColumnType::value_type(!(null_map_data[row] | filled_flag[row]));
605
8
        }
606
607
8
        filled_flag[row] += (!(null_map_data[row] | filled_flag[row]));
608
8
    }
609
6
}
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE6EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE7EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
_ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE8EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Line
Count
Source
552
2
                        const size_t input_rows_count) {
553
2
    if (result_column->size() == 0 && input_rows_count) {
554
1
        result_column->resize(input_rows_count);
555
1
        auto* __restrict result_raw_data =
556
1
                assert_cast<ColumnType*>(result_column.get())->get_data().data();
557
3
        for (int i = 0; i < input_rows_count; i++) {
558
2
            result_raw_data[i] = {};
559
2
        }
560
1
    }
561
2
    auto* __restrict result_raw_data =
562
2
            assert_cast<ColumnType*>(result_column.get())->get_data().data();
563
2
    auto* __restrict column_raw_data =
564
2
            assert_cast<const ColumnType*>(argument_column.get())->get_data().data();
565
566
    // Here it's SIMD thought the compiler automatically also
567
    // true: null_map_data[row]==0 && filled_idx[row]==0
568
    // if true, could filled current row data into result column
569
6
    for (size_t row = 0; row < input_rows_count; ++row) {
570
        if constexpr (std::is_same_v<ColumnType, ColumnDateV2>) {
571
            result_raw_data[row] = binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(
572
                    result_raw_data[row].to_date_int_val() +
573
                    column_raw_data[row].to_date_int_val() *
574
                            uint32_t(!(null_map_data[row] | filled_flag[row])));
575
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2>) {
576
            result_raw_data[row] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
577
                    result_raw_data[row].to_date_int_val() +
578
                    column_raw_data[row].to_date_int_val() *
579
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
580
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2Nano>) {
581
            if (!(null_map_data[row] | filled_flag[row])) {
582
                result_raw_data[row] = column_raw_data[row];
583
            }
584
        } else if constexpr (std::is_same_v<ColumnType, ColumnTimeStampTz>) {
585
            result_raw_data[row] = binary_cast<uint64_t, TimestampTzValue>(
586
                    result_raw_data[row].to_date_int_val() +
587
                    column_raw_data[row].to_date_int_val() *
588
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
589
        } else if constexpr (std::is_same_v<ColumnType, ColumnDate> ||
590
                             std::is_same_v<ColumnType, ColumnDateTime>) {
591
            result_raw_data[row] = binary_cast<int64_t, VecDateTimeValue>(
592
                    binary_cast<VecDateTimeValue, int64_t>(result_raw_data[row]) +
593
                    binary_cast<VecDateTimeValue, int64_t>(column_raw_data[row]) *
594
                            int64_t(!(null_map_data[row] | filled_flag[row])));
595
        } else if constexpr (std::is_same_v<ColumnType, ColumnFloat32> ||
596
4
                             std::is_same_v<ColumnType, ColumnFloat64>) {
597
4
            auto flag = (!(null_map_data[row] | filled_flag[row]));
598
4
            result_raw_data[row] += std::isfinite(column_raw_data[row])
599
4
                                            ? column_raw_data[row] * flag
600
4
                                            : (flag ? column_raw_data[row] : 0);
601
        } else {
602
            result_raw_data[row] +=
603
                    column_raw_data[row] *
604
                    typename ColumnType::value_type(!(null_map_data[row] | filled_flag[row]));
605
        }
606
607
4
        filled_flag[row] += (!(null_map_data[row] | filled_flag[row]));
608
4
    }
609
2
}
_ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE9EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Line
Count
Source
552
6
                        const size_t input_rows_count) {
553
6
    if (result_column->size() == 0 && input_rows_count) {
554
3
        result_column->resize(input_rows_count);
555
3
        auto* __restrict result_raw_data =
556
3
                assert_cast<ColumnType*>(result_column.get())->get_data().data();
557
9
        for (int i = 0; i < input_rows_count; i++) {
558
6
            result_raw_data[i] = {};
559
6
        }
560
3
    }
561
6
    auto* __restrict result_raw_data =
562
6
            assert_cast<ColumnType*>(result_column.get())->get_data().data();
563
6
    auto* __restrict column_raw_data =
564
6
            assert_cast<const ColumnType*>(argument_column.get())->get_data().data();
565
566
    // Here it's SIMD thought the compiler automatically also
567
    // true: null_map_data[row]==0 && filled_idx[row]==0
568
    // if true, could filled current row data into result column
569
18
    for (size_t row = 0; row < input_rows_count; ++row) {
570
        if constexpr (std::is_same_v<ColumnType, ColumnDateV2>) {
571
            result_raw_data[row] = binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(
572
                    result_raw_data[row].to_date_int_val() +
573
                    column_raw_data[row].to_date_int_val() *
574
                            uint32_t(!(null_map_data[row] | filled_flag[row])));
575
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2>) {
576
            result_raw_data[row] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
577
                    result_raw_data[row].to_date_int_val() +
578
                    column_raw_data[row].to_date_int_val() *
579
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
580
        } else if constexpr (std::is_same_v<ColumnType, ColumnDateTimeV2Nano>) {
581
            if (!(null_map_data[row] | filled_flag[row])) {
582
                result_raw_data[row] = column_raw_data[row];
583
            }
584
        } else if constexpr (std::is_same_v<ColumnType, ColumnTimeStampTz>) {
585
            result_raw_data[row] = binary_cast<uint64_t, TimestampTzValue>(
586
                    result_raw_data[row].to_date_int_val() +
587
                    column_raw_data[row].to_date_int_val() *
588
                            uint64_t(!(null_map_data[row] | filled_flag[row])));
589
        } else if constexpr (std::is_same_v<ColumnType, ColumnDate> ||
590
                             std::is_same_v<ColumnType, ColumnDateTime>) {
591
            result_raw_data[row] = binary_cast<int64_t, VecDateTimeValue>(
592
                    binary_cast<VecDateTimeValue, int64_t>(result_raw_data[row]) +
593
                    binary_cast<VecDateTimeValue, int64_t>(column_raw_data[row]) *
594
                            int64_t(!(null_map_data[row] | filled_flag[row])));
595
        } else if constexpr (std::is_same_v<ColumnType, ColumnFloat32> ||
596
12
                             std::is_same_v<ColumnType, ColumnFloat64>) {
597
12
            auto flag = (!(null_map_data[row] | filled_flag[row]));
598
12
            result_raw_data[row] += std::isfinite(column_raw_data[row])
599
12
                                            ? column_raw_data[row] * flag
600
12
                                            : (flag ? column_raw_data[row] : 0);
601
        } else {
602
            result_raw_data[row] +=
603
                    column_raw_data[row] *
604
                    typename ColumnType::value_type(!(null_map_data[row] | filled_flag[row]));
605
        }
606
607
12
        filled_flag[row] += (!(null_map_data[row] | filled_flag[row]));
608
12
    }
609
6
}
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_13ColumnDecimalILNS_13PrimitiveTypeE28EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_13ColumnDecimalILNS_13PrimitiveTypeE29EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_13ColumnDecimalILNS_13PrimitiveTypeE20EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_13ColumnDecimalILNS_13PrimitiveTypeE30EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_13ColumnDecimalILNS_13PrimitiveTypeE35EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE11EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE25EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE26EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE12EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE27EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE42EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE36EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
Unexecuted instantiation: _ZN5doris18insert_result_dataINS_12ColumnVectorILNS_13PrimitiveTypeE37EEEEEvRNS_3COWINS_7IColumnEE11mutable_ptrIS5_EERNS6_13immutable_ptrIS5_EEPKhPhm
610
611
Status insert_result_data_bitmap(MutableColumnPtr& result_column, ColumnPtr& argument_column,
612
                                 const UInt8* __restrict null_map_data,
613
0
                                 UInt8* __restrict filled_flag, const size_t input_rows_count) {
614
0
    if (result_column->size() == 0 && input_rows_count) {
615
0
        result_column->resize(input_rows_count);
616
0
    }
617
618
0
    auto* __restrict result_raw_data =
619
0
            reinterpret_cast<ColumnBitmap*>(result_column.get())->get_data().data();
620
0
    auto* __restrict column_raw_data =
621
0
            reinterpret_cast<const ColumnBitmap*>(argument_column.get())->get_data().data();
622
623
    // Here it's SIMD thought the compiler automatically also
624
    // true: null_map_data[row]==0 && filled_idx[row]==0
625
    // if true, could filled current row data into result column
626
0
    for (size_t row = 0; row < input_rows_count; ++row) {
627
0
        if (!(null_map_data[row] | filled_flag[row])) {
628
0
            result_raw_data[row] = column_raw_data[row];
629
0
        }
630
0
        filled_flag[row] += (!(null_map_data[row] | filled_flag[row]));
631
0
    }
632
0
    return Status::OK();
633
0
}
634
635
Status filled_result_column(const DataTypePtr& data_type, MutableColumnPtr& result_column,
636
                            ColumnPtr& argument_column, UInt8* __restrict null_map_data,
637
16
                            UInt8* __restrict filled_flag, const size_t input_rows_count) {
638
16
    if (data_type->get_primitive_type() == TYPE_BITMAP) {
639
0
        return insert_result_data_bitmap(result_column, argument_column, null_map_data, filled_flag,
640
0
                                         input_rows_count);
641
0
    }
642
16
    if (data_type->get_primitive_type() == TYPE_DATETIMEV2_NANO) {
643
2
        insert_result_data<ColumnDateTimeV2Nano>(result_column, argument_column, null_map_data,
644
2
                                                 filled_flag, input_rows_count);
645
2
        return Status::OK();
646
2
    }
647
648
14
    auto call = [&](const auto& type) -> bool {
649
14
        using DispatchType = std::decay_t<decltype(type)>;
650
14
        insert_result_data<typename DispatchType::ColumnType>(
651
14
                result_column, argument_column, null_map_data, filled_flag, input_rows_count);
652
14
        return true;
653
14
    };
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE2EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE3EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE4EEEEEbRKT_
vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE5EEEEEbRKT_
Line
Count
Source
648
6
    auto call = [&](const auto& type) -> bool {
649
6
        using DispatchType = std::decay_t<decltype(type)>;
650
6
        insert_result_data<typename DispatchType::ColumnType>(
651
6
                result_column, argument_column, null_map_data, filled_flag, input_rows_count);
652
6
        return true;
653
6
    };
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE6EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE7EEEEEbRKT_
vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE8EEEEEbRKT_
Line
Count
Source
648
2
    auto call = [&](const auto& type) -> bool {
649
2
        using DispatchType = std::decay_t<decltype(type)>;
650
2
        insert_result_data<typename DispatchType::ColumnType>(
651
2
                result_column, argument_column, null_map_data, filled_flag, input_rows_count);
652
2
        return true;
653
2
    };
vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE9EEEEEbRKT_
Line
Count
Source
648
6
    auto call = [&](const auto& type) -> bool {
649
6
        using DispatchType = std::decay_t<decltype(type)>;
650
6
        insert_result_data<typename DispatchType::ColumnType>(
651
6
                result_column, argument_column, null_map_data, filled_flag, input_rows_count);
652
6
        return true;
653
6
    };
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE28EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE29EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE20EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE30EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE35EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE11EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE25EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE26EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE43EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE12EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE27EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE42EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE36EEEEEbRKT_
Unexecuted instantiation: vcondition_expr.cpp:_ZZN5doris20filled_result_columnERKSt10shared_ptrIKNS_9IDataTypeEERNS_3COWINS_7IColumnEE11mutable_ptrIS7_EERNS8_13immutable_ptrIS7_EEPhSF_mENK3$_0clINS_16DispatchDataTypeILNS_13PrimitiveTypeE37EEEEEbRKT_
654
655
14
    if (!dispatch_switch_scalar(data_type->get_primitive_type(), call)) {
656
0
        return Status::InternalError("not support type {} in coalesce", data_type->get_name());
657
0
    }
658
14
    return Status::OK();
659
14
}
660
661
Status VectorizedCoalesceExpr::execute_column_impl(VExprContext* context, const Block* block,
662
                                                   const Selector* selector, size_t count,
663
30
                                                   ColumnPtr& return_column) const {
664
30
    DataTypePtr result_type = _data_type;
665
30
    const auto input_rows_count = count;
666
667
30
    size_t remaining_rows = input_rows_count;
668
30
    std::vector<uint32_t> record_idx(
669
30
            input_rows_count,
670
30
            0); //used to save column idx, record the result data of each row from which column
671
30
    std::vector<uint8_t> filled_flags(
672
30
            input_rows_count,
673
30
            0); //used to save filled flag, in order to check current row whether have filled data
674
675
30
    MutableColumnPtr result_column;
676
30
    if (!result_type->is_nullable()) {
677
16
        result_column = result_type->create_column();
678
16
    } else {
679
14
        result_column = remove_nullable(result_type)->create_column();
680
14
    }
681
682
    // because now follow below types does not support random position writing,
683
    // so insert into result data have two methods, one is for these types, one is for others type remaining
684
30
    bool cannot_random_write = result_column->is_column_string() ||
685
30
                               result_type->get_primitive_type() == PrimitiveType::TYPE_MAP ||
686
30
                               result_type->get_primitive_type() == PrimitiveType::TYPE_STRUCT ||
687
30
                               result_type->get_primitive_type() == PrimitiveType::TYPE_ARRAY ||
688
30
                               result_type->get_primitive_type() == PrimitiveType::TYPE_VARIANT ||
689
30
                               result_type->get_primitive_type() == PrimitiveType::TYPE_JSONB;
690
30
    if (cannot_random_write) {
691
12
        result_column->reserve(input_rows_count);
692
12
    }
693
694
30
    auto return_type = std::make_shared<DataTypeUInt8>();
695
30
    auto null_map = ColumnUInt8::create(input_rows_count,
696
30
                                        1); //if null_map_data==1, the current row should be null
697
30
    auto* __restrict null_map_data = null_map->get_data().data();
698
699
52
    auto is_not_null = [](const ColumnPtr& column, size_t size) -> ColumnUInt8::MutablePtr {
700
52
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*column)) {
701
            /// Return the negated null map.
702
34
            auto res_column = ColumnUInt8::create(size);
703
34
            const auto* __restrict src_data = nullable->get_null_map_data().data();
704
34
            auto* __restrict res_data = res_column->get_data().data();
705
706
90
            for (size_t i = 0; i < size; ++i) {
707
56
                res_data[i] = !src_data[i];
708
56
            }
709
34
            return res_column;
710
34
        } else {
711
            /// Since no element is nullable, return a constant one.
712
18
            return ColumnUInt8::create(size, 1);
713
18
        }
714
52
    };
715
716
30
    std::vector<ColumnPtr> original_columns(_children.size());
717
30
    std::vector<ColumnPtr> argument_not_null_columns(_children.size());
718
719
62
    for (size_t i = 0; i < _children.size() && remaining_rows; ++i) {
720
        // Execute child expression to get the argument column.
721
52
        RETURN_IF_ERROR(
722
52
                _children[i]->execute_column(context, block, selector, count, original_columns[i]));
723
52
        original_columns[i] = original_columns[i]->convert_to_full_column_if_const();
724
52
        argument_not_null_columns[i] = original_columns[i];
725
52
        if (const auto* nullable =
726
52
                    check_and_get_column<const ColumnNullable>(*argument_not_null_columns[i])) {
727
34
            argument_not_null_columns[i] = nullable->get_nested_column_ptr();
728
34
        }
729
730
52
        auto res_column = is_not_null(original_columns[i], input_rows_count);
731
732
52
        auto& res_map = res_column->get_data();
733
52
        auto* __restrict res = res_map.data();
734
735
        // Here it's SIMD thought the compiler automatically
736
        // true: res[j]==1 && null_map_data[j]==1, false: others
737
        // if true: remaining_rows--; record_idx[j]=column_idx; null_map_data[j]=0, so the current row could fill result
738
148
        for (size_t j = 0; j < input_rows_count; ++j) {
739
96
            remaining_rows -= (res[j] & null_map_data[j]);
740
96
            record_idx[j] += (res[j] & null_map_data[j]) * i;
741
96
            null_map_data[j] -= (res[j] & null_map_data[j]);
742
96
        }
743
744
52
        if (remaining_rows == 0) {
745
            //check whether all result data from the same column
746
30
            size_t is_same_column_count = 0;
747
30
            const auto data = record_idx[0];
748
82
            for (size_t row = 0; row < input_rows_count; ++row) {
749
52
                is_same_column_count += (record_idx[row] == data);
750
52
            }
751
752
30
            if (is_same_column_count == input_rows_count) {
753
20
                if (result_type->is_nullable()) {
754
8
                    return_column = make_nullable(argument_not_null_columns[i]);
755
12
                } else {
756
12
                    return_column = argument_not_null_columns[i];
757
12
                }
758
20
                return Status::OK();
759
20
            }
760
30
        }
761
762
32
        if (!cannot_random_write) {
763
            //if not string type, could check one column firstly,
764
            //and then fill the not null value in result column,
765
            //this method may result in higher CPU cache
766
16
            RETURN_IF_ERROR(filled_result_column(result_type, result_column,
767
16
                                                 argument_not_null_columns[i], null_map_data,
768
16
                                                 filled_flags.data(), input_rows_count));
769
16
        }
770
32
    }
771
772
10
    if (cannot_random_write) {
773
        //if string type,  should according to the record results, fill in result one by one,
774
24
        for (size_t row = 0; row < input_rows_count; ++row) {
775
20
            if (null_map_data[row]) { //should be null
776
0
                result_column->insert_default();
777
20
            } else {
778
20
                result_column->insert_from(*argument_not_null_columns[record_idx[row]].get(), row);
779
20
            }
780
20
        }
781
4
    }
782
783
10
    if (result_type->is_nullable()) {
784
6
        return_column = ColumnNullable::create(std::move(result_column), std::move(null_map));
785
6
    } else {
786
4
        return_column = std::move(result_column);
787
4
    }
788
789
    DCHECK_EQ(return_column->size(), count);
790
10
    return Status::OK();
791
30
}
792
793
} // namespace doris