Coverage Report

Created: 2026-06-26 13:37

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