sparrow 0.9.0
Loading...
Searching...
No Matches
dispatch.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <type_traits>
18
41
42namespace sparrow
43{
44 template <class F>
45 using visit_result_t = std::invoke_result_t<F, null_array>;
46
47 template <class F>
48 [[nodiscard]] visit_result_t<F> visit(F&& func, const array_wrapper& ar)
49 {
50 if (ar.is_dictionary())
51 {
52 switch (ar.data_type())
53 {
56 case data_type::INT8:
70 default:
71 throw std::runtime_error("data datype of dictionary encoded array must be an integer");
72 }
73 }
74 else
75 {
76 switch (ar.data_type())
77 {
78 case data_type::NA:
79 return func(unwrap_array<null_array>(ar));
80 case data_type::BOOL:
81 return func(unwrap_array<primitive_array<bool>>(ar));
84 case data_type::INT8:
100 case data_type::FLOAT:
105 return func(unwrap_array<string_array>(ar));
107 return func(unwrap_array<big_string_array>(ar));
109 return func(unwrap_array<binary_array>(ar));
111 return func(unwrap_array<big_binary_array>(ar));
114 case data_type::LIST:
115 return func(unwrap_array<list_array>(ar));
117 return func(unwrap_array<big_list_array>(ar));
119 return func(unwrap_array<list_view_array>(ar));
121 return func(unwrap_array<big_list_view_array>(ar));
125 return func(unwrap_array<struct_array>(ar));
126 case data_type::MAP:
127 return func(unwrap_array<map_array>(ar));
129 return func(unwrap_array<dense_union_array>(ar));
131 return func(unwrap_array<sparse_union_array>(ar));
133 return func(unwrap_array<decimal_32_array>(ar));
135 return func(unwrap_array<decimal_64_array>(ar));
137 return func(unwrap_array<decimal_128_array>(ar));
139 return func(unwrap_array<decimal_256_array>(ar));
143 return func(unwrap_array<date_days_array>(ar));
147 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
148 {
150 }
151 else
152 {
154 }
156 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
157 {
159 }
160 else
161 {
163 }
165 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
166 {
168 }
169 else
170 {
172 }
174 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
175 {
177 }
178 else
179 {
181 }
183 return func(unwrap_array<time_seconds_array>(ar));
204 default:
205 throw std::invalid_argument("array type not supported");
206 }
207 }
208 }
209}
Base class for array type erasure.
constexpr bool is_dictionary() const
constexpr arrow_proxy & get_arrow_proxy()
constexpr enum data_type data_type() const noexcept
SPARROW_API const date::time_zone * get_timezone(const arrow_proxy &proxy)
primitive_array_impl< T > primitive_array
Array of values of whose type has fixed binary size.
T & unwrap_array(array_wrapper &)
std::invoke_result_t< F, null_array > visit_result_t
Definition dispatch.hpp:45
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:48