Project
Loading...
Searching...
No Matches
ArrowTypes.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FRAMEWORK_ARROWTYPES_H
13#define O2_FRAMEWORK_ARROWTYPES_H
14#include "Framework/Traits.h"
15#include "arrow/type_fwd.h"
16#include <span>
17
18namespace o2::soa
19{
20template <typename T>
22};
23template <>
24struct arrow_array_for<bool> {
25 using type = arrow::BooleanArray;
26};
27template <>
28struct arrow_array_for<int8_t> {
29 using type = arrow::Int8Array;
30};
31template <>
32struct arrow_array_for<uint8_t> {
33 using type = arrow::UInt8Array;
34};
35template <>
36struct arrow_array_for<int16_t> {
37 using type = arrow::Int16Array;
38};
39template <>
40struct arrow_array_for<uint16_t> {
41 using type = arrow::UInt16Array;
42};
43template <>
44struct arrow_array_for<int32_t> {
45 using type = arrow::Int32Array;
46};
47template <>
48struct arrow_array_for<int64_t> {
49 using type = arrow::Int64Array;
50};
51template <>
52struct arrow_array_for<uint32_t> {
53 using type = arrow::UInt32Array;
54};
55template <>
56struct arrow_array_for<uint64_t> {
57 using type = arrow::UInt64Array;
58};
59template <>
60struct arrow_array_for<float> {
61 using type = arrow::FloatArray;
62};
63template <>
64struct arrow_array_for<double> {
65 using type = arrow::DoubleArray;
66};
67template <>
68struct arrow_array_for<std::span<std::byte>> {
69 using type = arrow::BinaryViewArray;
70};
71template <int N>
72struct arrow_array_for<float[N]> {
73 using type = arrow::FixedSizeListArray;
74 using value_type = float;
75};
76template <int N>
77struct arrow_array_for<int[N]> {
78 using type = arrow::FixedSizeListArray;
79 using value_type = int;
80};
81template <int N>
82struct arrow_array_for<short[N]> {
83 using type = arrow::FixedSizeListArray;
84 using value_type = short;
85};
86template <int N>
87struct arrow_array_for<double[N]> {
88 using type = arrow::FixedSizeListArray;
89 using value_type = double;
90};
91template <int N>
92struct arrow_array_for<int8_t[N]> {
93 using type = arrow::FixedSizeListArray;
94 using value_type = int8_t;
95};
96
97#define ARROW_VECTOR_FOR(_type_) \
98 template <> \
99 struct arrow_array_for<std::vector<_type_>> { \
100 using type = arrow::ListArray; \
101 using value_type = _type_; \
102 };
103
108
113
116
117template <typename T>
119template <typename T>
121
122template <class Array>
123using array_element_t = std::decay_t<decltype(std::declval<Array>()[0])>;
124
125template <typename T>
126std::shared_ptr<arrow::DataType> asArrowDataType(int list_size = 1)
127{
128 auto typeGenerator = [](std::shared_ptr<arrow::DataType> const& type, int list_size) -> std::shared_ptr<arrow::DataType> {
129 switch (list_size) {
130 case -1:
131 return arrow::list(type);
132 case 1:
133 return std::move(type);
134 default:
135 return arrow::fixed_size_list(type, list_size);
136 }
137 };
138
139 if constexpr (std::is_arithmetic_v<T>) {
140 if constexpr (std::same_as<T, bool>) {
141 return typeGenerator(arrow::boolean(), list_size);
142 } else if constexpr (std::same_as<T, uint8_t>) {
143 return typeGenerator(arrow::uint8(), list_size);
144 } else if constexpr (std::same_as<T, uint16_t>) {
145 return typeGenerator(arrow::uint16(), list_size);
146 } else if constexpr (std::same_as<T, uint32_t>) {
147 return typeGenerator(arrow::uint32(), list_size);
148 } else if constexpr (std::same_as<T, uint64_t>) {
149 return typeGenerator(arrow::uint64(), list_size);
150 } else if constexpr (std::same_as<T, int8_t>) {
151 return typeGenerator(arrow::int8(), list_size);
152 } else if constexpr (std::same_as<T, int16_t>) {
153 return typeGenerator(arrow::int16(), list_size);
154 } else if constexpr (std::same_as<T, int32_t>) {
155 return typeGenerator(arrow::int32(), list_size);
156 } else if constexpr (std::same_as<T, int64_t>) {
157 return typeGenerator(arrow::int64(), list_size);
158 } else if constexpr (std::same_as<T, float>) {
159 return typeGenerator(arrow::float32(), list_size);
160 } else if constexpr (std::same_as<T, double>) {
161 return typeGenerator(arrow::float64(), list_size);
162 }
163 } else if constexpr (std::is_bounded_array_v<T>) {
164 return asArrowDataType<array_element_t<T>>(std::extent_v<T>);
165 } else if constexpr (o2::framework::is_specialization_v<T, std::vector>) {
166 return asArrowDataType<typename T::value_type>(-1);
167 }
168 return nullptr;
169}
170} // namespace o2::soa
171#endif // O2_FRAMEWORK_ARROWTYPES_H
#define ARROW_VECTOR_FOR(_type_)
Definition ArrowTypes.h:97
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
std::decay_t< decltype(std::declval< Array >()[0])> array_element_t
Definition ArrowTypes.h:123
std::shared_ptr< arrow::DataType > asArrowDataType(int list_size=1)
Definition ArrowTypes.h:126
typename arrow_array_for< T >::value_type value_for_t
Definition ArrowTypes.h:120
typename arrow_array_for< T >::type arrow_array_for_t
Definition ArrowTypes.h:118
Defining DataPointCompositeObject explicitly as copiable.
arrow::FixedSizeListArray type
Definition ArrowTypes.h:88
arrow::FixedSizeListArray type
Definition ArrowTypes.h:73
arrow::FixedSizeListArray type
Definition ArrowTypes.h:93
arrow::FixedSizeListArray type
Definition ArrowTypes.h:78
arrow::FixedSizeListArray type
Definition ArrowTypes.h:83