sparrow 1.3.0
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
19
20namespace sparrow
21{
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>
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}
void set_metadata(std::optional< R > metadata)
Sets the metadata key-value pairs.
SPARROW_API std::optional< key_value_view > metadata() const
Gets the metadata key-value pairs.
static void init(arrow_proxy &)
Definition extension.hpp:26
static constexpr std::string_view EXTENSION_NAME
Definition extension.hpp:37
static void init(arrow_proxy &proxy)
Definition extension.hpp:41