Coverage Report

Created: 2024-11-20 16:51

/root/doris/be/src/vec/exprs/vliteral.cpp
Line
Count
Source (jump to first uncovered line)
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 "vec/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 "vec/aggregate_functions/aggregate_function.h"
30
#include "vec/columns/column.h"
31
#include "vec/core/block.h"
32
#include "vec/core/field.h"
33
#include "vec/core/types.h"
34
#include "vec/data_types/data_type_decimal.h"
35
36
namespace doris::vectorized {
37
#include "common/compile_check_begin.h"
38
39
class VExprContext;
40
41
14
void VLiteral::init(const TExprNode& node) {
42
14
    Field field;
43
14
    field = _data_type->get_field(node);
44
14
    _column_ptr = _data_type->create_column_const(1, field);
45
14
}
46
47
0
Status VLiteral::prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) {
48
0
    RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
49
0
    return Status::OK();
50
0
}
51
52
14
Status VLiteral::execute(VExprContext* context, vectorized::Block* block, int* result_column_id) {
53
    // Literal expr should return least one row.
54
    // sometimes we just use a VLiteral without open or prepare. so can't check it at this moment
55
14
    size_t row_size = std::max(block->rows(), _column_ptr->size());
56
14
    *result_column_id = VExpr::insert_param(block, {_column_ptr, _data_type, _expr_name}, row_size);
57
14
    return Status::OK();
58
14
}
59
60
14
std::string VLiteral::value() const {
61
14
    DCHECK(_column_ptr->size() == 1);
62
14
    return _data_type->to_string(*_column_ptr, 0);
63
14
}
64
65
0
std::string VLiteral::debug_string() const {
66
0
    std::stringstream out;
67
0
    out << "VLiteral (name = " << _expr_name;
68
0
    out << ", type = " << _data_type->get_name();
69
0
    out << ", value = (" << value();
70
0
    out << "))";
71
0
    return out.str();
72
0
}
73
74
0
bool VLiteral::equals(const VExpr& other) {
75
0
    const auto* other_ptr = dynamic_cast<const VLiteral*>(&other);
76
0
    if (!other_ptr) {
77
0
        return false;
78
0
    }
79
0
    if (this->_expr_name != other_ptr->_expr_name) {
80
0
        return false;
81
0
    }
82
0
    if (this->_column_ptr->structure_equals(*other_ptr->_column_ptr)) {
83
0
        if (this->_column_ptr->size() != other_ptr->_column_ptr->size()) {
84
0
            return false;
85
0
        }
86
0
        for (size_t i = 0; i < this->_column_ptr->size(); i++) {
87
0
            if (this->_column_ptr->compare_at(i, i, *other_ptr->_column_ptr, -1) != 0) {
88
0
                return false;
89
0
            }
90
0
        }
91
0
    }
92
0
    return true;
93
0
}
94
95
#include "common/compile_check_end.h"
96
} // namespace doris::vectorized