Skip to content

Commit 917fb4a

Browse files
committed
Added support for estimating result size of nullable attributes
1 parent 788da71 commit 917fb4a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ public synchronized Pair<String, String> getRangeVar(int dimIdx, BigInteger rang
345345
}
346346
}
347347

348+
/**
349+
* Retrieves the estimated result size for a fixed-sized attribute/dimension.
350+
*
351+
* @param ctx The TileDB Context
352+
* @param attribute The attribute name
353+
* @return The estimated result size
354+
* @throws TileDBError
355+
*/
348356
public synchronized int getEstResultSize(Context ctx, String attribute) throws TileDBError {
349357
SWIGTYPE_p_unsigned_long_long size = tiledb.new_ullp();
350358

@@ -354,6 +362,14 @@ public synchronized int getEstResultSize(Context ctx, String attribute) throws T
354362
return tiledb.ullp_value(size).intValue();
355363
}
356364

365+
/**
366+
* Retrieves the estimated result size for a var-sized attribute/dimension.
367+
*
368+
* @param ctx The TileDB Context
369+
* @param attribute The attribute name
370+
* @return A Pair containing the estimated result size of the offsets and the data buffers
371+
* @throws TileDBError
372+
*/
357373
public synchronized Pair<Integer, Integer> getEstResultSizeVar(Context ctx, String attribute)
358374
throws TileDBError {
359375
SWIGTYPE_p_unsigned_long_long offsetsSize = tiledb.new_ullp();
@@ -367,6 +383,50 @@ public synchronized Pair<Integer, Integer> getEstResultSizeVar(Context ctx, Stri
367383
tiledb.ullp_value(offsetsSize).intValue(), tiledb.ullp_value(dataSize).intValue());
368384
}
369385

386+
/**
387+
* Retrieves the estimated result size for a var-sized nullable attribute.
388+
*
389+
* @param ctx The TileDB Context
390+
* @param attribute The attribute name
391+
* @return A Pair containing another Pair with the estimated result size of the offsets and the
392+
* data buffers, and the estimated result size of the validity buffer
393+
* @throws TileDBError
394+
*/
395+
public synchronized Pair<Pair<Integer, Integer>, Integer> getEstResultSizeVarNullable(
396+
Context ctx, String attribute) throws TileDBError {
397+
SWIGTYPE_p_unsigned_long_long size = tiledb.new_ullp();
398+
SWIGTYPE_p_unsigned_long_long offsets = tiledb.new_ullp();
399+
SWIGTYPE_p_unsigned_long_long validity = tiledb.new_ullp();
400+
401+
ctx.handleError(
402+
tiledb.tiledb_query_get_est_result_size_var_nullable(
403+
ctx.getCtxp(), queryp, attribute, offsets, size, validity));
404+
405+
return new Pair(
406+
new Pair(tiledb.ullp_value(offsets).intValue(), tiledb.ullp_value(size).intValue()),
407+
tiledb.ullp_value(validity).intValue());
408+
}
409+
410+
/**
411+
* Retrieves the estimated result size for a fixed-sized nullable attribute.
412+
*
413+
* @param ctx The TileDB Context
414+
* @param attribute The attribute name
415+
* @return The estimated result size
416+
* @throws TileDBError
417+
*/
418+
public synchronized Pair<Integer, Integer> getEstResultSizeNullable(Context ctx, String attribute)
419+
throws TileDBError {
420+
SWIGTYPE_p_unsigned_long_long size = tiledb.new_ullp();
421+
SWIGTYPE_p_unsigned_long_long validity = tiledb.new_ullp();
422+
423+
ctx.handleError(
424+
tiledb.tiledb_query_get_est_result_size_nullable(
425+
ctx.getCtxp(), queryp, attribute, size, validity));
426+
427+
return new Pair(tiledb.ullp_value(size).intValue(), tiledb.ullp_value(validity).intValue());
428+
}
429+
370430
/**
371431
* Retrieves the number of ranges of the query subarray along a given dimension.
372432
*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,10 @@ public void denseArrayReadTest() throws Exception {
11241124
query.setBufferNullable("a1", a1Array, a1byteMap);
11251125
query.setBufferNullable("a2", a2Array, a2byteMap);
11261126

1127+
Pair<Integer, Integer> estimated = query.getEstResultSizeNullable(ctx, "a1");
1128+
Assert.assertEquals((int) estimated.getFirst(), 4);
1129+
Assert.assertEquals((int) estimated.getSecond(), 4);
1130+
11271131
// Submit query
11281132
query.submit();
11291133

@@ -1252,6 +1256,12 @@ public void sparseArrayReadTest() throws Exception {
12521256
query.setBufferNullable("a1", a1Array, a1byteMap);
12531257
query.setBufferNullable("a2", a2Offsets, a2Array, a2byteMap);
12541258

1259+
Pair<Pair<Integer, Integer>, Integer> estimated =
1260+
query.getEstResultSizeVarNullable(ctx, "a2");
1261+
Assert.assertEquals(40, (int) estimated.getFirst().getFirst());
1262+
Assert.assertEquals(40, (int) estimated.getFirst().getFirst());
1263+
Assert.assertEquals(10, (int) estimated.getSecond());
1264+
12551265
// Submit query
12561266
query.submit();
12571267

0 commit comments

Comments
 (0)