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
24 changes: 21 additions & 3 deletions java/src/main/java/org/lance/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,13 @@ public Dataset checkoutVersion(long version) {
Preconditions.checkArgument(version > 0, "version number must be greater than 0");
try (LockManager.ReadLock readLock = lockManager.acquireReadLock()) {
Preconditions.checkArgument(nativeDatasetHandle != 0, "Dataset is closed");
return nativeCheckoutVersion(version);
Dataset newDataset = nativeCheckoutVersion(version);
if (selfManagedAllocator) {
newDataset.allocator = new RootAllocator(Long.MAX_VALUE);
} else {
newDataset.allocator = allocator;
}
return newDataset;
}
}

Expand All @@ -828,7 +834,13 @@ public Dataset checkoutTag(String tag) {
Preconditions.checkArgument(tag != null, "Tag can not be null");
try (LockManager.ReadLock readLock = lockManager.acquireReadLock()) {
Preconditions.checkArgument(nativeDatasetHandle != 0, "Dataset is closed");
return nativeCheckoutTag(tag);
Dataset newDataset = nativeCheckoutTag(tag);
if (selfManagedAllocator) {
newDataset.allocator = new RootAllocator(Long.MAX_VALUE);
} else {
newDataset.allocator = allocator;
}
return newDataset;
}
}

Expand Down Expand Up @@ -1380,7 +1392,13 @@ public Dataset checkout(Ref ref) {
Preconditions.checkNotNull(ref);
try (LockManager.ReadLock readLock = lockManager.acquireReadLock()) {
Preconditions.checkArgument(nativeDatasetHandle != 0, "Dataset is closed");
return nativeCheckout(ref);
Dataset newDataset = nativeCheckout(ref);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add some tests to verify operational after checking out branches?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add getSchema invoking on new dataset in test cases.

if (selfManagedAllocator) {
newDataset.allocator = new RootAllocator(Long.MAX_VALUE);
} else {
newDataset.allocator = allocator;
}
return newDataset;
}
}

Expand Down
3 changes: 3 additions & 0 deletions java/src/test/java/org/lance/DatasetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void testDatasetCheckoutVersion(@TempDir Path tempDir) {

// checkout the dataset at version 1
try (Dataset checkoutV1 = dataset2.checkoutVersion(1)) {
assertNotNull(checkoutV1.getSchema());
assertEquals(1, checkoutV1.version());
assertEquals(2, checkoutV1.latestVersion());
assertEquals(0, checkoutV1.countRows());
Expand Down Expand Up @@ -305,6 +306,7 @@ void testTags(@TempDir Path tempDir) {

// checkout the dataset at version 1
try (Dataset checkoutV1 = dataset2.checkoutTag("tag1")) {
assertNotNull(checkoutV1.getSchema());
assertEquals(1, checkoutV1.version());
assertEquals(2, checkoutV1.latestVersion());
assertEquals(0, checkoutV1.countRows());
Expand Down Expand Up @@ -1696,6 +1698,7 @@ void testBranches(@TempDir Path tempDir) {

// Step 6. use checkout_branch to checkout branch2
try (Dataset branch2V4New = mainV2.checkout(Ref.ofBranch("branch2"))) {
assertNotNull(branch2V4New.getSchema());
assertEquals(4, branch2V4New.version());
assertEquals(10, branch2V4New.countRows()); // A(5) + B(3) + C(2)
}
Expand Down