Coverage Report

Created: 2026-06-30 21:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vcolumn_ref.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 <atomic>
20
21
#include "exprs/function/function.h"
22
#include "exprs/vexpr.h"
23
#include "runtime/descriptors.h"
24
#include "runtime/runtime_state.h"
25
26
namespace doris {
27
class VColumnRef final : public VExpr {
28
    ENABLE_FACTORY_CREATOR(VColumnRef);
29
30
public:
31
    //this is different of slotref is using slot_id find a column_id
32
    //slotref: need to find the equal id in tuple, then return column_id, the plan of FE is very important
33
    //columnref: is columnid = slotid, not used to find, so you should know this column placed in block
34
    VColumnRef(const TExprNode& node)
35
1.33k
            : VExpr(node),
36
1.33k
              _column_id(node.column_ref.column_id),
37
1.33k
              _column_name(node.column_ref.column_name) {}
38
39
1.33k
    Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) override {
40
1.33k
        RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
41
1.33k
        DCHECK_EQ(_children.size(), 0);
42
1.33k
        if (_column_id < 0) {
43
0
            return Status::InternalError(
44
0
                    "VColumnRef have invalid slot id: {}, _column_name: {}, desc: {}", _column_id,
45
0
                    _column_name, desc.debug_string());
46
0
        }
47
1.33k
        _prepare_finished = true;
48
1.33k
        return Status::OK();
49
1.33k
    }
50
51
    Status open(RuntimeState* state, VExprContext* context,
52
6.13k
                FunctionContext::FunctionStateScope scope) override {
53
6.13k
        DCHECK(_prepare_finished);
54
6.13k
        RETURN_IF_ERROR(VExpr::open(state, context, scope));
55
6.13k
        _open_finished = true;
56
6.13k
        return Status::OK();
57
6.13k
    }
58
59
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
60
15.9k
                               size_t count, ColumnPtr& result_column) const override {
61
15.9k
        DCHECK(_open_finished || block == nullptr);
62
15.9k
        auto origin_column = block->get_by_position(_column_id + _gap).column;
63
15.9k
        result_column = filter_column_with_selector(origin_column, selector, count);
64
15.9k
        return Status::OK();
65
15.9k
    }
66
67
32.0k
    DataTypePtr execute_type(const Block* block) const override {
68
32.0k
        DCHECK(_open_finished || block == nullptr);
69
32.0k
        return block->get_by_position(_column_id + _gap).type;
70
32.0k
    }
71
72
21.2k
    bool is_constant() const override { return false; }
73
74
0
    int column_id() const { return _column_id; }
75
76
18.4k
    const std::string& expr_name() const override { return _column_name; }
77
78
40
    void set_gap(int gap) {
79
40
        if (_gap == 0) {
80
16
            _gap = gap;
81
16
        }
82
40
    }
83
84
0
    Status clone_node(VExprSPtr* cloned_expr) const override {
85
0
        DORIS_CHECK(cloned_expr != nullptr);
86
0
        auto node = clone_texpr_node();
87
0
        TColumnRef column_ref;
88
0
        column_ref.__set_column_id(_column_id);
89
0
        column_ref.__set_column_name(_column_name);
90
0
        node.__set_column_ref(column_ref);
91
0
        auto cloned = VColumnRef::create_shared(node);
92
0
        cloned->set_gap(_gap.load());
93
0
        *cloned_expr = std::move(cloned);
94
0
        return Status::OK();
95
0
    }
96
97
0
    std::string debug_string() const override {
98
0
        std::stringstream out;
99
0
        out << "VColumnRef(slot_id: " << _column_id << ",column_name: " << _column_name
100
0
            << VExpr::debug_string() << ")";
101
0
        return out.str();
102
0
    }
103
104
67
    double execute_cost() const override { return 0.0; }
105
106
private:
107
    int _column_id;
108
    std::atomic<int> _gap = 0;
109
    std::string _column_name;
110
};
111
} // namespace doris