sparrow ..
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
28#include "sparrow/map_array.hpp"
42
43namespace sparrow
44{
45 template <class F>
46 using visit_result_t = std::invoke_result_t<F, null_array>;
47
48 template <class F>
49 [[nodiscard]] visit_result_t<F> visit(F&& func, const array_wrapper& ar)
50 {
51 if (ar.is_dictionary())
52 {
53 switch (ar.data_type())
54 {
57 case data_type::INT8:
71 default:
72 throw std::runtime_error("data datype of dictionary encoded array must be an integer");
73 }
74 }
75 else
76 {
77 switch (ar.data_type())
78 {
79 case data_type::NA:
80 return func(unwrap_array<null_array>(ar));
81 case data_type::BOOL:
82 return func(unwrap_array<primitive_array<bool>>(ar));
85 case data_type::INT8:
101 case data_type::FLOAT:
106 return func(unwrap_array<string_array>(ar));
108 return func(unwrap_array<string_view_array>(ar));
110 return func(unwrap_array<big_string_array>(ar));
112 return func(unwrap_array<binary_array>(ar));
114 return func(unwrap_array<binary_view_array>(ar));
116 return func(unwrap_array<big_binary_array>(ar));
119 case data_type::LIST:
120 return func(unwrap_array<list_array>(ar));
122 return func(unwrap_array<big_list_array>(ar));
124 return func(unwrap_array<list_view_array>(ar));
126 return func(unwrap_array<big_list_view_array>(ar));
130 return func(unwrap_array<struct_array>(ar));
131 case data_type::MAP:
132 return func(unwrap_array<map_array>(ar));
134 return func(unwrap_array<dense_union_array>(ar));
136 return func(unwrap_array<sparse_union_array>(ar));
138 return func(unwrap_array<decimal_32_array>(ar));
140 return func(unwrap_array<decimal_64_array>(ar));
142 return func(unwrap_array<decimal_128_array>(ar));
144 return func(unwrap_array<decimal_256_array>(ar));
148 return func(unwrap_array<date_days_array>(ar));
152 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
153 {
155 }
156 else
157 {
159 }
161 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
162 {
164 }
165 else
166 {
168 }
170 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
171 {
173 }
174 else
175 {
177 }
179 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
180 {
182 }
183 else
184 {
186 }
188 return func(unwrap_array<time_seconds_array>(ar));
209 default:
210 throw std::invalid_argument("array type not supported");
211 }
212 }
213 }
214}
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
Forward declaration of dictionary_encoded_array.
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:46
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:49