sparrow 1.2.0
Loading...
Searching...
No Matches
array.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 "sparrow/array_api.hpp"
19
20namespace sparrow
21{
22 template <layout A>
23 requires(not std::is_lvalue_reference_v<A>)
24 constexpr array::array(A&& a)
25 : p_array(new array_wrapper_impl<A>(std::forward<A>(a)))
26 {
27 }
28
29 template <layout A>
30 constexpr array::array(A* a)
31 : p_array(new array_wrapper_impl<A>(a))
32 {
33 }
34
35 template <layout A>
36 constexpr array::array(std::shared_ptr<A> a)
37 : p_array(new array_wrapper_impl<A>(a))
38 {
39 }
40
41 template <class F>
42 constexpr array::visit_result_t<F> array::visit(F&& func) const
43 {
44 return sparrow::visit(std::forward<F>(func), *p_array);
45 }
46
47 template <layout_or_array A>
48 bool owns_arrow_array(const A& a)
49 {
51 }
52
53 template <layout_or_array A>
54 bool owns_arrow_schema(const A& a)
55 {
57 }
58
59 template <layout_or_array A>
64
65 template <layout_or_array A>
66 const ArrowArray* get_arrow_array(const A& a)
67 {
69 }
70
71 template <layout_or_array A>
76
77 template <layout_or_array A>
78 const ArrowSchema* get_arrow_schema(const A& a)
79 {
81 }
82
83 template <layout_or_array A>
84 std::pair<ArrowArray*, ArrowSchema*> get_arrow_structures(A& a)
85 {
87 return std::make_pair(&(proxy.array()), &(proxy.schema()));
88 }
89
90 template <layout_or_array A>
91 std::pair<const ArrowArray*, const ArrowSchema*> get_arrow_structures(const A& a)
92 {
94 return std::make_pair(&(proxy.array()), &(proxy.schema()));
95 }
96
97 template <layout_or_array A>
102
103 template <layout_or_array A>
108
109 template <layout_or_array A>
110 std::pair<ArrowArray, ArrowSchema> extract_arrow_structures(A&& a)
111 {
113 return std::make_pair(proxy.extract_array(), proxy.extract_schema());
114 }
115}
116
117#if defined(__cpp_lib_format)
118
119template <>
120struct std::formatter<sparrow::array>
121{
122 constexpr auto parse(std::format_parse_context& ctx)
123 {
124 return ctx.begin(); // Simple implementation
125 }
126
127 using iterator = std::format_context::iterator;
128
130 iterator format(const sparrow::array& ar, std::format_context& ctx) const;
131};
132
133namespace sparrow
134{
135 inline std::ostream& operator<<(std::ostream& os, const array& value)
136 {
137 os << std::format("{}", value);
138 return os;
139 }
140}
141
142#endif
Dynamically typed array encapsulating an Arrow layout.
Definition array_api.hpp:43
std::invoke_result_t< F, null_array > visit_result_t
constexpr visit_result_t< F > visit(F &&func) const
Returns the result of calling the given functor func on the layout internally held by the array.
Definition array.hpp:42
array()=default
Constructs an empty array.
SPARROW_API ArrowArray extract_array()
Extract the ArrowArray from the proxy, and transfers the responsibility to release it after usage to ...
SPARROW_API ArrowSchema & schema()
Get a reference to the ArrowSchema of the proxy.
SPARROW_API bool owns_schema() const
Check whether the proxy has ownership of its internal the ArrowSchema.
SPARROW_API ArrowArray & array()
Get a reference to the ArrowArray of the proxy.
SPARROW_API bool owns_array() const
Check whether the proxy has ownership of its internal the ArrowArray.
SPARROW_API ArrowSchema extract_schema()
Extract the ArrowSchema from the proxy, and transfers the responsibility to release it after usage to...
static const sparrow::arrow_proxy & get_arrow_proxy(const ARRAY &array)
#define SPARROW_API
Definition config.hpp:38
ArrowArray extract_arrow_array(A &&a)
Extracts the internal ArrowArray structure from the given Array or typed layout.
Definition array.hpp:98
std::pair< ArrowArray, ArrowSchema > extract_arrow_structures(A &&a)
Extracts the internal ArrowArray and ArrowSchema structures from the given array or typed layout.
Definition array.hpp:110
std::ostream & operator<<(std::ostream &os, const nullval_t &)
ArrowSchema extract_arrow_schema(A &&a)
Extracts the internal ArrowSchema structure from the given array or typed layout.
Definition array.hpp:104
ArrowSchema * get_arrow_schema(A &a)
Returns a pointer to the internal ArrowSchema of the given array or layout.
Definition array.hpp:72
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:49
bool owns_arrow_schema(const A &a)
Returns true if the given layout or array has ownership of its internal ArrowSchema.
Definition array.hpp:54
bool owns_arrow_array(const A &a)
Returns true if the given layout or array has ownership of its internal ArrowArray.
Definition array.hpp:48
std::pair< ArrowArray *, ArrowSchema * > get_arrow_structures(A &a)
Returns pointers to the internal ArrowArray and ArrowSchema of the given Array or layout.
Definition array.hpp:84
ArrowArray * get_arrow_array(A &a)
Returns a pointer to the internal ArrowArray of the given array or layout.
Definition array.hpp:60