Coverage Report

Created: 2026-05-27 11:25

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