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
16 changes: 16 additions & 0 deletions java/lance-jni/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 46 additions & 0 deletions java/src/test/java/org/lance/TransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
*/
package org.lance;

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;
Expand All @@ -25,7 +30,10 @@
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 {

Expand Down Expand Up @@ -63,4 +71,42 @@ 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()));
}
}
}
}