sparrow 0.9.0
Loading...
Searching...
No Matches
c_interface.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 <concepts>
18#include <cstdint>
19
20#ifndef ARROW_C_DATA_INTERFACE
21# define ARROW_C_DATA_INTERFACE
22
23extern "C"
24{
26 {
27 // Array type description
28 const char* format;
29 const char* name;
30 const char* metadata;
31 int64_t flags;
32 int64_t n_children;
35
36 // Release callback
37 void (*release)(struct ArrowSchema*);
38 // Opaque producer-specific data
40 };
41
43 {
44 // Array data description
45 int64_t length;
46 int64_t null_count;
47 int64_t offset;
48 int64_t n_buffers;
49 int64_t n_children;
50 const void** buffers;
53
54 // Release callback
55 void (*release)(struct ArrowArray*);
56 // Opaque producer-specific data
58 };
59
60} // extern "C"
61
62#endif // ARROW_C_DATA_INTERFACE
63
64namespace sparrow
65{
66 enum class ArrowFlag : int64_t
67 {
68 DICTIONARY_ORDERED = 1, // For dictionary-encoded types, whether the ordering of dictionary indices
69 // is semantically meaningful.
70 NULLABLE = 2, // Whether this field is semantically nullable (regardless of whether it
71 // actually has null values).
72 MAP_KEYS_SORTED = 4 // For map types, whether the keys within each map value are sorted.
73 };
74
76 enum class ownership : bool
77 {
80
84 };
85
96
99 .schema = ownership::not_owning,
100 .array = ownership::not_owning,
101 };
102
104 inline constexpr auto owns_arrow_data = arrow_data_ownership{
105 .schema = ownership::owning,
106 .array = ownership::owning,
107 };
108
110 template <class T>
111 concept any_arrow_c_interface = std::same_as<std::remove_cvref_t<T>, ArrowArray>
112 or std::same_as<std::remove_cvref_t<T>, ArrowSchema>;
113
114
116 template <class T>
117 concept arrow_schema_or_ptr = std::same_as<T, ArrowSchema>
118 or std::same_as<std::remove_reference_t<T>, ArrowSchema*>;
119
121 template <class T>
122 concept arrow_array_or_ptr = std::same_as<T, ArrowArray>
123 or std::same_as<std::remove_reference_t<T>, ArrowArray*>;
124
125
126} // namespace sparrow
Matches only the C interface structs for Arrow.
Matches ArrowArray or a non-const pointer to an ArrowArray.
Matches ArrowSchema or a non-const pointer to an ArrowSchema.
constexpr auto owns_arrow_data
Useful shortcut value to specify full owning of handled Arrow data.
constexpr auto doesnt_own_arrow_data
Useful shortcut value to specify non-owning handled Arrow data.
ownership
Specifies the ownership model when passing Arrow data to another system.
@ owning
The system handling the related Arrow data owns that data and is responsible for releasing it through...
@ not_owning
The system handling the related Arrow data do not own that data, that system must not and will not re...
void(* release)(struct ArrowArray *)
void * private_data
int64_t n_children
int64_t null_count
struct ArrowArray ** children
int64_t offset
struct ArrowArray * dictionary
const void ** buffers
int64_t n_buffers
int64_t length
int64_t flags
const char * metadata
int64_t n_children
const char * name
void * private_data
const char * format
struct ArrowSchema * dictionary
void(* release)(struct ArrowSchema *)
struct ArrowSchema ** children
Specifies the ownership model when passing Arrow data to another system through ArrowArray and ArrowS...
ownership schema
< Specifies if the ownership of the schema data