Skip to content

Commit 9f00fc1

Browse files
committed
Add support for non empty domain var by name [ch1877]
1 parent a9a9e47 commit 9f00fc1

File tree

2 files changed

+202
-2
lines changed

2 files changed

+202
-2
lines changed

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,111 @@ public Pair getNonEmptyDomainFromName(String name) throws TileDBError {
540540
}
541541
}
542542

543+
/**
544+
* Retrieves the non-empty domain range sizes from an array for a given dimension index. This is
545+
* the union of the non-empty domains of the array fragments on the given dimension. Applicable
546+
* only to var-sized dimensions.
547+
*
548+
* @param index The dimension index
549+
* @return The non-empty domain range sizes
550+
* @throws TileDBError A TileDB exception
551+
*/
552+
public Pair<BigInteger, BigInteger> getNonEmptyDomainVarSizeFromIndex(long index)
553+
throws TileDBError {
554+
SWIGTYPE_p_int emptyp = tiledb.new_intp();
555+
SWIGTYPE_p_unsigned_long_long startSize = tiledb.new_ullp();
556+
SWIGTYPE_p_unsigned_long_long endSize = tiledb.new_ullp();
557+
558+
ctx.handleError(
559+
tiledb.tiledb_array_get_non_empty_domain_var_size_from_index(
560+
ctx.getCtxp(), arrayp, index, startSize, endSize, emptyp));
561+
562+
return new Pair(tiledb.ullp_value(startSize), tiledb.ullp_value(endSize));
563+
}
564+
565+
/**
566+
* Retrieves the non-empty domain range sizes from an array for a given dimension name. This is
567+
* the union of the non-empty domains of the array fragments on the given dimension. Applicable
568+
* only to var-sized dimensions.
569+
*
570+
* @param name The dimension name
571+
* @return The non-empty domain range sizes
572+
* @throws TileDBError A TileDB exception
573+
*/
574+
public Pair<BigInteger, BigInteger> getNonEmptyDomainVarSizeFromName(String name)
575+
throws TileDBError {
576+
SWIGTYPE_p_int emptyp = tiledb.new_intp();
577+
SWIGTYPE_p_unsigned_long_long startSize = tiledb.new_ullp();
578+
SWIGTYPE_p_unsigned_long_long endSize = tiledb.new_ullp();
579+
580+
ctx.handleError(
581+
tiledb.tiledb_array_get_non_empty_domain_var_size_from_name(
582+
ctx.getCtxp(), arrayp, name, startSize, endSize, emptyp));
583+
584+
return new Pair(tiledb.ullp_value(startSize), tiledb.ullp_value(endSize));
585+
}
586+
587+
/**
588+
* Retrieves the non-empty domain from an array for a given dimension index. This is the union of
589+
* the non-empty domains of the array fragments on the given dimension. Applicable only to
590+
* var-sized dimensions.
591+
*
592+
* @param index The dimension index
593+
* @return The non-empty domain
594+
* @throws TileDBError A TileDB exception
595+
*/
596+
public Pair<String, String> getNonEmptyDomainVarFromIndex(long index) throws TileDBError {
597+
SWIGTYPE_p_int emptyp = tiledb.new_intp();
598+
599+
Dimension dim = this.schema.getDomain().getDimension(index);
600+
Pair<BigInteger, BigInteger> size = this.getNonEmptyDomainVarSizeFromIndex(index);
601+
602+
Datatype dimType = dim.getType();
603+
int startSize = size.getFirst().intValue();
604+
int endSize = size.getSecond().intValue();
605+
606+
NativeArray start = new NativeArray(ctx, startSize, dimType);
607+
NativeArray end = new NativeArray(ctx, endSize, dimType);
608+
609+
ctx.handleError(
610+
tiledb.tiledb_array_get_non_empty_domain_var_from_index(
611+
ctx.getCtxp(), arrayp, index, start.toVoidPointer(), end.toVoidPointer(), emptyp));
612+
613+
return new Pair(
614+
new String((byte[]) start.toJavaArray()), new String((byte[]) end.toJavaArray()));
615+
}
616+
617+
/**
618+
* Retrieves the non-empty domain from an array for a given dimension name. This is the union of
619+
* the non-empty domains of the array fragments on the given dimension. Applicable only to
620+
* var-sized dimensions.
621+
*
622+
* @param name The dimension name
623+
* @return The non-empty domain
624+
* @throws TileDBError A TileDB exception
625+
*/
626+
public Pair<String, String> getNonEmptyDomainVarFromName(String name) throws TileDBError {
627+
SWIGTYPE_p_int emptyp = tiledb.new_intp();
628+
629+
Dimension dim = this.schema.getDomain().getDimension(name);
630+
631+
Pair<BigInteger, BigInteger> size = this.getNonEmptyDomainVarSizeFromName(name);
632+
633+
Datatype dimType = dim.getType();
634+
int startSize = size.getFirst().intValue();
635+
int endSize = size.getSecond().intValue();
636+
637+
NativeArray start = new NativeArray(ctx, startSize, dimType);
638+
NativeArray end = new NativeArray(ctx, endSize, dimType);
639+
640+
ctx.handleError(
641+
tiledb.tiledb_array_get_non_empty_domain_var_from_name(
642+
ctx.getCtxp(), arrayp, name, start.toVoidPointer(), end.toVoidPointer(), emptyp));
643+
644+
return new Pair(
645+
new String((byte[]) start.toJavaArray()), new String((byte[]) end.toJavaArray()));
646+
}
647+
543648
/**
544649
* Compute an upper bound on the buffer elements needed to read a subarray.
545650
*

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

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static io.tiledb.java.api.Datatype.*;
44
import static io.tiledb.java.api.Layout.TILEDB_ROW_MAJOR;
5+
import static io.tiledb.java.api.Layout.TILEDB_UNORDERED;
56
import static io.tiledb.java.api.QueryType.TILEDB_READ;
67
import static io.tiledb.java.api.QueryType.TILEDB_WRITE;
78

@@ -17,6 +18,7 @@ public class ArrayTest {
1718

1819
private Context ctx;
1920
private String arrayURI;
21+
private String dimName;
2022
private String attributeName;
2123
private byte[] key;
2224

@@ -26,6 +28,7 @@ public class ArrayTest {
2628
public void setup() throws Exception {
2729
ctx = new Context();
2830
arrayURI = temp.getRoot().toString();
31+
dimName = "d1";
2932
attributeName = "a1";
3033
String keyString = "0123456789abcdeF0123456789abcdeF";
3134
key = keyString.getBytes(StandardCharsets.US_ASCII);
@@ -46,14 +49,14 @@ private Object[] getArray(Object val) {
4649
return outputArray;
4750
}
4851

49-
public ArraySchema schemaCreate() throws Exception {
52+
public ArraySchema schemaCreate(ArrayType type) throws TileDBError {
5053
Dimension<Long> d1 =
5154
new Dimension<Long>(ctx, "d1", Long.class, new Pair<Long, Long>(1l, 4l), 2l);
5255
Domain domain = new Domain(ctx);
5356
domain.addDimension(d1);
5457

5558
Attribute a1 = new Attribute(ctx, attributeName, Long.class);
56-
ArraySchema schema = new ArraySchema(ctx, ArrayType.TILEDB_DENSE);
59+
ArraySchema schema = new ArraySchema(ctx, type);
5760
schema.setTileOrder(Layout.TILEDB_ROW_MAJOR);
5861
schema.setCellOrder(Layout.TILEDB_ROW_MAJOR);
5962
schema.setDomain(domain);
@@ -62,6 +65,34 @@ public ArraySchema schemaCreate() throws Exception {
6265
return schema;
6366
}
6467

68+
public ArraySchema schemaCreate() throws TileDBError {
69+
return schemaCreate(ArrayType.TILEDB_DENSE);
70+
}
71+
72+
public ArraySchema schemaStringDimsCreate(ArrayType arrayType) throws Exception {
73+
Dimension<Long> d1 = new Dimension<Long>(ctx, "d1", TILEDB_STRING_ASCII, null, null);
74+
Domain domain = new Domain(ctx);
75+
domain.addDimension(d1);
76+
77+
ArraySchema schema = new ArraySchema(ctx, arrayType);
78+
79+
schema.setDomain(domain);
80+
schema.check();
81+
return schema;
82+
}
83+
84+
public void insertArbitraryValuesVarSize(
85+
Array array, String attrName, NativeArray a_data, NativeArray a_offsets, Layout layout)
86+
throws TileDBError {
87+
// Create query
88+
try (Query query = new Query(array, TILEDB_WRITE)) {
89+
query.setLayout(layout).setBuffer(attrName, a_offsets, a_data);
90+
query.submit();
91+
query.finalizeQuery();
92+
}
93+
array.close();
94+
}
95+
6596
public void insertArbitraryValuesMeth(Array array, NativeArray a_data) throws TileDBError {
6697
// Create query
6798
try (Query query = new Query(array, TILEDB_WRITE)) {
@@ -260,6 +291,70 @@ public void testArraygetNonEmptyDomainFromName() throws Exception {
260291
}
261292
}
262293

294+
@Test
295+
public void testArrayGetNonEmptyDomainVarSizeFromIndex() throws Exception {
296+
Array.create(arrayURI, schemaStringDimsCreate(ArrayType.TILEDB_SPARSE));
297+
NativeArray data = new NativeArray(ctx, "aabbccddee", TILEDB_STRING_ASCII);
298+
NativeArray offsets = new NativeArray(ctx, new long[] {0, 2, 4, 6}, TILEDB_UINT64);
299+
insertArbitraryValuesVarSize(
300+
new Array(ctx, arrayURI, TILEDB_WRITE), dimName, data, offsets, TILEDB_UNORDERED);
301+
302+
Array array = new Array(ctx, arrayURI, TILEDB_READ);
303+
304+
Pair<BigInteger, BigInteger> size = array.getNonEmptyDomainVarSizeFromIndex(0);
305+
306+
Assert.assertEquals(2, size.getFirst().intValue());
307+
Assert.assertEquals(4, size.getSecond().intValue());
308+
}
309+
310+
@Test
311+
public void testArrayGetNonEmptyDomainVarSizeFromName() throws Exception {
312+
Array.create(arrayURI, schemaStringDimsCreate(ArrayType.TILEDB_SPARSE));
313+
NativeArray data = new NativeArray(ctx, "aabbccddee", TILEDB_STRING_ASCII);
314+
NativeArray offsets = new NativeArray(ctx, new long[] {0, 2, 4, 6}, TILEDB_UINT64);
315+
insertArbitraryValuesVarSize(
316+
new Array(ctx, arrayURI, TILEDB_WRITE), dimName, data, offsets, TILEDB_UNORDERED);
317+
318+
Array array = new Array(ctx, arrayURI, TILEDB_READ);
319+
320+
Pair<BigInteger, BigInteger> size = array.getNonEmptyDomainVarSizeFromName(dimName);
321+
322+
Assert.assertEquals(2, size.getFirst().intValue());
323+
Assert.assertEquals(4, size.getSecond().intValue());
324+
}
325+
326+
@Test
327+
public void testArrayGetNonEmptyDomainVarFromIndex() throws Exception {
328+
Array.create(arrayURI, schemaStringDimsCreate(ArrayType.TILEDB_SPARSE));
329+
NativeArray data = new NativeArray(ctx, "aabbccddee", TILEDB_STRING_ASCII);
330+
NativeArray offsets = new NativeArray(ctx, new long[] {0, 2, 4, 6}, TILEDB_UINT64);
331+
insertArbitraryValuesVarSize(
332+
new Array(ctx, arrayURI, TILEDB_WRITE), dimName, data, offsets, TILEDB_UNORDERED);
333+
334+
Array array = new Array(ctx, arrayURI, TILEDB_READ);
335+
336+
Pair<String, String> size = array.getNonEmptyDomainVarFromIndex(0);
337+
338+
Assert.assertEquals("aa", size.getFirst());
339+
Assert.assertEquals("ddee", size.getSecond());
340+
}
341+
342+
@Test
343+
public void testArrayGetNonEmptyDomainVarFromName() throws Exception {
344+
Array.create(arrayURI, schemaStringDimsCreate(ArrayType.TILEDB_SPARSE));
345+
NativeArray data = new NativeArray(ctx, "aabbccddee", TILEDB_STRING_ASCII);
346+
NativeArray offsets = new NativeArray(ctx, new long[] {0, 2, 4, 6}, TILEDB_UINT64);
347+
insertArbitraryValuesVarSize(
348+
new Array(ctx, arrayURI, TILEDB_WRITE), dimName, data, offsets, TILEDB_UNORDERED);
349+
350+
Array array = new Array(ctx, arrayURI, TILEDB_READ);
351+
352+
Pair<String, String> size = array.getNonEmptyDomainVarFromName(dimName);
353+
354+
Assert.assertEquals("aa", size.getFirst());
355+
Assert.assertEquals("ddee", size.getSecond());
356+
}
357+
263358
@Test
264359
public void testArrayMetadata() throws Exception {
265360
Array.create(arrayURI, schemaCreate());

0 commit comments

Comments
 (0)