sparrow 0.3.0
Loading...
Searching...
No Matches
run_end_encoded_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 implied.
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"
23
24namespace sparrow
25{
27
31 template <class T>
32 constexpr bool is_run_end_encoded_array_v = std::same_as<T, run_end_encoded_array>;
33
34 namespace detail
35 {
36 template <class T>
37 struct get_data_type_from_array;
38
39 template <>
41 {
42 [[nodiscard]] static constexpr sparrow::data_type get()
43 {
45 }
46 };
47 }
48
50 {
51 public:
52
54 using size_type = std::size_t;
58
60
61 template <class... Args>
63 explicit run_end_encoded_array(Args&&... args)
64 : run_end_encoded_array(create_proxy(std::forward<Args>(args)...))
65 {
66 }
67
70
73
75 [[nodiscard]] SPARROW_API array_traits::const_reference operator[](std::uint64_t i) const;
76
77 [[nodiscard]] SPARROW_API iterator begin();
78 [[nodiscard]] SPARROW_API iterator end();
79
80 [[nodiscard]] SPARROW_API const_iterator begin() const;
81 [[nodiscard]] SPARROW_API const_iterator end() const;
82
83 [[nodiscard]] SPARROW_API const_iterator cbegin() const;
84 [[nodiscard]] SPARROW_API const_iterator cend() const;
85
88
89 [[nodiscard]] SPARROW_API bool empty() const;
90 [[nodiscard]] SPARROW_API size_type size() const;
91
92 [[nodiscard]] std::optional<std::string_view> name() const;
93 [[nodiscard]] std::optional<std::string_view> metadata() const;
94
95 private:
96
97 [[nodiscard]] SPARROW_API static auto create_proxy(
98 array&& acc_lengths,
99 array&& encoded_values,
100 std::optional<std::string_view> name = std::nullopt,
101 std::optional<std::string_view> metadata = std::nullopt
102 ) -> arrow_proxy;
103
104 using acc_length_ptr_variant_type = std::variant<const std::uint16_t*, const std::uint32_t*, const std::uint64_t*>;
105
106 [[nodiscard]] SPARROW_API static std::pair<std::int64_t, std::int64_t>
107 extract_length_and_null_count(const array&, const array&);
108 [[nodiscard]] SPARROW_API static acc_length_ptr_variant_type
109 get_acc_lengths_ptr(const array_wrapper& ar);
110 [[nodiscard]] SPARROW_API std::uint64_t get_run_length(std::uint64_t run_index) const;
111
112 [[nodiscard]] SPARROW_API arrow_proxy& get_arrow_proxy();
113 [[nodiscard]] SPARROW_API const arrow_proxy& get_arrow_proxy() const;
114
115 arrow_proxy m_proxy;
116 std::uint64_t m_encoded_length;
117
118 cloning_ptr<array_wrapper> p_acc_lengths_array;
119 cloning_ptr<array_wrapper> p_encoded_values_array;
120 acc_length_ptr_variant_type m_acc_lengths;
121
122 // friend classes
123 friend class run_encoded_array_iterator<false>;
124 friend class run_encoded_array_iterator<true>;
126 };
127
130} // namespace sparrow
131
132#if defined(__cpp_lib_format)
133
134template <>
135struct std::formatter<sparrow::run_end_encoded_array>
136{
137 constexpr auto parse(std::format_parse_context& ctx)
138 {
139 return ctx.begin(); // Simple implementation
140 }
141
142 SPARROW_API auto format(const sparrow::run_end_encoded_array& ar, std::format_context& ctx) const
143 -> decltype(ctx.out());
144};
145
146namespace sparrow
147{
148 SPARROW_API std::ostream& operator<<(std::ostream& os, const sparrow::run_end_encoded_array& value);
149}
150
151#endif
Base class for array type erasure.
Dynamically typed array encapsulating an Arrow layout.
Definition array_api.hpp:39
Proxy class over ArrowArray and ArrowSchema.
Smart pointer behaving like a copiable std::unique_ptr.
Definition memory.hpp:127
SPARROW_API const_iterator end() const
SPARROW_API array_traits::const_reference operator[](std::uint64_t i)
run_encoded_array_iterator< true > const_iterator
array_traits::inner_value_type inner_value_type
SPARROW_API size_type size() const
SPARROW_API array_traits::const_reference back() const
SPARROW_API bool empty() const
SPARROW_API iterator end()
SPARROW_API iterator begin()
SPARROW_API const_iterator begin() const
self_type & operator=(self_type &&)=default
SPARROW_API array_traits::const_reference operator[](std::uint64_t i) const
SPARROW_API run_end_encoded_array(const self_type &)
run_end_encoded_array(self_type &&)=default
std::optional< std::string_view > metadata() const
SPARROW_API run_end_encoded_array(arrow_proxy proxy)
std::optional< std::string_view > name() const
SPARROW_API array_traits::const_reference front() const
SPARROW_API const_iterator cend() const
SPARROW_API self_type & operator=(const self_type &)
SPARROW_API const_iterator cbegin() const
run_encoded_array_iterator< false > iterator
#define SPARROW_API
Definition config.hpp:38
constexpr bool excludes_copy_and_move_ctor_v
Definition mp_utils.hpp:507
SPARROW_API bool operator==(const array &lhs, const array &rhs)
Compares the content of two arrays.
constexpr bool is_run_end_encoded_array_v
Checks whether T is a run_end_encoded_array type.
std::ostream & operator<<(std::ostream &stream, T n)
Definition large_int.hpp:93
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
mpl::rename< mpl::transform< detail::array_const_reference_t, all_base_types_t >, nullable_variant > const_reference
mpl::rename< all_base_types_t, std::variant > inner_value_type