Skip to content

Add putMetadata overload #156

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

Merged
merged 1 commit into from
May 4, 2020
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
12 changes: 12 additions & 0 deletions src/main/java/io/tiledb/java/api/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,18 @@ public Boolean hasMetadataKey(String key) throws TileDBError {
return result;
}

/**
* Puts a metadata key-value item to an open array. The array must be opened in WRITE mode,
* otherwise the function will error out.
*
* @param key a key to assign to the input value
* @param buffer the metadata to put into the Array metadata
* @throws TileDBError A TileDB exception
*/
public void putMetadata(String key, Object buffer) throws TileDBError {
putMetadata(key, new NativeArray(ctx, buffer, buffer.getClass()));
}

/**
* Puts a metadata key-value item to an open array. The array must be opened in WRITE mode,
* otherwise the function will error out.
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/io/tiledb/java/api/ArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,34 @@ public void testArrayMetadata() throws Exception {

arraydn.close();
}

@Test
public void testArrayPutMetadataOverload() throws Exception {
Array.create(arrayURI, schemaCreate());

long[] array_a = new long[] {1, 2, 3, 6};
insertArbitraryValues(new NativeArray(ctx, array_a, Long.class));

Array arrayw = new Array(ctx, arrayURI, TILEDB_WRITE);

String floatKey = "md-float";
float[] metadataFloat =
new float[] {
0.1f, 0.2f, 1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f,
4.1f, 4.2f, 5.1f, 5.2f, 6.1f, 6.2f, 7.1f, 7.2f,
8.1f, 8.2f, 9.1f, 9.2f, 10.1f, 10.2f, 11.1f, 11.2f,
12.1f, 12.2f, 13.1f, 13.2f, 14.1f, 14.2f, 15.1f, 15.2f
};

arrayw.putMetadata(floatKey, metadataFloat);
arrayw.close();

Array array = new Array(ctx, arrayURI, TILEDB_READ);

float[] metadataFloatActual = (float[]) array.getMetadata(floatKey).toJavaArray();

Assert.assertArrayEquals(metadataFloat, metadataFloatActual, 1e-10f);

array.close();
}
}