Coverage Report

Created: 2026-09-19 14:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/expr/cast.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 <string>
21
22
#include "common/object_pool.h"
23
#include "common/status.h"
24
#include "exprs/function_context.h"
25
#include "exprs/vexpr.h"
26
27
namespace doris {
28
class RowDescriptor;
29
class RuntimeState;
30
class TExprNode;
31
class Block;
32
class VExprContext;
33
} // namespace doris
34
35
namespace doris::format {
36
37
class Cast final : public VExpr {
38
    ENABLE_FACTORY_CREATOR(Cast);
39
40
public:
41
    Cast(const DataTypePtr& type, bool truncate_datetimev2_precision = false)
42
148
            : _truncate_datetimev2_precision(truncate_datetimev2_precision) {
43
148
        _node_type = TExprNodeType::CAST_EXPR;
44
148
        _opcode = TExprOpcode::CAST;
45
148
        _data_type = type;
46
148
    }
47
148
    ~Cast() override = default;
48
    Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) override;
49
    Status open(RuntimeState* state, VExprContext* context,
50
                FunctionContext::FunctionStateScope scope) override;
51
    void close(VExprContext* context, FunctionContext::FunctionStateScope scope) override;
52
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
53
                               size_t count, ColumnPtr& result_column) const override;
54
    std::string debug_string() const override;
55
0
    uint64_t get_digest(uint64_t seed) const override { return 0; }
56
25
    const std::string& expr_name() const override { return _expr_name; }
57
    // Ordinary CAST can fail for data-dependent input. Localization must retain the same
58
    // full-batch error behavior as VCastExpr instead of hiding errors in previously rejected rows.
59
3
    bool is_safe_to_execute_on_selected_rows() const override { return false; }
60
10
    Status clone_node(VExprSPtr* cloned_expr) const override {
61
10
        DORIS_CHECK(cloned_expr != nullptr);
62
10
        *cloned_expr = Cast::create_shared(_data_type, _truncate_datetimev2_precision);
63
10
        return Status::OK();
64
10
    }
65
66
private:
67
    Status _do_execute(VExprContext* context, const Block* block, const Selector* selector,
68
                       size_t count, ColumnPtr& result_column) const;
69
    std::string _expr_name;
70
    FunctionBasePtr _function;
71
    bool _truncate_datetimev2_precision = false;
72
};
73
74
353
inline bool is_cast_expr(const VExprSPtr& expr) {
75
353
    return dynamic_cast<const Cast*>(expr.get()) != nullptr;
76
353
}
77
78
} // namespace doris::format