sparrow 0.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
38
39namespace sparrow
40{
41 template <class F>
42 using visit_result_t = std::invoke_result_t<F, null_array>;
43
44 template <class F>
45 [[nodiscard]] visit_result_t<F> visit(F&& func, const array_wrapper& ar)
46 {
47 if (ar.is_dictionary())
48 {
49 switch (ar.data_type())
50 {
53 case data_type::INT8:
67 default:
68 throw std::runtime_error("data datype of dictionary encoded array must be an integer");
69 }
70 }
71 else
72 {
73 switch (ar.data_type())
74 {
75 case data_type::NA:
76 return func(unwrap_array<null_array>(ar));
77 case data_type::BOOL:
78 return func(unwrap_array<primitive_array<bool>>(ar));
81 case data_type::INT8:
102 return func(unwrap_array<string_array>(ar));
104 return func(unwrap_array<big_string_array>(ar));
106 return func(unwrap_array<binary_array>(ar));
108 return func(unwrap_array<big_binary_array>(ar));
111 case data_type::LIST:
112 return func(unwrap_array<list_array>(ar));
114 return func(unwrap_array<big_list_array>(ar));
116 return func(unwrap_array<list_view_array>(ar));
118 return func(unwrap_array<big_list_view_array>(ar));
122 return func(unwrap_array<struct_array>(ar));
124 return func(unwrap_array<dense_union_array>(ar));
126 return func(unwrap_array<sparse_union_array>(ar));
128 return func(unwrap_array<decimal_32_array>(ar));
130 return func(unwrap_array<decimal_64_array>(ar));
132 return func(unwrap_array<decimal_128_array>(ar));
134 return func(unwrap_array<decimal_256_array>(ar));
138 return func(unwrap_array<date_days_array>(ar));
150 return func(unwrap_array<time_seconds_array>(ar));
171 default:
172 throw std::invalid_argument("array type not supported");
173 }
174 }
175 }
176}
Base class for array type erasure.
enum data_type data_type() const
date::zoned_time< Duration, TimeZonePtr > timestamp
T & unwrap_array(array_wrapper &)
std::invoke_result_t< F, null_array > visit_result_t
Definition dispatch.hpp:42
array_trivial_copyable< T > primitive_array
Array of values of whose type has fixed binary size.
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:45