-
Notifications
You must be signed in to change notification settings - Fork 638
feat(java): support replace schema and field metadata #4119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| import com.lancedb.lance.ipc.LanceScanner; | ||
| import com.lancedb.lance.schema.ColumnAlteration; | ||
| import com.lancedb.lance.schema.LanceField; | ||
| import com.lancedb.lance.schema.SqlExpressions; | ||
|
|
||
| import org.apache.arrow.c.ArrowArrayStream; | ||
|
|
@@ -847,4 +848,74 @@ void testGetLanceSchema(@TempDir Path tempDir) { | |
| assertEquals(testDataset.getSchema(), dataset.getLanceSchema().asArrowSchema()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testReplaceSchemaMetadata(@TempDir Path tempDir) { | ||
| String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can just use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I think that would be better. Do we need to use this pattern just in this PR or raise another PR to change the whole DatasetTest? Or just modify the whole DatasetTest in this PR. I used to keep PRs small, but not preferable.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an issue tracking this, we can do it separately |
||
| String datasetPath = tempDir.resolve(testMethodName).toString(); | ||
| try (RootAllocator allocator = new RootAllocator(Long.MAX_VALUE)) { | ||
| TestUtils.SimpleTestDataset testDataset = | ||
| new TestUtils.SimpleTestDataset(allocator, datasetPath); | ||
| dataset = testDataset.createEmptyDataset(); | ||
| assertEquals(1, dataset.version()); | ||
| Map<String, String> replaceMetadata = new HashMap<>(); | ||
| replaceMetadata.put("key1", "value1"); | ||
| replaceMetadata.put("key2", "value2"); | ||
| dataset.replaceSchemaMetadata(replaceMetadata); | ||
| assertEquals(2, dataset.version()); | ||
| Map<String, String> currentMetadata = dataset.getSchema().getCustomMetadata(); | ||
| for (String configKey : currentMetadata.keySet()) { | ||
| assertEquals(currentMetadata.get(configKey), replaceMetadata.get(configKey)); | ||
| } | ||
| assertEquals(replaceMetadata.size(), currentMetadata.size()); | ||
|
|
||
| Map<String, String> replaceConfig2 = new HashMap<>(); | ||
| replaceConfig2.put("key1", "value3"); | ||
| dataset.replaceSchemaMetadata(replaceConfig2); | ||
| currentMetadata = dataset.getSchema().getCustomMetadata(); | ||
| assertEquals(3, dataset.version()); | ||
| assertEquals(1, currentMetadata.size()); | ||
| assertEquals("value3", currentMetadata.get("key1")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testReplaceFieldConfig(@TempDir Path tempDir) { | ||
| String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); | ||
| String datasetPath = tempDir.resolve(testMethodName).toString(); | ||
| try (RootAllocator allocator = new RootAllocator(Long.MAX_VALUE)) { | ||
| TestUtils.SimpleTestDataset testDataset = | ||
| new TestUtils.SimpleTestDataset(allocator, datasetPath); | ||
| dataset = testDataset.createEmptyDataset(); | ||
| assertEquals(1, dataset.version()); | ||
| LanceField field = dataset.getLanceSchema().fields().get(0); | ||
| Map<String, String> replaceMetadata = new HashMap<>(); | ||
| replaceMetadata.put("key1", "value1"); | ||
| replaceMetadata.put("key2", "value2"); | ||
| dataset.replaceFieldMetadata(Collections.singletonMap(field.getId(), replaceMetadata)); | ||
| assertEquals(2, dataset.version()); | ||
| Map<String, String> currentMetadata = dataset.getSchema().getFields().get(0).getMetadata(); | ||
| for (String configKey : currentMetadata.keySet()) { | ||
| assertEquals(currentMetadata.get(configKey), replaceMetadata.get(configKey)); | ||
| } | ||
| assertEquals(replaceMetadata.size(), currentMetadata.size()); | ||
|
|
||
| Map<String, String> replaceConfig2 = new HashMap<>(); | ||
|
jackye1995 marked this conversation as resolved.
|
||
| replaceConfig2.put("key1", "value3"); | ||
| dataset.replaceFieldMetadata(Collections.singletonMap(field.getId(), replaceConfig2)); | ||
| currentMetadata = dataset.getSchema().getFields().get(0).getMetadata(); | ||
| assertEquals(3, dataset.version()); | ||
| assertEquals(1, currentMetadata.size()); | ||
| assertEquals("value3", currentMetadata.get("key1")); | ||
|
|
||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> | ||
| dataset.replaceFieldMetadata( | ||
| Collections.singletonMap(Integer.MAX_VALUE, replaceConfig2))); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> dataset.replaceFieldMetadata(Collections.singletonMap(-1, replaceConfig2))); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.