From 6815c276a1eac3e91d8faafc18cd8aaedae632d8 Mon Sep 17 00:00:00 2001 From: yanghua Date: Wed, 19 Nov 2025 20:31:31 +0800 Subject: [PATCH] fix: panicException when calling compaction --- python/python/tests/test_optimize.py | 18 ++++++++++++++++++ python/src/transaction.rs | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/python/python/tests/test_optimize.py b/python/python/tests/test_optimize.py index 5b58891d28a..1f23f3bac48 100644 --- a/python/python/tests/test_optimize.py +++ b/python/python/tests/test_optimize.py @@ -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 + ) diff --git a/python/src/transaction.rs b/python/src/transaction.rs index 2fc5272bd93..87400afe743 100644 --- a/python/src/transaction.rs +++ b/python/src/transaction.rs @@ -611,7 +611,7 @@ impl<'py> IntoPyObject<'py> for PyLance<&RewriteGroup> { fn into_pyobject(self, py: Python<'py>) -> Result { 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"); @@ -653,7 +653,7 @@ impl<'py> IntoPyObject<'py> for PyLance<&RewrittenIndex> { fn into_pyobject(self, py: Python<'py>) -> Result { 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");