Coverage Report

Created: 2026-06-27 16:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vliteral.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
20
#include <memory>
21
#include <string>
22
23
#include "common/object_pool.h"
24
#include "common/status.h"
25
#include "core/data_type/data_type.h"
26
#include "core/data_type_serde/data_type_serde.h"
27
#include "core/field.h"
28
#include "exprs/vexpr.h"
29
30
namespace doris {
31
class TExprNode;
32
33
class Block;
34
class VExprContext;
35
36
class VLiteral : public VExpr {
37
    ENABLE_FACTORY_CREATOR(VLiteral);
38
39
public:
40
    VLiteral(const TExprNode& node, bool should_init = true)
41
324
            : VExpr(node), _expr_name(_data_type->get_name()) {
42
324
        if (should_init) {
43
309
            Field field;
44
309
            field = _data_type->get_field(node);
45
309
            _column_ptr = _data_type->create_column_const(1, field);
46
309
        }
47
324
    }
48
49
325
    VLiteral(const DataTypePtr& type, const Field& field) : VExpr(type, false) {
50
325
        _data_type = type;
51
325
        _column_ptr = _data_type->create_column_const(1, field);
52
325
        _node_type = TExprNodeType::LITERAL;
53
325
        _expr_name = _data_type->get_name();
54
325
    }
55
56
#ifdef BE_TEST
57
168
    VLiteral() = default;
58
    MOCK_FUNCTION std::string value() const;
59
#endif
60
61
    Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) override;
62
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
63
                               size_t count, ColumnPtr& result_column) const override;
64
65
341
    const std::string& expr_name() const override { return _expr_name; }
66
    std::string debug_string() const override;
67
68
8
    double execute_cost() const override { return 0.0; }
69
70
    MOCK_FUNCTION std::string value(const DataTypeSerDe::FormatOptions& options) const;
71
72
498
    const ColumnPtr& get_column_ptr() const { return _column_ptr; }
73
14
    const DataTypePtr& get_data_type() const { return _data_type; }
74
75
645
    bool is_literal() const override { return true; }
76
77
    bool equals(const VExpr& other) override;
78
79
    uint64_t get_digest(uint64_t seed) const override;
80
121
    Status clone_node(VExprSPtr* cloned_expr) const override {
81
121
        DORIS_CHECK(cloned_expr != nullptr);
82
121
        Field field;
83
121
        _column_ptr->get(0, field);
84
121
        *cloned_expr = VLiteral::create_shared(_data_type, field);
85
121
        return Status::OK();
86
121
    }
87
88
protected:
89
0
    VLiteral(const DataTypePtr& type) : VExpr(type, false) {}
90
    ColumnPtr _column_ptr;
91
    std::string _expr_name;
92
};
93
94
} // namespace doris