sparrow 1.3.0
Loading...
Searching...
No Matches
uuid_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 <cstddef>
18#include <optional>
19#include <string_view>
20#include <vector>
21
24
25namespace sparrow
26{
43 {
44 public:
45
46 static constexpr size_t UUID_SIZE = 16;
47 static constexpr std::string_view EXTENSION_NAME = "arrow.uuid";
48
49 protected:
50
51 static void init(arrow_proxy& proxy)
52 {
53 const size_t element_size = num_bytes_for_fixed_sized_binary(proxy.format());
54 SPARROW_ASSERT_TRUE(element_size == UUID_SIZE);
55 // Add UUID extension metadata
56 std::optional<key_value_view> metadata = proxy.metadata();
57 std::vector<metadata_pair> extension_metadata = metadata.has_value()
58 ? std::vector<metadata_pair>(
59 metadata->begin(),
60 metadata->end()
61 )
62 : std::vector<metadata_pair>{};
63
64 // Check if extension metadata already exists
65 const bool has_extension_name = std::ranges::find_if(
66 extension_metadata,
67 [](const auto& pair)
68 {
69 return pair.first == "ARROW:extension:name"
70 && pair.second == EXTENSION_NAME;
71 }
72 )
73 != extension_metadata.end();
74 if (!has_extension_name)
75 {
76 extension_metadata.emplace_back("ARROW:extension:name", EXTENSION_NAME);
77 extension_metadata.emplace_back("ARROW:extension:metadata", "");
78 }
79 proxy.set_metadata(std::make_optional(extension_metadata));
80 }
81 };
82
84 fixed_width_binary_traits::value_type,
85 fixed_width_binary_traits::const_reference,
87
88 namespace detail
89 {
90 template <>
92 {
93 [[nodiscard]] static constexpr sparrow::data_type get()
94 {
96 }
97 };
98 }
99}
SPARROW_API const std::string_view format() const
Gets the Arrow format string describing the data type.
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.
#define SPARROW_ASSERT_TRUE(expr__)
SPARROW_API std::size_t num_bytes_for_fixed_sized_binary(std::string_view format)
Get the number of bytes for a fixed width binary layout from the ArrowArray format string.
fixed_width_binary_array_impl< fixed_width_binary_traits::value_type, fixed_width_binary_traits::const_reference, uuid_extension > uuid_array
data_type
Runtime identifier of arrow data types, usually associated with raw bytes with the associated value.
Metafunction for retrieving the data_type of a typed array.
UUID array implementation following Arrow canonical extension specification.
static void init(arrow_proxy &proxy)
static constexpr std::string_view EXTENSION_NAME
static constexpr size_t UUID_SIZE