sparrow 1.3.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
28#include "sparrow/map_array.hpp"
43
44namespace sparrow
45{
46 template <class F>
47 using visit_result_t = std::invoke_result_t<F, null_array>;
48
49 template <class F>
50 [[nodiscard]] visit_result_t<F> visit(F&& func, const array_wrapper& ar)
51 {
52 if (ar.is_dictionary())
53 {
54 switch (ar.data_type())
55 {
58 case data_type::INT8:
72 default:
73 throw std::runtime_error("data datype of dictionary encoded array must be an integer");
74 }
75 }
76 else
77 {
78 switch (ar.data_type())
79 {
80 case data_type::NA:
81 return func(unwrap_array<null_array>(ar));
82 case data_type::BOOL:
83 return func(unwrap_array<primitive_array<bool>>(ar));
86 case data_type::INT8:
102 case data_type::FLOAT:
107 return func(unwrap_array<string_array>(ar));
109 return func(unwrap_array<string_view_array>(ar));
111 return func(unwrap_array<big_string_array>(ar));
113 return func(unwrap_array<binary_array>(ar));
115 return func(unwrap_array<binary_view_array>(ar));
117 return func(unwrap_array<big_binary_array>(ar));
120 case data_type::LIST:
121 return func(unwrap_array<list_array>(ar));
123 return func(unwrap_array<big_list_array>(ar));
125 return func(unwrap_array<list_view_array>(ar));
127 return func(unwrap_array<big_list_view_array>(ar));
131 return func(unwrap_array<struct_array>(ar));
132 case data_type::MAP:
133 return func(unwrap_array<map_array>(ar));
135 return func(unwrap_array<dense_union_array>(ar));
137 return func(unwrap_array<sparse_union_array>(ar));
139 return func(unwrap_array<decimal_32_array>(ar));
141 return func(unwrap_array<decimal_64_array>(ar));
143 return func(unwrap_array<decimal_128_array>(ar));
145 return func(unwrap_array<decimal_256_array>(ar));
147 {
148 const std::optional<key_value_view> metadata = ar.get_arrow_proxy().metadata(); // ensure
149 // uuid_array
150 // is
151 // handled
152 // in
153 // uuid_array.cpp
154 if (metadata.has_value())
155 {
156 const auto it = metadata->find("ARROW:extension:name");
157 if (it != metadata->end())
158 {
159 return func(unwrap_array<uuid_array>(ar));
160 }
161 }
163 }
165 return func(unwrap_array<date_days_array>(ar));
169 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
170 {
172 }
173 else
174 {
176 }
178 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
179 {
181 }
182 else
183 {
185 }
187 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
188 {
190 }
191 else
192 {
194 }
196 if (get_timezone(ar.get_arrow_proxy()) == nullptr)
197 {
199 }
200 else
201 {
203 }
205 return func(unwrap_array<time_seconds_array>(ar));
226 default:
227 throw std::invalid_argument("array type not supported");
228 }
229 }
230 }
231}
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 std::optional< key_value_view > metadata() const
Gets the metadata key-value pairs.
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:47
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:50