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
18 changes: 18 additions & 0 deletions python/python/tests/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,21 @@ def test_migration_via_fragment_apis(tmp_path):
ds2 = lance.dataset(tmp_path / "dataset2")

assert ds2.data_storage_version == "2.0"


def test_compaction_generates_rewrite_transaction(tmp_path: Path):
# Create a small dataset with multiple fragments
base_dir = tmp_path / "rewrite_txn"
data = pa.table({"a": range(300), "b": range(300)})

dataset = lance.write_dataset(data, base_dir, max_rows_per_file=100)

# Run compaction: should perform a rewrite (no deletions materialized)
dataset.optimize.compact_files(materialize_deletions=False, num_threads=1)

# Verify at least one transaction is a Rewrite; guard against None entries
transactions = dataset.get_transactions()
assert any(
t is not None and t.operation.__class__.__name__ == "Rewrite"
for t in transactions
)
4 changes: 2 additions & 2 deletions python/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl<'py> IntoPyObject<'py> for PyLance<&RewriteGroup> {
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
let cls = py
.import(intern!(py, "lance"))
.and_then(|module| module.getattr(intern!(py, "LanceTransaction")))
.and_then(|module| module.getattr(intern!(py, "LanceOperation")))
.and_then(|cls| cls.getattr(intern!(py, "RewriteGroup")))
.expect("Failed to get RewriteGroup class");

Expand Down Expand Up @@ -653,7 +653,7 @@ impl<'py> IntoPyObject<'py> for PyLance<&RewrittenIndex> {
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
let cls = py
.import(intern!(py, "lance"))
.and_then(|module| module.getattr(intern!(py, "LanceTransaction")))
.and_then(|module| module.getattr(intern!(py, "LanceOperation")))
.and_then(|cls| cls.getattr(intern!(py, "RewrittenIndex")))
.expect("Failed to get RewrittenIndex class");

Expand Down