Skip to content

Commit 28592dd

Browse files
committed
Add putMetadata overload
1 parent dc80fec commit 28592dd

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/main/java/io/tiledb/java/api/Array.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,19 @@ public Boolean hasMetadataKey(String key) throws TileDBError {
767767
return result;
768768
}
769769

770+
/**
771+
* Puts a metadata key-value item to an open array. The array must be opened in WRITE mode,
772+
* otherwise the function will error out.
773+
*
774+
* @param key a key to assign to the input value
775+
* @param buffer the metadata to put into the Array metadata
776+
* @param javaType javaType of the metadata
777+
* @throws TileDBError A TileDB exception
778+
*/
779+
public void putMetadata(String key, Object buffer, Class javaType) throws TileDBError {
780+
putMetadata(key, new NativeArray(ctx, buffer, javaType));
781+
}
782+
770783
/**
771784
* Puts a metadata key-value item to an open array. The array must be opened in WRITE mode,
772785
* otherwise the function will error out.

src/test/java/io/tiledb/java/api/ArrayTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,34 @@ public void testArrayMetadata() throws Exception {
415415

416416
arraydn.close();
417417
}
418+
419+
@Test
420+
public void testArrayPutMetadataOverload() throws Exception {
421+
Array.create(arrayURI, schemaCreate());
422+
423+
long[] array_a = new long[] {1, 2, 3, 6};
424+
insertArbitraryValues(new NativeArray(ctx, array_a, Long.class));
425+
426+
Array arrayw = new Array(ctx, arrayURI, TILEDB_WRITE);
427+
428+
String floatKey = "md-float";
429+
float[] metadataFloat =
430+
new float[] {
431+
0.1f, 0.2f, 1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f,
432+
4.1f, 4.2f, 5.1f, 5.2f, 6.1f, 6.2f, 7.1f, 7.2f,
433+
8.1f, 8.2f, 9.1f, 9.2f, 10.1f, 10.2f, 11.1f, 11.2f,
434+
12.1f, 12.2f, 13.1f, 13.2f, 14.1f, 14.2f, 15.1f, 15.2f
435+
};
436+
437+
arrayw.putMetadata(floatKey, metadataFloat, Float.class);
438+
arrayw.close();
439+
440+
Array array = new Array(ctx, arrayURI, TILEDB_READ);
441+
442+
float[] metadataFloatActual = (float[]) array.getMetadata(floatKey).toJavaArray();
443+
444+
Assert.assertArrayEquals(metadataFloat, metadataFloatActual, 1e-10f);
445+
446+
array.close();
447+
}
418448
}

0 commit comments

Comments
 (0)