iceberg-cpp
Loading...
Searching...
No Matches
position_delete_index.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 <cstdint>
26#include <memory>
27#include <span>
28#include <vector>
29
32#include "iceberg/result.h"
33#include "iceberg/type_fwd.h"
34
35namespace iceberg {
36
42class ICEBERG_EXPORT PositionDeleteIndex {
43 public:
44 PositionDeleteIndex() = default;
45 explicit PositionDeleteIndex(std::shared_ptr<DataFile> delete_file);
46 explicit PositionDeleteIndex(std::vector<std::shared_ptr<DataFile>> delete_files);
47 ~PositionDeleteIndex() = default;
48
51 void Delete(int64_t pos);
52
56 void Delete(int64_t pos_start, int64_t pos_end);
57
61 bool IsDeleted(int64_t pos) const;
62
64 bool IsEmpty() const;
65
67 int64_t Cardinality() const;
68
71 void Merge(const PositionDeleteIndex& other);
72
78 const std::vector<std::shared_ptr<DataFile>>& delete_files() const {
79 return delete_files_;
80 }
81
87
94 static Result<PositionDeleteIndex> Deserialize(std::span<const uint8_t> blob,
95 std::shared_ptr<DataFile> delete_file);
96
97 private:
99
100 // Bulk-add positions sharing high-32-bit `key`. Private hook for
101 // `ForEachPositionDelete`'s bulk path; keeps `Delete` the sole public
102 // mutation surface.
103 void BulkAddForKey(int32_t key, std::span<const uint32_t> positions);
104
105 friend void ICEBERG_EXPORT ForEachPositionDelete(std::span<const int64_t> positions,
106 PositionDeleteIndex& target,
107 std::vector<uint32_t>& scratch);
108
109 RoaringPositionBitmap bitmap_;
110 std::vector<std::shared_ptr<DataFile>> delete_files_;
111};
112
113} // namespace iceberg
Tracks deleted row positions using a bitmap.
Definition position_delete_index.h:42
friend void ICEBERG_EXPORT ForEachPositionDelete(std::span< const int64_t > positions, PositionDeleteIndex &target, std::vector< uint32_t > &scratch)
Apply positions to target as deletes; semantically equivalent to calling target.Delete(pos) for each ...
void Delete(int64_t pos)
Mark a position as deleted.
void Merge(const PositionDeleteIndex &other)
Merge another index into this one.
void Delete(int64_t pos_start, int64_t pos_end)
Mark a range of positions as deleted [pos_start, pos_end).
bool IsDeleted(int64_t pos) const
Check if a position is deleted.
bool IsEmpty() const
Check if the index is empty (no positions deleted).
static Result< PositionDeleteIndex > Deserialize(std::span< const uint8_t > blob, std::shared_ptr< DataFile > delete_file)
Deserialize a deletion-vector-v1 blob into an index.
int64_t Cardinality() const
Get the number of deleted positions.
Result< std::vector< uint8_t > > Serialize()
Serialize the index into a deletion-vector-v1 blob.
const std::vector< std::shared_ptr< DataFile > > & delete_files() const
The delete files whose positions were merged into this index.
Definition position_delete_index.h:78
A bitmap that supports positive 64-bit positions, optimized for cases where most positions fit in 32 ...
Definition roaring_position_bitmap.h:52
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
Define Result, Status, and error helpers.