Coverage Report

Created: 2026-03-11 11:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/exprs/vcondition_expr.h
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
#pragma once
19
#include <string>
20
21
#include "common/status.h"
22
#include "core/block/column_numbers.h"
23
#include "exprs/function/function.h"
24
#include "exprs/function/if.h"
25
#include "exprs/function_context.h"
26
#include "exprs/vexpr.h"
27
#include "exprs/vexpr_context.h"
28
#include "exprs/vliteral.h"
29
#include "exprs/vslot_ref.h"
30
#include "runtime/runtime_state.h"
31
namespace doris {
32
class RowDescriptor;
33
class RuntimeState;
34
class TExprNode;
35
} // namespace doris
36
37
namespace doris {
38
39
class Block;
40
class VExprContext;
41
42
class VConditionExpr : public VExpr {
43
public:
44
0
    VConditionExpr(const TExprNode& node) : VExpr(node) {}
45
0
    ~VConditionExpr() override = default;
46
47
    Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) final;
48
    Status open(RuntimeState* state, VExprContext* context,
49
                FunctionContext::FunctionStateScope scope) final;
50
    void close(VExprContext* context, FunctionContext::FunctionStateScope scope) final;
51
52
    std::string debug_string() const override;
53
54
protected:
55
    static size_t count_true_with_notnull(const ColumnPtr& col);
56
};
57
58
class VectorizedIfExpr : public VConditionExpr {
59
    ENABLE_FACTORY_CREATOR(VectorizedIfExpr);
60
61
public:
62
0
    VectorizedIfExpr(const TExprNode& node) : VConditionExpr(node) {}
63
64
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
65
                          size_t count, ColumnPtr& result_column) const override;
66
67
0
    const std::string& expr_name() const override { return IF_NAME; }
68
    inline static const std::string IF_NAME = "if";
69
70
protected:
71
    Status _execute_impl_internal(Block& block, const ColumnNumbers& arguments, uint32_t result,
72
                                  size_t input_rows_count) const;
73
74
private:
75
    template <PrimitiveType PType>
76
    Status execute_basic_type(Block& block, const ColumnUInt8* cond_col,
77
                              const ColumnWithTypeAndName& then_col,
78
                              const ColumnWithTypeAndName& else_col, uint32_t result,
79
0
                              Status& status) const {
80
0
        if (then_col.type->get_primitive_type() != else_col.type->get_primitive_type()) {
81
0
            return Status::InternalError(
82
0
                    "then and else column type must be same for function {} , but got {} , {}",
83
0
                    expr_name(), then_col.type->get_name(), else_col.type->get_name());
84
0
        }
85
86
0
        auto res_column =
87
0
                NumIfImpl<PType>::execute_if(cond_col->get_data(), then_col.column, else_col.column,
88
0
                                             block.get_by_position(result).type->get_scale());
89
0
        if (!res_column) {
90
0
            return Status::InternalError("unexpected args column {} , {} , of function {}",
91
0
                                         then_col.column->get_name(), else_col.column->get_name(),
92
0
                                         expr_name());
93
0
        }
94
0
        block.replace_by_position(result, std::move(res_column));
95
0
        return Status::OK();
96
0
    }
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE2EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE3EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE4EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE5EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE6EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE7EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE8EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE9EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE28EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE29EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE20EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE30EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE35EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE11EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE25EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE26EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE12EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE27EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE42EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE36EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
Unexecuted instantiation: _ZNK5doris16VectorizedIfExpr18execute_basic_typeILNS_13PrimitiveTypeE37EEENS_6StatusERNS_5BlockEPKNS_12ColumnVectorILS2_2EEERKNS_21ColumnWithTypeAndNameESC_jRS3_
97
98
    Status execute_generic(Block& block, const ColumnUInt8* cond_col,
99
                           const ColumnWithTypeAndName& then_col_type_name,
100
                           const ColumnWithTypeAndName& else_col_type_name, uint32_t result,
101
                           size_t input_row_count) const;
102
103
    Status execute_for_null_then_else(Block& block, const ColumnWithTypeAndName& arg_cond,
104
                                      const ColumnWithTypeAndName& arg_then,
105
                                      const ColumnWithTypeAndName& arg_else, uint32_t result,
106
                                      size_t input_rows_count, bool& handled) const;
107
108
    Status execute_for_null_condition(Block& block, const ColumnNumbers& arguments,
109
                                      const ColumnWithTypeAndName& arg_cond,
110
                                      const ColumnWithTypeAndName& arg_then,
111
                                      const ColumnWithTypeAndName& arg_else, uint32_t result,
112
                                      bool& handled) const;
113
114
    Status execute_for_nullable_then_else(Block& block, const ColumnWithTypeAndName& arg_cond,
115
                                          const ColumnWithTypeAndName& arg_then,
116
                                          const ColumnWithTypeAndName& arg_else, uint32_t result,
117
                                          size_t input_rows_count, bool& handled) const;
118
};
119
120
class VectorizedIfNullExpr : public VectorizedIfExpr {
121
    ENABLE_FACTORY_CREATOR(VectorizedIfNullExpr);
122
123
public:
124
0
    VectorizedIfNullExpr(const TExprNode& node) : VectorizedIfExpr(node) {}
125
0
    const std::string& expr_name() const override { return IF_NULL_NAME; }
126
    inline static const std::string IF_NULL_NAME = "ifnull";
127
128
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
129
                          size_t count, ColumnPtr& result_column) const override;
130
};
131
132
class VectorizedCoalesceExpr : public VConditionExpr {
133
    ENABLE_FACTORY_CREATOR(VectorizedCoalesceExpr);
134
135
public:
136
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
137
                          size_t count, ColumnPtr& result_column) const override;
138
0
    VectorizedCoalesceExpr(const TExprNode& node) : VConditionExpr(node) {}
139
0
    const std::string& expr_name() const override { return NAME; }
140
    inline static const std::string NAME = "coalesce";
141
};
142
143
} // namespace doris