Repository navigation
Expose OverwriteAction.set_snapshot_properties through the FFI #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8319385
52a30eb
6ec94fb
6fd375d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "iceberg_rust_ffi" | ||
| version = "0.9.3" | ||
| version = "0.9.4" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,3 +406,68 @@ end | |
| end | ||
| println("✅ OverwriteAction error handling tests passed") | ||
| end | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # set_snapshot_properties | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| @testset "set_snapshot_properties round-trips through a real commit" begin | ||
| mktempdir() do warehouse | ||
| cat = catalog_create_memory(warehouse) | ||
| table = C_NULL | ||
| updated = C_NULL | ||
| try | ||
| create_namespace(cat, ["ns"]) | ||
| table = create_table(cat, ["ns"], "t", _ow_schema()) | ||
|
|
||
| files = RustyIceberg.with_data_file_writer(table) do w | ||
| write(w, (id=Int64[1, 2], value=[1.0, 2.0])) | ||
| end | ||
|
|
||
| updated = RustyIceberg.with_transaction(table, cat) do tx | ||
| with_overwrite(tx) do action | ||
| add_data_files(action, files) | ||
| # "added-data-files" collides with a computed key; the real value | ||
| # (asserted below) must win, not this bogus one. | ||
| set_snapshot_properties(action, Dict( | ||
| "attempt_id" => "test-attempt-123", | ||
| "added-data-files" => "999", | ||
| )) | ||
| end | ||
| end | ||
|
|
||
| @test !isnothing(table_current_snapshot_id(updated)) | ||
| data = read_table_data(updated) | ||
| @test sort(data.id) == [1, 2] | ||
|
|
||
| summary = table_current_snapshot_summary(updated) | ||
| @test !isnothing(summary) | ||
| @test summary["operation"] == "overwrite" | ||
| @test summary["attempt_id"] == "test-attempt-123" | ||
| @test summary["added-data-files"] == "1" | ||
| @test summary["total-records"] == "2" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing tests the collision behavior, and it rests on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added — round-trip test now sets added-data-files => 999 and asserts the real computed value (1) wins. |
||
| finally | ||
| table != C_NULL && free_table(table) | ||
| updated != C_NULL && free_table(updated) | ||
| free_catalog!(cat) | ||
| end | ||
| end | ||
| println("✅ set_snapshot_properties round-trips through a real commit") | ||
| end | ||
|
|
||
| @testset "table_current_snapshot_summary on a null table throws" begin | ||
| # `Table` is a raw `Ptr{Cvoid}`, not a wrapper struct -- `free_table` can't null it | ||
| # out on the caller's side, so a freed-then-reused Table is unchecked UB here, same | ||
| # as every other Table-consuming function in this file. What the null-check in | ||
| # table_current_snapshot_summary actually guards against is a genuinely-null Table | ||
| # value, matching table_schema's existing behavior -- that's what this tests. | ||
| @test_throws RustyIceberg.IcebergException table_current_snapshot_summary(C_NULL) | ||
| println("✅ table_current_snapshot_summary on a null table throws") | ||
| end | ||
|
|
||
| @testset "set_snapshot_properties on a freed action throws" begin | ||
| action = RustyIceberg.OverwriteAction() | ||
| free_overwrite_action!(action) | ||
| @test_throws RustyIceberg.IcebergException set_snapshot_properties(action, Dict("k" => "v")) | ||
| println("✅ set_snapshot_properties on a freed action throws") | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns
nothingfor two cases: no snapshot, and null/freed table pointer.table_schemaright above throwsSTATE_RESOURCE_FREEDfor the second one. Can we match it? Otherwise a freed handle looks like "never committed", which is the one thing reconciliation shouldn't get wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — added the null-table check, matching table_schema. Also rewrote the corresponding test to pass C_NULL directly instead of a freed table: Table is a raw Ptr{Cvoid}, so free_table can't null the caller's copy, making freed-then-reused UB throughout this file (not just here) rather than something this check can catch.