Coverage Report

Created: 2026-04-14 03:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vliteral.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/vliteral.h"
19
20
#include <fmt/format.h>
21
#include <gen_cpp/Exprs_types.h>
22
#include <gen_cpp/Types_types.h>
23
#include <glog/logging.h>
24
#include <sys/types.h>
25
26
#include <algorithm>
27
#include <ostream>
28
29
#include "core/block/block.h"
30
#include "core/column/column.h"
31
#include "core/data_type/data_type_decimal.h"
32
#include "core/field.h"
33
#include "core/types.h"
34
#include "exprs/aggregate/aggregate_function.h"
35
36
namespace doris {
37
38
class VExprContext;
39
40
625k
void VLiteral::init(const TExprNode& node) {
41
625k
    Field field;
42
625k
    field = _data_type->get_field(node);
43
625k
    _column_ptr = _data_type->create_column_const(1, field);
44
625k
}
45
46
621k
Status VLiteral::prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) {
47
621k
    RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
48
621k
    return Status::OK();
49
621k
}
50
51
Status VLiteral::execute_column(VExprContext* context, const Block* block, Selector* selector,
52
900k
                                size_t count, ColumnPtr& result_column) const {
53
900k
    DCHECK(selector == nullptr || selector->size() == count);
54
900k
    result_column = _column_ptr->clone_resized(count);
55
900k
    DCHECK_EQ(result_column->size(), count);
56
900k
    return Status::OK();
57
900k
}
58
59
571
std::string VLiteral::value(const DataTypeSerDe::FormatOptions& options) const {
60
571
    DCHECK(_column_ptr->size() == 1);
61
571
    return _data_type->to_string(*_column_ptr, 0, options);
62
571
}
63
64
#ifdef BE_TEST
65
std::string VLiteral::value() const {
66
    auto format_options = DataTypeSerDe::get_default_format_options();
67
    auto timezone = cctz::utc_time_zone();
68
    format_options.timezone = &timezone;
69
    return value(format_options);
70
}
71
#endif
72
73
528
std::string VLiteral::debug_string() const {
74
528
    auto format_options = DataTypeSerDe::get_default_format_options();
75
528
    auto timezone = cctz::utc_time_zone();
76
528
    format_options.timezone = &timezone;
77
78
528
    std::stringstream out;
79
528
    out << "VLiteral (name = " << _expr_name;
80
528
    out << ", type = " << _data_type->get_name();
81
528
    out << ", value = (" << value(format_options);
82
528
    out << "))";
83
528
    return out.str();
84
528
}
85
86
0
bool VLiteral::equals(const VExpr& other) {
87
0
    const auto* other_ptr = dynamic_cast<const VLiteral*>(&other);
88
0
    if (!other_ptr) {
89
0
        return false;
90
0
    }
91
0
    if (this->_expr_name != other_ptr->_expr_name) {
92
0
        return false;
93
0
    }
94
0
    if (this->_column_ptr->structure_equals(*other_ptr->_column_ptr)) {
95
0
        if (this->_column_ptr->size() != other_ptr->_column_ptr->size()) {
96
0
            return false;
97
0
        }
98
0
        for (size_t i = 0; i < this->_column_ptr->size(); i++) {
99
0
            if (this->_column_ptr->compare_at(i, i, *other_ptr->_column_ptr, -1) != 0) {
100
0
                return false;
101
0
            }
102
0
        }
103
0
    }
104
0
    return true;
105
0
}
106
107
189k
uint64_t VLiteral::get_digest(uint64_t seed) const {
108
189k
    _column_ptr->update_xxHash_with_value(0, 1, seed, nullptr);
109
189k
    return seed;
110
189k
}
111
112
} // namespace doris