From e04ce82f4d6318896f633152b9fb93774ed44b04 Mon Sep 17 00:00:00 2001 From: majin1102 Date: Thu, 29 Jan 2026 21:40:04 +0800 Subject: [PATCH 1/2] fix(java): throw panic when read CreateIndex transaction --- java/lance-jni/src/transaction.rs | 16 +++++++ .../test/java/org/lance/TransactionTest.java | 47 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/java/lance-jni/src/transaction.rs b/java/lance-jni/src/transaction.rs index df80ba94f3f..ea5996aaeed 100644 --- a/java/lance-jni/src/transaction.rs +++ b/java/lance-jni/src/transaction.rs @@ -394,6 +394,22 @@ fn convert_to_java_operation_inner<'local>( ], )?) } + Operation::CreateIndex { + new_indices, + removed_indices, + } => { + let java_new_indices = export_vec(env, &new_indices)?; + let java_removed_indices = export_vec(env, &removed_indices)?; + + Ok(env.new_object( + "org/lance/operation/CreateIndex", + "(Ljava/util/List;Ljava/util/List;)V", + &[ + JValue::Object(&java_new_indices), + JValue::Object(&java_removed_indices), + ], + )?) + } Operation::Update { removed_fragment_ids, updated_fragments, diff --git a/java/src/test/java/org/lance/TransactionTest.java b/java/src/test/java/org/lance/TransactionTest.java index 3d7172f29dd..09f1a4b9b31 100644 --- a/java/src/test/java/org/lance/TransactionTest.java +++ b/java/src/test/java/org/lance/TransactionTest.java @@ -13,7 +13,13 @@ */ package org.lance; +import org.lance.index.Index; +import org.lance.index.IndexOptions; +import org.lance.index.IndexParams; +import org.lance.index.IndexType; +import org.lance.index.scalar.ScalarIndexParams; import org.lance.operation.Append; +import org.lance.operation.CreateIndex; import org.apache.arrow.memory.RootAllocator; import org.junit.jupiter.api.Test; @@ -22,10 +28,14 @@ import java.nio.file.Path; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TransactionTest { @@ -63,4 +73,41 @@ public void testTransaction(@TempDir Path tempDir) { } } } + + @Test + public void testReadTransactionCreateIndex(@TempDir Path tempDir) { + String datasetPath = tempDir.resolve("read_transaction_create_index").toString(); + try (RootAllocator allocator = new RootAllocator(Long.MAX_VALUE)) { + TestUtils.SimpleTestDataset testDataset = + new TestUtils.SimpleTestDataset(allocator, datasetPath); + + try (Dataset dataset = testDataset.createEmptyDataset()) { + assertEquals(1, dataset.version()); + } + + try (Dataset dataset = testDataset.write(1, 10)) { + ScalarIndexParams scalarParams = ScalarIndexParams.create("btree", "{\"zone_size\": 2048}"); + IndexParams indexParams = IndexParams.builder().setScalarIndexParams(scalarParams).build(); + + dataset.createIndex( + IndexOptions.builder(Collections.singletonList("id"), IndexType.BTREE, indexParams) + .withIndexName("btree_id_index") + .build()); + + assertTrue( + dataset.listIndexes().contains("btree_id_index"), + "Expected 'btree_id_index' to be created"); + + Transaction readTx = dataset.readTransaction().orElse(null); + assertNotNull(readTx, "readTransaction() should return a transaction for CreateIndex"); + assertEquals("CreateIndex", readTx.operation().name()); + + assertInstanceOf(CreateIndex.class, readTx.operation()); + CreateIndex op = (CreateIndex) readTx.operation(); + assertFalse(op.getNewIndices().isEmpty(), "newIndices should not be empty for CreateIndex"); + assertTrue(op.getRemovedIndices().isEmpty(), "removedIndices should be empty for CreateIndex"); + assertEquals("btree_id_index", (op.getNewIndices().get(0).name())); + } + } + } } From 3775d1f18fb9aa07f6f1782296dd81404eb683e6 Mon Sep 17 00:00:00 2001 From: majin1102 Date: Thu, 29 Jan 2026 21:43:52 +0800 Subject: [PATCH 2/2] spotless --- java/src/test/java/org/lance/TransactionTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java/src/test/java/org/lance/TransactionTest.java b/java/src/test/java/org/lance/TransactionTest.java index 09f1a4b9b31..c9d0e937263 100644 --- a/java/src/test/java/org/lance/TransactionTest.java +++ b/java/src/test/java/org/lance/TransactionTest.java @@ -13,7 +13,6 @@ */ package org.lance; -import org.lance.index.Index; import org.lance.index.IndexOptions; import org.lance.index.IndexParams; import org.lance.index.IndexType; @@ -28,7 +27,6 @@ import java.nio.file.Path; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -105,7 +103,8 @@ public void testReadTransactionCreateIndex(@TempDir Path tempDir) { assertInstanceOf(CreateIndex.class, readTx.operation()); CreateIndex op = (CreateIndex) readTx.operation(); assertFalse(op.getNewIndices().isEmpty(), "newIndices should not be empty for CreateIndex"); - assertTrue(op.getRemovedIndices().isEmpty(), "removedIndices should be empty for CreateIndex"); + assertTrue( + op.getRemovedIndices().isEmpty(), "removedIndices should be empty for CreateIndex"); assertEquals("btree_id_index", (op.getNewIndices().get(0).name())); } }