sparrow 0.3.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 <algorithm>
18#include <array>
19#include <concepts>
20#include <cstdint>
21#include <stdexcept>
22#include <vector>
23
24#ifndef ARROW_C_DATA_INTERFACE
25# define ARROW_C_DATA_INTERFACE
26
27extern "C"
28{
30 {
31 // Array type description
32 const char* format;
33 const char* name;
34 const char* metadata;
35 int64_t flags;
36 int64_t n_children;
39
40 // Release callback
41 void (*release)(struct ArrowSchema*);
42 // Opaque producer-specific data
44 };
45
47 {
48 // Array data description
49 int64_t length;
50 int64_t null_count;
51 int64_t offset;
52 int64_t n_buffers;
53 int64_t n_children;
54 const void** buffers;
57
58 // Release callback
59 void (*release)(struct ArrowArray*);
60 // Opaque producer-specific data
62 };
63
64} // extern "C"
65
66#endif // ARROW_C_DATA_INTERFACE
67
68namespace sparrow
69{
70 enum class ArrowFlag : int64_t
71 {
72 DICTIONARY_ORDERED = 1, // For dictionary-encoded types, whether the ordering of dictionary indices
73 // is semantically meaningful.
74 NULLABLE = 2, // Whether this field is semantically nullable (regardless of whether it
75 // actually has null values).
76 MAP_KEYS_SORTED = 4 // For map types, whether the keys within each map value are sorted.
77 };
78
80 enum class ownership : bool
81 {
84
88 };
89
100
103 .schema = ownership::not_owning,
104 .array = ownership::not_owning,
105 };
106
108 inline constexpr auto owns_arrow_data = arrow_data_ownership{
109 .schema = ownership::owning,
110 .array = ownership::owning,
111 };
112
114 template <class T>
115 concept any_arrow_c_interface = std::same_as<std::remove_cvref_t<T>, ArrowArray>
116 or std::same_as<std::remove_cvref_t<T>, ArrowSchema>;
117
118
120 template <class T>
121 concept arrow_schema_or_ptr = std::same_as<T, ArrowSchema>
122 or std::same_as<std::remove_reference_t<T>, ArrowSchema*>;
123
125 template <class T>
126 concept arrow_array_or_ptr = std::same_as<T, ArrowArray>
127 or std::same_as<std::remove_reference_t<T>, ArrowArray*>;
128
129
130} // 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