sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
extension.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/arrow_interface/arrow_array_schema_proxy.hpp
"
18
#include "
sparrow/utils/fixed_string.hpp
"
19
20
namespace
sparrow
21
{
22
class
empty_extension
23
{
24
protected
:
25
26
static
void
init
(
arrow_proxy
&)
27
{
28
// No-op for empty extension
29
}
30
};
31
32
template
<fixed_
string
extension_name>
33
class
simple_extension
34
{
35
public
:
36
37
static
constexpr
std::string_view
EXTENSION_NAME
= extension_name;
38
39
protected
:
40
41
static
void
init
(
arrow_proxy
& proxy)
42
{
43
// Add JSON extension metadata
44
std::optional<key_value_view> metadata = proxy.
metadata
();
45
std::vector<metadata_pair> extension_metadata = metadata.has_value()
46
? std::vector<metadata_pair>(
47
metadata->begin(),
48
metadata->end()
49
)
50
: std::vector<metadata_pair>{};
51
52
// Check if extension metadata already exists
53
const
bool
has_extension_name = std::ranges::find_if(
54
extension_metadata,
55
[](
const
auto
& pair)
56
{
57
return
pair.first ==
"ARROW:extension:name"
58
&& pair.second ==
EXTENSION_NAME
;
59
}
60
)
61
!= extension_metadata.end();
62
if
(!has_extension_name)
63
{
64
extension_metadata.emplace_back(
"ARROW:extension:name"
,
EXTENSION_NAME
);
65
extension_metadata.emplace_back(
"ARROW:extension:metadata"
,
""
);
66
}
67
proxy.
set_metadata
(std::make_optional(extension_metadata));
68
}
69
};
70
71
}
arrow_array_schema_proxy.hpp
sparrow::arrow_proxy
Definition
arrow_array_schema_proxy.hpp:111
sparrow::arrow_proxy::set_metadata
void set_metadata(std::optional< R > metadata)
Sets the metadata key-value pairs.
Definition
arrow_array_schema_proxy.hpp:347
sparrow::arrow_proxy::metadata
SPARROW_API std::optional< key_value_view > metadata() const
Gets the metadata key-value pairs.
sparrow::empty_extension
Definition
extension.hpp:23
sparrow::empty_extension::init
static void init(arrow_proxy &)
Definition
extension.hpp:26
sparrow::simple_extension
Definition
extension.hpp:34
sparrow::simple_extension::EXTENSION_NAME
static constexpr std::string_view EXTENSION_NAME
Definition
extension.hpp:37
sparrow::simple_extension::init
static void init(arrow_proxy &proxy)
Definition
extension.hpp:41
fixed_string.hpp
sparrow
Definition
array.hpp:21
sparrow
utils
extension.hpp
Generated by
1.17.0