Skip to content

Commit 7965dcd

Browse files
committed
feat: add position_deletes metadata table
1 parent 0ff15f6 commit 7965dcd

15 files changed

Lines changed: 1474 additions & 1 deletion

‎src/iceberg/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ set(ICEBERG_SOURCES
5555
geospatial.cc
5656
inspect/history_table.cc
5757
inspect/metadata_table.cc
58+
inspect/position_deletes_table.cc
5859
inspect/snapshots_table.cc
5960
inheritable_metadata.cc
6061
json_serde.cc

‎src/iceberg/arrow_c_data_util.cc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ Status AppendValue(const ArrowSchema& input_schema, const ArrowArray& input_arra
220220

221221
} // namespace
222222

223+
Status AppendArrayValue(const ArrowSchema& input_schema, const ArrowArray& input_array,
224+
const ArrowArrayView& input_view, int64_t row_index,
225+
ArrowArray* output_array) {
226+
return AppendValue(input_schema, input_array, input_view, row_index, output_array);
227+
}
228+
223229
ProjectionContext::ProjectionContext(ProjectionContext&& other) noexcept
224230
: input_schema_(std::exchange(other.input_schema_, nullptr)),
225231
output_schema_(std::exchange(other.output_schema_, nullptr)),

‎src/iceberg/arrow_c_data_util_internal.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "iceberg/result.h"
3636
#include "iceberg/type_fwd.h"
3737

38+
struct ArrowArrayView;
39+
3840
namespace iceberg {
3941

4042
/// \brief Cached state for ProjectBatch over one input/output schema pair.
@@ -242,4 +244,10 @@ ICEBERG_EXPORT Result<ArrowArray> ProjectBatch(ArrowArray* input_batch,
242244
std::span<const int32_t> row_indices,
243245
ProjectionContext& projection);
244246

247+
/// \brief Append one value from an Arrow array into a compatible nanoarrow builder.
248+
ICEBERG_EXPORT Status AppendArrayValue(const ArrowSchema& input_schema,
249+
const ArrowArray& input_array,
250+
const ArrowArrayView& input_view,
251+
int64_t row_index, ArrowArray* output_array);
252+
245253
} // namespace iceberg

‎src/iceberg/deletes/position_delete_index.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ int64_t PositionDeleteIndex::Cardinality() const {
136136
return static_cast<int64_t>(bitmap_.Cardinality());
137137
}
138138

139+
void PositionDeleteIndex::ForEach(const std::function<void(int64_t)>& fn) const {
140+
bitmap_.ForEach(fn);
141+
}
142+
139143
void PositionDeleteIndex::Merge(const PositionDeleteIndex& other) {
140144
bitmap_.Or(other.bitmap_);
141145
delete_files_.insert(delete_files_.end(), other.delete_files_.begin(),

‎src/iceberg/deletes/position_delete_index.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/// Index of deleted row positions for a data file.
2424

2525
#include <cstdint>
26+
#include <functional>
2627
#include <memory>
2728
#include <span>
2829
#include <vector>
@@ -66,6 +67,9 @@ class ICEBERG_EXPORT PositionDeleteIndex {
6667
/// \brief Get the number of deleted positions.
6768
int64_t Cardinality() const;
6869

70+
/// \brief Iterate over deleted positions in ascending order.
71+
void ForEach(const std::function<void(int64_t)>& fn) const;
72+
6973
/// \brief Merge another index into this one.
7074
/// \param other The index to merge (union operation)
7175
void Merge(const PositionDeleteIndex& other);

‎src/iceberg/inspect/meson.build‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
# under the License.
1717

1818
install_headers(
19-
['history_table.h', 'metadata_table.h', 'snapshots_table.h'],
19+
[
20+
'history_table.h',
21+
'metadata_table.h',
22+
'position_deletes_table.h',
23+
'snapshots_table.h',
24+
],
2025
subdir: 'iceberg/inspect',
2126
)

‎src/iceberg/inspect/metadata_table.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <utility>
2424

2525
#include "iceberg/inspect/history_table.h"
26+
#include "iceberg/inspect/position_deletes_table.h"
2627
#include "iceberg/inspect/snapshots_table.h"
2728

2829
namespace iceberg {
@@ -35,6 +36,10 @@ MetadataTable::MetadataTable(std::shared_ptr<Table> source_table,
3536

3637
MetadataTable::~MetadataTable() = default;
3738

39+
Result<ArrowArray> MetadataTable::Scan(const Schema& /*projected_schema*/) {
40+
return NotSupported("Scan is not supported for this metadata table type");
41+
}
42+
3843
Result<std::unique_ptr<MetadataTable>> MetadataTable::Make(std::shared_ptr<Table> table,
3944
Kind kind) {
4045
if (table == nullptr) [[unlikely]] {
@@ -46,6 +51,8 @@ Result<std::unique_ptr<MetadataTable>> MetadataTable::Make(std::shared_ptr<Table
4651
return SnapshotsTable::Make(table);
4752
case Kind::kHistory:
4853
return HistoryTable::Make(table);
54+
case Kind::kPositionDeletes:
55+
return PositionDeletesTable::Make(table);
4956
}
5057

5158
return NotSupported("Unsupported metadata table type");

‎src/iceberg/inspect/metadata_table.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <memory>
2626

27+
#include "iceberg/arrow_c_data.h"
2728
#include "iceberg/iceberg_export.h"
2829
#include "iceberg/result.h"
2930
#include "iceberg/table_identifier.h"
@@ -37,6 +38,7 @@ class ICEBERG_EXPORT MetadataTable {
3738
enum class Kind {
3839
kSnapshots,
3940
kHistory,
41+
kPositionDeletes,
4042
};
4143

4244
static Result<std::unique_ptr<MetadataTable>> Make(std::shared_ptr<Table> table,
@@ -46,6 +48,14 @@ class ICEBERG_EXPORT MetadataTable {
4648

4749
virtual Kind kind() const noexcept = 0;
4850

51+
/// \brief Scan all rows using the metadata table's full schema.
52+
Result<ArrowArray> Scan() { return Scan(*schema_); }
53+
54+
/// \brief Scan all rows projected to the requested top-level fields.
55+
///
56+
/// The default implementation returns NotSupported.
57+
virtual Result<ArrowArray> Scan(const Schema& projected_schema);
58+
4959
const TableIdentifier& name() const { return identifier_; }
5060

5161
const std::shared_ptr<Schema>& schema() const { return schema_; }

0 commit comments

Comments
 (0)