Coverage Report

Created: 2026-03-15 22:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/short_circuit_evaluation_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
#include <vector>
21
22
#include "common/status.h"
23
#include "exprs/vexpr.h"
24
#include "exprs/vexpr_context.h"
25
#include "runtime/runtime_state.h"
26
27
namespace doris {
28
29
class Block;
30
class VExprContext;
31
struct ColumnAndSelector;
32
33
class ShortCircuitExpr : public VExpr {
34
public:
35
0
    ShortCircuitExpr(const TExprNode& node) : VExpr(node) {}
36
0
    ~ShortCircuitExpr() override = default;
37
    Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) final;
38
    Status open(RuntimeState* state, VExprContext* context,
39
                FunctionContext::FunctionStateScope scope) final;
40
    void close(VExprContext* context, FunctionContext::FunctionStateScope scope) final;
41
42
    std::string debug_string() const final;
43
44
protected:
45
    // Helper method to dispatch fill operation for two-branch case (e.g., IF, IFNULL).
46
    // Uses ScalarFillWithSelector for scalar types, NonScalarFillWithSelector otherwise.
47
    [[nodiscard]] ColumnPtr dispatch_fill_columns(const ColumnPtr& true_column,
48
                                                  const Selector& true_selector,
49
                                                  const ColumnPtr& false_column,
50
                                                  const Selector& false_selector,
51
                                                  size_t count) const;
52
53
    // Helper method to dispatch fill operation for multi-branch case (e.g., COALESCE, CASE).
54
    // Uses ScalarFillWithSelector for scalar types, NonScalarFillWithSelector otherwise.
55
    [[nodiscard]] ColumnPtr dispatch_fill_columns(
56
            const std::vector<ColumnAndSelector>& columns_and_selectors, size_t count) const;
57
};
58
59
class ShortCircuitIfExpr final : public ShortCircuitExpr {
60
public:
61
    ENABLE_FACTORY_CREATOR(ShortCircuitIfExpr);
62
0
    ShortCircuitIfExpr(const TExprNode& node) : ShortCircuitExpr(node) {}
63
0
    ~ShortCircuitIfExpr() override = default;
64
65
0
    const std::string& expr_name() const override { return IF_NAME; }
66
67
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
68
                          size_t count, ColumnPtr& result_column) const override;
69
70
private:
71
    inline static const std::string IF_NAME = "if";
72
};
73
class ShortCircuitCaseExpr final : public ShortCircuitExpr {
74
public:
75
    ENABLE_FACTORY_CREATOR(ShortCircuitCaseExpr);
76
    ShortCircuitCaseExpr(const TExprNode& node);
77
0
    ~ShortCircuitCaseExpr() override = default;
78
0
    const std::string& expr_name() const override { return CASE_NAME; }
79
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
80
                          size_t count, ColumnPtr& result_column) const override;
81
82
private:
83
    const bool _has_else_expr;
84
    inline static const std::string CASE_NAME = "case";
85
};
86
87
class ShortCircuitIfNullExpr final : public ShortCircuitExpr {
88
public:
89
    ENABLE_FACTORY_CREATOR(ShortCircuitIfNullExpr);
90
0
    ShortCircuitIfNullExpr(const TExprNode& node) : ShortCircuitExpr(node) {}
91
0
    ~ShortCircuitIfNullExpr() override = default;
92
93
0
    const std::string& expr_name() const override { return IFNULL_NAME; }
94
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
95
                          size_t count, ColumnPtr& result_column) const override;
96
97
private:
98
    inline static const std::string IFNULL_NAME = "ifnull";
99
};
100
101
class ShortCircuitCoalesceExpr final : public ShortCircuitExpr {
102
public:
103
    ENABLE_FACTORY_CREATOR(ShortCircuitCoalesceExpr);
104
0
    ShortCircuitCoalesceExpr(const TExprNode& node) : ShortCircuitExpr(node) {}
105
0
    ~ShortCircuitCoalesceExpr() override = default;
106
0
    const std::string& expr_name() const override { return COALESCE_NAME; }
107
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
108
                          size_t count, ColumnPtr& result_column) const override;
109
110
private:
111
    inline static const std::string COALESCE_NAME = "coalesce";
112
};
113
} // namespace doris