sparrow 0.3.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>)
25 : p_array(new array_wrapper_impl<A>(std::move(a)))
26 {
27 }
28
29 template <layout A>
31 : p_array(new array_wrapper_impl<A>(a))
32 {
33 }
34
35 template <layout A>
36 array::array(std::shared_ptr<A> a)
37 : p_array(new array_wrapper_impl<A>(a))
38 {
39 }
40
41 template <class F>
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>
70
71 template <layout_or_array A>
72 std::pair<ArrowArray*, ArrowSchema*> get_arrow_structures(A& a)
73 {
75 return std::make_pair(&(proxy.array()), &(proxy.schema()));
76 }
77
78 template <layout_or_array A>
83
84 template <layout_or_array A>
89
90 template <layout_or_array A>
91 std::pair<ArrowArray, ArrowSchema> extract_arrow_structures(A&& a)
92 {
94 return std::make_pair(proxy.extract_array(), proxy.extract_schema());
95 }
96}
97
98#if defined(__cpp_lib_format)
99
100template <>
101struct std::formatter<sparrow::array>
102{
103 constexpr auto parse(std::format_parse_context& ctx)
104 {
105 return ctx.begin(); // Simple implementation
106 }
107
108 auto format(const sparrow::array& ar, std::format_context& ctx) const
109 {
110 return ar.visit(
111 [&ctx](const auto& layout)
112 {
113 return std::format_to(ctx.out(), "{}", layout);
114 }
115 );
116 }
117};
118
119inline std::ostream& operator<<(std::ostream& os, const sparrow::array& value)
120{
121 os << std::format("{}", value);
122 return os;
123}
124
125#endif
Dynamically typed array encapsulating an Arrow layout.
Definition array_api.hpp:39
std::invoke_result_t< F, null_array > visit_result_t
array()=default
Constructs an empty array.
visit_result_t< F > visit(F &&func) const
Returns the result of calling the given functor func on the layout internally hold by the array.
Definition array.hpp:42
Proxy class over ArrowArray and ArrowSchema.
SPARROW_API ArrowArray extract_array()
SPARROW_API ArrowSchema & schema()
SPARROW_API bool owns_schema() const
SPARROW_API ArrowArray & array()
SPARROW_API bool owns_array() const
SPARROW_API ArrowSchema extract_schema()
static const sparrow::arrow_proxy & get_arrow_proxy(const ARRAY &array)
ArrowArray extract_arrow_array(A &&a)
Extracts the internal ArrowArray structure from the given Array or typed layout.
Definition array.hpp:79
std::pair< ArrowArray, ArrowSchema > extract_arrow_structures(A &&a)
Extracts the internal ArrowArrays and ArrowSchema structures from the given array or typed layout.
Definition array.hpp:91
std::ostream & operator<<(std::ostream &stream, T n)
Definition large_int.hpp:93
ArrowSchema extract_arrow_schema(A &&a)
Extracts the internal ArrowSchema structure from the given array or typed layout.
Definition array.hpp:85
ArrowSchema * get_arrow_schema(A &a)
Returns a pointer to the internal ArrowSchema of the given array or layout.
Definition array.hpp:66
visit_result_t< F > visit(F &&func, const array_wrapper &ar)
Definition dispatch.hpp:45
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:72
ArrowArray * get_arrow_array(A &a)
Returns a pointer to the internal ArrowArray of the given array or layout.
Definition array.hpp:60