iceberg-cpp
Loading...
Searching...
No Matches
struct_like_set.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <memory>
26#include <memory_resource>
27#include <unordered_set>
28#include <vector>
29
31#include "iceberg/result.h"
33#include "iceberg/type_fwd.h"
34
35namespace iceberg {
36
38ICEBERG_EXPORT Result<bool> StructLikeEqual(const StructLike& lhs, const StructLike& rhs);
39
50template <bool kValidate = true>
51class ICEBERG_TEMPLATE_CLASS_EXPORT StructLikeSet {
52 public:
53 static constexpr size_t kDefaultArenaInitialSize = 64 * 1024;
54
56 explicit StructLikeSet(const StructType& type,
57 size_t arena_initial_size = kDefaultArenaInitialSize);
58
60
62 Status Insert(const StructLike& row);
63
65 Result<bool> Contains(const StructLike& row) const;
66
68 bool IsEmpty() const;
69
71 size_t Size() const;
72
73 private:
75 struct KeyHash {
76 using is_transparent = void;
77 size_t operator()(const std::unique_ptr<StructLike>& p) const noexcept;
78 size_t operator()(const StructLike& s) const noexcept;
79 };
80
82 struct KeyEqual {
83 using is_transparent = void;
84 bool operator()(const std::unique_ptr<StructLike>& lhs,
85 const std::unique_ptr<StructLike>& rhs) const noexcept;
86 bool operator()(const StructLike& lhs,
87 const std::unique_ptr<StructLike>& rhs) const noexcept;
88 bool operator()(const std::unique_ptr<StructLike>& lhs,
89 const StructLike& rhs) const noexcept;
90 };
91
93 Result<std::unique_ptr<StructLike>> MakeArenaRow(const StructLike& row) const;
94
97 Result<Scalar> DeepCopyScalar(const Scalar& scalar) const;
98
100 std::string_view CopyToArena(std::string_view src) const;
101
102 std::vector<std::shared_ptr<Type>> field_types_;
103 mutable std::pmr::monotonic_buffer_resource arena_;
104 std::unordered_set<std::unique_ptr<StructLike>, KeyHash, KeyEqual> set_;
105};
106
107extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT StructLikeSet<true>;
108extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT StructLikeSet<false>;
109
110} // namespace iceberg
A set of StructLike rows with type-aware hashing and equality.
Definition struct_like_set.h:51
StructLikeSet(const StructType &type, size_t arena_initial_size=kDefaultArenaInitialSize)
Create a StructLikeSet for the given struct type.
size_t Size() const
Get the number of elements in the set.
bool IsEmpty() const
Check if the set is empty.
Result< bool > Contains(const StructLike &row) const
Check if the set contains a row.
Status Insert(const StructLike &row)
Insert a row into the set.
An immutable struct-like wrapper.
Definition struct_like.h:62
A data type representing a struct with nested fields.
Definition type.h:119
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
ICEBERG_EXPORT Result< bool > StructLikeEqual(const StructLike &lhs, const StructLike &rhs)
Compare two StructLike rows by scalar values.
Define Result, Status, and error helpers.