1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/function/cast/bound_cast_data.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/function/cast/default_casts.hpp" |
12 | |
13 | namespace duckdb { |
14 | |
15 | struct ListBoundCastData : public BoundCastData { |
16 | explicit ListBoundCastData(BoundCastInfo child_cast) : child_cast_info(std::move(child_cast)) { |
17 | } |
18 | |
19 | BoundCastInfo child_cast_info; |
20 | static unique_ptr<BoundCastData> BindListToListCast(BindCastInput &input, const LogicalType &source, |
21 | const LogicalType &target); |
22 | static unique_ptr<FunctionLocalState> InitListLocalState(CastLocalStateParameters ¶meters); |
23 | |
24 | public: |
25 | unique_ptr<BoundCastData> Copy() const override { |
26 | return make_uniq<ListBoundCastData>(args: child_cast_info.Copy()); |
27 | } |
28 | }; |
29 | |
30 | struct ListCast { |
31 | static bool ListToListCast(Vector &source, Vector &result, idx_t count, CastParameters ¶meters); |
32 | }; |
33 | |
34 | struct StructBoundCastData : public BoundCastData { |
35 | StructBoundCastData(vector<BoundCastInfo> child_casts, LogicalType target_p) |
36 | : child_cast_info(std::move(child_casts)), target(std::move(target_p)) { |
37 | } |
38 | |
39 | vector<BoundCastInfo> child_cast_info; |
40 | LogicalType target; |
41 | |
42 | static unique_ptr<BoundCastData> BindStructToStructCast(BindCastInput &input, const LogicalType &source, |
43 | const LogicalType &target); |
44 | static unique_ptr<FunctionLocalState> InitStructCastLocalState(CastLocalStateParameters ¶meters); |
45 | |
46 | public: |
47 | unique_ptr<BoundCastData> Copy() const override { |
48 | vector<BoundCastInfo> copy_info; |
49 | for (auto &info : child_cast_info) { |
50 | copy_info.push_back(x: info.Copy()); |
51 | } |
52 | return make_uniq<StructBoundCastData>(args: std::move(copy_info), args: target); |
53 | } |
54 | }; |
55 | |
56 | struct StructCastLocalState : public FunctionLocalState { |
57 | public: |
58 | vector<unique_ptr<FunctionLocalState>> local_states; |
59 | }; |
60 | |
61 | struct MapBoundCastData : public BoundCastData { |
62 | MapBoundCastData(BoundCastInfo key_cast, BoundCastInfo value_cast) |
63 | : key_cast(std::move(key_cast)), value_cast(std::move(value_cast)) { |
64 | } |
65 | |
66 | BoundCastInfo key_cast; |
67 | BoundCastInfo value_cast; |
68 | |
69 | static unique_ptr<BoundCastData> BindMapToMapCast(BindCastInput &input, const LogicalType &source, |
70 | const LogicalType &target); |
71 | |
72 | public: |
73 | unique_ptr<BoundCastData> Copy() const override { |
74 | return make_uniq<MapBoundCastData>(args: key_cast.Copy(), args: value_cast.Copy()); |
75 | } |
76 | }; |
77 | |
78 | struct MapCastLocalState : public FunctionLocalState { |
79 | public: |
80 | unique_ptr<FunctionLocalState> key_state; |
81 | unique_ptr<FunctionLocalState> value_state; |
82 | }; |
83 | |
84 | } // namespace duckdb |
85 | |