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
40
41namespace sparrow
42{
43 template <class F>
44 using visit_result_t = std::invoke_result_t<F, null_array>;
45
46 template <class F>
47 [[nodiscard]] visit_result_t<F> visit(F&& func, const array_wrapper& ar)
48 {
49 if (ar.is_dictionary())
50 {
51 switch (ar.data_type())
52 {
55 case data_type::INT8:
69 default:
70 throw std::runtime_error("data datype of dictionary encoded array must be an integer");
71 }
72 }
73 else
74 {
75 switch (ar.data_type())
76 {
77 case data_type::NA:
78 return func(unwrap_array<null_array>(ar));
79 case data_type::BOOL:
80 return func(unwrap_array<primitive_array<bool>>(ar));
83 case data_type::INT8:
104 return func(unwrap_array<string_array>(ar));
106 return func(unwrap_array<big_string_array>(ar));
108 return func(unwrap_array<binary_array>(ar));
110 return func(unwrap_array<big_binary_array>(ar));
113 case data_type::LIST:
114 return func(unwrap_array<list_array>(ar));
116 return func(unwrap_array<big_list_array>(ar));
118 return func(unwrap_array<list_view_array>(ar));
120 return func(unwrap_array<big_list_view_array>(ar));
124 return func(unwrap_array<struct_array>(ar));
126 return func(unwrap_array<dense_union_array>(ar));
128 return func(unwrap_array<sparse_union_array>(ar));
130 return func(unwrap_array<decimal_32_array>(ar));
132 return func(unwrap_array<decimal_64_array>(ar));
134 return func(unwrap_array<decimal_128_array>(ar));
136 return func(unwrap_array<decimal_256_array>(ar));
140 return func(unwrap_array<date_days_array>(ar));
144 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
145 {
147 }
148 else
149 {
151 }
153 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
154 {
156 }
157 else
158 {
160 }
162 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
163 {
165 }
166 else
167 {
169 }
171 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
172 {
174 }
175 else
176 {
178 }
180 return func(unwrap_array<time_seconds_array>(ar));
201 default:
202 throw std::invalid_argument("array type not supported");
203 }
204 }
205 }
206}
Base class for array type erasure.
arrow_proxy & get_arrow_proxy()
enum data_type data_type() const
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:44
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:47