sparrow 2.6.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
data_traits.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 implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <chrono>
18#include <concepts>
19#include <string>
20#include <string_view>
21#include <vector>
22
30
31namespace sparrow
32{
33
34 template <class T>
36 {
37 using value_type = T;
38 using const_reference = const T&;
39 };
40
41 template <>
47
48 // Define automatically all standard floating-point and integral types support, excluding `bool`.
49 template <class T>
50 requires std::integral<T> or std::floating_point<T>
52 {
53 };
54
55 template <>
57 {
58 };
59
60 template <>
61 struct arrow_traits<bool>
62 {
63 using value_type = bool;
64 using const_reference = bool;
65 };
66
67 template <>
68 struct arrow_traits<std::string>
69 {
70 using value_type = std::string;
71 using const_reference = std::string_view;
72 };
73
74 template <>
75 struct arrow_traits<std::vector<byte_t>>
76 {
77 using value_type = std::vector<byte_t>;
79 };
80
81 template <>
87
88 template <>
94
95 template <>
101
102 template <>
108
109 template <>
115
116 template <>
122
123 template <>
129
130 template <>
132 {
133 };
134
135 template <>
137 {
138 };
139
140 template <>
141 struct arrow_traits<std::chrono::seconds> : common_native_types_traits<std::chrono::seconds>
142 {
143 };
144
145 template <>
146 struct arrow_traits<std::chrono::milliseconds> : common_native_types_traits<std::chrono::milliseconds>
147 {
148 };
149
150 template <>
151 struct arrow_traits<std::chrono::microseconds> : common_native_types_traits<std::chrono::microseconds>
152 {
153 };
154
155 template <>
156 struct arrow_traits<std::chrono::nanoseconds> : common_native_types_traits<std::chrono::nanoseconds>
157 {
158 };
159
160 template <>
166
167 template <>
173
174 template <>
180
181 template <>
187
188 template <>
190 : common_native_types_traits<zoned_time_without_timezone_seconds>
191 {
192 };
193
194 template <>
196 : common_native_types_traits<zoned_time_without_timezone_milliseconds>
197 {
198 };
199
200 template <>
202 : common_native_types_traits<zoned_time_without_timezone_microseconds>
203 {
204 };
205
206 template <>
208 : common_native_types_traits<zoned_time_without_timezone_nanoseconds>
209 {
210 };
211
212 template <>
213 struct arrow_traits<chrono::time_seconds> : common_native_types_traits<chrono::time_seconds>
214 {
215 };
216
217 template <>
218 struct arrow_traits<chrono::time_milliseconds> : common_native_types_traits<chrono::time_milliseconds>
219 {
220 };
221
222 template <>
223 struct arrow_traits<chrono::time_microseconds> : common_native_types_traits<chrono::time_microseconds>
224 {
225 };
226
227 template <>
228 struct arrow_traits<chrono::time_nanoseconds> : common_native_types_traits<chrono::time_nanoseconds>
229 {
230 };
231
232 template <>
233 struct arrow_traits<chrono::months> : common_native_types_traits<chrono::months>
234 {
235 };
236
237 template <>
239 {
240 };
241
242 template <>
244 : common_native_types_traits<month_day_nanoseconds_interval>
245 {
246 };
247
248 namespace impl
249 {
250 // Owning counterparts of the views a layout exposes by reference, mirroring the
251 // value_type/const_reference pairs of the arrow_traits above.
252 template <>
253 struct materialized<std::string_view>
254 {
255 using type = std::string;
256 };
257
258 template <class T, std::size_t Extent>
259 struct materialized<sequence_view<T, Extent>>
260 {
261 using type = std::vector<std::remove_const_t<T>>;
262 };
263 }
264
265 namespace detail
266 {
267 template <class T>
269
270 template <class T>
272
273 template <class T>
275
276 template <class T>
278 }
279
281 {
282 using inner_value_type = /* std::variant<null_type, bool, uint8_t, ...> */
284 // std::variant can not hold references, we need to write something based on variant and
285 // reference_wrapper
286 // using inner_const_reference = /* std::variant<null_type, const bool&, const suint8_t&, ....> */
287 /* mpl::rename<
288 mpl::transform<
289 detail::array_inner_const_reference_t,
290 all_base_types_t>,
291 std::variant>;*/
292 using value_type = // nullable_variant<nullable<null_type>, nullable<bool>, nullable<uint8_t>, ...>
294 using const_reference = // nullable_variant<nullable<null_type>, nullable<const bool&>,
295 // nullable<const uint8_t&>, ...>
297 };
298
299 namespace predicate
300 {
301
302 struct
303 {
304 template <class T>
305 consteval bool operator()(mpl::typelist<T>)
306 {
308 }
310
311 struct
312 {
313 template <class T>
314 consteval bool operator()(mpl::typelist<T>)
315 {
317 }
318 } constexpr has_arrow_traits;
319 }
320}
Variant of nullable types with has_value() convenience method.
The class sequence_view describes an object that can refer to a constant contiguous sequence of T wit...
Matches C++ representation types which are supported by default.
Matches valid and complete arrow_traits specializations for type T.
nullable< array_inner_value_type_t< T > > array_value_type_t
typename arrow_traits< T >::value_type array_inner_value_type_t
typename arrow_traits< T >::const_reference array_inner_const_reference_t
nullable< array_inner_const_reference_t< T > > array_const_reference_t
typename impl::rename_impl< From, To >::type rename
Changes the template type of a type list.
Definition mp_utils.hpp:268
struct sparrow::predicate::@133355332276125161102302222157102151155345254340 has_arrow_traits
primesum::int128_t int128_t
Definition large_int.hpp:84
half_float::half float16_t
date::zoned_time< Duration, TimeZonePtr > timestamp
primesum::int256_t int256_t
Definition large_int.hpp:85
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > date_milliseconds
std::chrono::time_point< std::chrono::system_clock, chrono::days > date_days
Extensions to the C++ standard library.
mpl::rename< mpl::unique< mpl::transform< detail::array_const_reference_t, all_base_types_t > >, nullable_variant > const_reference
mpl::rename< mpl::transform< detail::array_value_type_t, all_base_types_t >, nullable_variant > value_type
mpl::rename< all_base_types_t, std::variant > inner_value_type
sequence_view< const byte_t > const_reference
Provides compile-time information about Arrow data types.
std::vector< std::remove_const_t< T > > type
Owning counterpart of the type stored by a nullable.
Definition nullable.hpp:267
A sequence of types used for metaprogramming operations.
Definition mp_utils.hpp:123
A zoned time value without timezone, in microseconds.
A zoned time value without timezone, in milliseconds.
A zoned time value without timezone, in nanoseconds.
A zoned time value without timezone, in seconds.