Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iceberg_rust_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default = ["julia"]
julia = []

[dependencies]
iceberg = { git = "https://github.com/RelationalAI/iceberg-rust.git", rev = "37e79b805407a0340d08823373cafed9cdac0083" }
iceberg = { git = "https://github.com/RelationalAI/iceberg-rust.git", rev = "ae83309fd198ec30f052a7e9f983711c5f581aea" }
object_store_ffi = { git = "https://github.com/RelationalAI/object_store_ffi", rev = "79b08071c7a1642532b5891253280861eca9e44e", default-features = false }
tokio = { version = "1.0", features = ["full"] }
futures = "0.3"
Expand Down
27 changes: 24 additions & 3 deletions iceberg_rust_ffi/src/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use tokio::sync::Mutex as AsyncMutex;
use crate::scan_common::*;
use crate::{IcebergArrowStream, IcebergTable};

/// Sentinel value for optional snapshot IDs in the C API.
/// When -1 is passed as from_snapshot_id or to_snapshot_id, it means None (use default).
const SNAPSHOT_ID_NONE: i64 = -1;

/// Struct for incremental scan builder and scan
#[repr(C)]
pub struct IcebergIncrementalScan {
Expand Down Expand Up @@ -62,6 +66,11 @@ impl RawResponse for IcebergUnzippedStreamsResponse {
}

/// Create a new incremental scan builder
///
/// # Arguments
/// * `table` - The table to scan
/// * `from_snapshot_id` - Starting snapshot ID, or `SNAPSHOT_ID_NONE` (-1) to scan from the root (oldest) snapshot
/// * `to_snapshot_id` - Ending snapshot ID, or `SNAPSHOT_ID_NONE` (-1) to scan to the current (latest) snapshot
#[no_mangle]
pub extern "C" fn iceberg_new_incremental_scan(
table: *mut IcebergTable,
Expand All @@ -72,9 +81,21 @@ pub extern "C" fn iceberg_new_incremental_scan(
return ptr::null_mut();
}
let table_ref = unsafe { &*table };
let scan_builder = table_ref
.table
.incremental_scan(from_snapshot_id, to_snapshot_id);

// Convert SNAPSHOT_ID_NONE to None for optional snapshot IDs
let from_id = if from_snapshot_id == SNAPSHOT_ID_NONE {
None
} else {
Some(from_snapshot_id)
};

let to_id = if to_snapshot_id == SNAPSHOT_ID_NONE {
None
} else {
Some(to_snapshot_id)
};

let scan_builder = table_ref.table.incremental_scan(from_id, to_id);
Box::into_raw(Box::new(IcebergIncrementalScan {
builder: Some(scan_builder),
scan: None,
Expand Down
35 changes: 31 additions & 4 deletions src/incremental.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Incremental table scan implementation

# Sentinel value for optional snapshot IDs (matches Rust FFI SNAPSHOT_ID_NONE constant)
const SNAPSHOT_ID_NONE = Int64(-1)

"""
IncrementalScan

Expand Down Expand Up @@ -49,15 +52,39 @@ mutable struct UnzippedStreamsResponse
end

"""
new_incremental_scan(table::Table, from_snapshot_id::Int64, to_snapshot_id::Int64) -> IncrementalScan
new_incremental_scan(table::Table, from_snapshot_id::Union{Int64,Nothing}, to_snapshot_id::Union{Int64,Nothing}) -> IncrementalScan

Create an incremental scan for the given table between two snapshots.

# Arguments
- `table::Table`: The Iceberg table to scan
- `from_snapshot_id`: Starting snapshot ID, or `nothing` to scan from the root (oldest) snapshot
- `to_snapshot_id`: Ending snapshot ID, or `nothing` to scan to the current (latest) snapshot

# Examples
```julia
# Scan full history (root to current)
scan = new_incremental_scan(table, nothing, nothing)

# Scan from root to specific snapshot
scan = new_incremental_scan(table, nothing, snapshot_id)

# Scan from specific snapshot to current
scan = new_incremental_scan(table, snapshot_id, nothing)

# Scan between specific snapshots
scan = new_incremental_scan(table, from_id, to_id)
```
"""
function new_incremental_scan(table::Table, from_snapshot_id::Int64, to_snapshot_id::Int64)
function new_incremental_scan(table::Table, from_snapshot_id::Union{Int64,Nothing}, to_snapshot_id::Union{Int64,Nothing})
# Convert nothing to SNAPSHOT_ID_NONE for C API
from_id = from_snapshot_id === nothing ? SNAPSHOT_ID_NONE : from_snapshot_id
to_id = to_snapshot_id === nothing ? SNAPSHOT_ID_NONE : to_snapshot_id

scan_ptr = @ccall rust_lib.iceberg_new_incremental_scan(
table::Table,
from_snapshot_id::Int64,
to_snapshot_id::Int64
from_id::Int64,
to_id::Int64
)::Ptr{Cvoid}
return IncrementalScan(scan_ptr)
end
Expand Down