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 <functional> |
21 | | #include <string> |
22 | | |
23 | | #include "common/object_pool.h" |
24 | | #include "common/status.h" |
25 | | #include "core/block/column_with_type_and_name.h" |
26 | | #include "exprs/function_context.h" |
27 | | #include "exprs/vexpr.h" |
28 | | |
29 | | namespace doris { |
30 | | class RowDescriptor; |
31 | | class RuntimeState; |
32 | | class TExprNode; |
33 | | class Block; |
34 | | class VExprContext; |
35 | | struct CastOptions; |
36 | | } // namespace doris |
37 | | |
38 | | namespace doris::format { |
39 | | |
40 | | class Cast : public VExpr { |
41 | | ENABLE_FACTORY_CREATOR(Cast); |
42 | | |
43 | | public: |
44 | 218 | Cast(const DataTypePtr& type) { |
45 | 218 | _node_type = TExprNodeType::CAST_EXPR; |
46 | 218 | _opcode = TExprOpcode::CAST; |
47 | 218 | _data_type = type; |
48 | 218 | } |
49 | 218 | ~Cast() override = default; |
50 | | Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) override; |
51 | | Status open(RuntimeState* state, VExprContext* context, |
52 | | FunctionContext::FunctionStateScope scope) override; |
53 | | void close(VExprContext* context, FunctionContext::FunctionStateScope scope) override; |
54 | | Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector, |
55 | | size_t count, ColumnPtr& result_column) const override; |
56 | | std::string debug_string() const override; |
57 | 0 | uint64_t get_digest(uint64_t seed) const override { return 0; } |
58 | 63 | const std::string& expr_name() const override { return _expr_name; } |
59 | | // Ordinary CAST can fail for data-dependent input. Localization must retain the same |
60 | | // full-batch error behavior as VCastExpr instead of hiding errors in previously rejected rows. |
61 | 6 | bool is_safe_to_execute_on_selected_rows() const override { return false; } |
62 | 9 | Status clone_node(VExprSPtr* cloned_expr) const override { |
63 | 9 | DORIS_CHECK(cloned_expr != nullptr); |
64 | 9 | *cloned_expr = Cast::create_shared(_data_type); |
65 | 9 | return Status::OK(); |
66 | 9 | } |
67 | | |
68 | | protected: |
69 | 15 | virtual void configure_cast_options(CastOptions& /*options*/) const {} |
70 | | |
71 | | private: |
72 | | Status _do_execute(VExprContext* context, const Block* block, const Selector* selector, |
73 | | size_t count, ColumnPtr& result_column) const; |
74 | | using CastExecutor = |
75 | | std::function<Status(RuntimeState*, const ColumnWithTypeAndName&, |
76 | | ColumnWithTypeAndName&, size_t, const NullMap::value_type*)>; |
77 | | std::string _expr_name; |
78 | | CastExecutor _cast_executor; |
79 | | RuntimeState* _runtime_state = nullptr; |
80 | | }; |
81 | | |
82 | 417 | inline bool is_cast_expr(const VExprSPtr& expr) { |
83 | 417 | return dynamic_cast<const Cast*>(expr.get()) != nullptr; |
84 | 417 | } |
85 | | |
86 | | } // namespace doris::format |