sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
private_data.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 <memory>
18
#include <queue>
19
#include <ranges>
20
#include <string>
21
22
#include <
sparrow/arrow_interface/arrow_array.hpp
>
23
#include <
sparrow/arrow_interface/arrow_schema.hpp
>
24
#include <
sparrow/c_interface.hpp
>
25
26
namespace
sparrow
27
{
28
class
arrow_array_stream_private_data
29
{
30
public
:
31
32
arrow_array_stream_private_data
() =
default
;
33
34
void
import_schema
(
schema_unique_ptr
&& out_schema)
35
{
36
m_schema = std::move(out_schema);
37
}
38
39
[[nodiscard]]
ArrowSchema
*
schema
()
40
{
41
return
m_schema.get();
42
}
43
44
[[nodiscard]]
const
ArrowSchema
*
schema
()
const
45
{
46
return
m_schema.get();
47
}
48
49
template
<std::ranges::input_range R>
50
requires
std::same_as<std::ranges::range_value_t<R>,
ArrowArray
*>
51
void
import_arrays
(R&& arrays)
52
{
53
for
(
auto
&&
array
: arrays)
54
{
55
m_arrays.push(array_ptr(
array
));
56
}
57
}
58
59
void
import_array
(
array_unique_ptr
&&
array
)
60
{
61
m_arrays.push(std::move(
array
));
62
}
63
64
[[nodiscard]]
ArrowArray
*
export_next_array
()
65
{
66
if
(m_arrays.empty())
67
{
68
return
new
ArrowArray
{};
69
}
70
71
ArrowArray
*
array
= m_arrays.
front
().release();
72
m_arrays.pop();
73
return
array
;
74
}
75
76
[[nodiscard]]
const
std::string&
get_last_error_message
()
const
77
{
78
return
m_last_error_message;
79
}
80
81
void
set_last_error_message
(std::string_view message)
82
{
83
m_last_error_message = message;
84
}
85
86
private
:
87
88
schema_unique_ptr
m_schema;
89
std::queue<array_unique_ptr> m_arrays{};
90
std::string m_last_error_message{};
91
};
92
}
arrow_array.hpp
arrow_schema.hpp
c_interface.hpp
sparrow::array
Dynamically typed array encapsulating an Arrow layout.
Definition
array_api.hpp:50
sparrow::array::front
SPARROW_API const_reference front() const
Returns a constant reference to the first element in the container.
sparrow::arrow_array_stream_private_data::schema
ArrowSchema * schema()
Definition
private_data.hpp:39
sparrow::arrow_array_stream_private_data::import_schema
void import_schema(schema_unique_ptr &&out_schema)
Definition
private_data.hpp:34
sparrow::arrow_array_stream_private_data::schema
const ArrowSchema * schema() const
Definition
private_data.hpp:44
sparrow::arrow_array_stream_private_data::get_last_error_message
const std::string & get_last_error_message() const
Definition
private_data.hpp:76
sparrow::arrow_array_stream_private_data::import_arrays
void import_arrays(R &&arrays)
Definition
private_data.hpp:51
sparrow::arrow_array_stream_private_data::arrow_array_stream_private_data
arrow_array_stream_private_data()=default
sparrow::arrow_array_stream_private_data::import_array
void import_array(array_unique_ptr &&array)
Definition
private_data.hpp:59
sparrow::arrow_array_stream_private_data::export_next_array
ArrowArray * export_next_array()
Definition
private_data.hpp:64
sparrow::arrow_array_stream_private_data::set_last_error_message
void set_last_error_message(std::string_view message)
Definition
private_data.hpp:81
sparrow
Definition
array.hpp:21
sparrow::schema_unique_ptr
std::unique_ptr< ArrowSchema, arrow_schema_deleter > schema_unique_ptr
Definition
arrow_schema.hpp:263
sparrow::array_unique_ptr
std::unique_ptr< ArrowArray, arrow_array_deleter > array_unique_ptr
Definition
arrow_array.hpp:239
ArrowArray
Definition
c_interface.hpp:43
ArrowSchema
Definition
c_interface.hpp:26
sparrow
arrow_interface
arrow_array_stream
private_data.hpp
Generated by
1.17.0