Skip to content

Commit 0d34b69

Browse files
Removed usage of deprecated tiledb_array_max_buffer_size and tiledb_array_max_buffer_size_var methods
1 parent 8fdd53a commit 0d34b69

File tree

10 files changed

+54
-146
lines changed

10 files changed

+54
-146
lines changed

src/main/java/examples/io/tiledb/java/api/DenseReadAsync.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ public static void main(String[] args) throws Exception {
4141

4242
Array my_dense_array = new Array(ctx, "my_dense_array");
4343

44-
// Calcuate maximum buffer sizes for the query results per attribute
45-
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
46-
HashMap<String, Pair<Long, Long>> max_sizes = my_dense_array.maxBufferElements(subarray);
47-
4844
// Create query
4945
Query query = new Query(my_dense_array, TILEDB_READ);
5046
query.setLayout(TILEDB_GLOBAL_ORDER);
47+
HashMap<String, Pair<Long, Long>> max_sizes = query.getResultEstimations();
48+
5149
query.setBuffer(
5250
"a1", new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class));
5351
query.setBuffer(

src/main/java/examples/io/tiledb/java/api/DenseReadGlobal.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ public static void main(String[] args) throws Exception {
4747

4848
// Print maximum buffer elements for the query results per attribute
4949
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
50-
HashMap<String, Pair<Long, Long>> max_sizes = my_dense_array.maxBufferElements(subarray);
51-
for (Map.Entry<String, Pair<Long, Long>> e : max_sizes.entrySet()) {
52-
System.out.println(
53-
e.getKey() + " (" + e.getValue().getFirst() + ", " + e.getValue().getSecond() + ")");
54-
}
5550

5651
// Create query
5752
Query query = new Query(my_dense_array, TILEDB_READ);
5853
query.setLayout(TILEDB_GLOBAL_ORDER);
5954
query.setSubarray(subarray);
55+
HashMap<String, Pair<Long, Long>> max_sizes = query.getResultEstimations();
56+
for (Map.Entry<String, Pair<Long, Long>> e : max_sizes.entrySet()) {
57+
System.out.println(
58+
e.getKey() + " (" + e.getValue().getFirst() + ", " + e.getValue().getSecond() + ")");
59+
}
6060
query.setBuffer(
6161
"a1", new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class));
6262
query.setBuffer(

src/main/java/examples/io/tiledb/java/api/SparseReadGlobal.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ public static void main(String[] args) throws Exception {
5858

5959
// Print maximum buffer elements for the query results per attribute
6060
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
61-
HashMap<String, Pair<Long, Long>> max_sizes = my_sparse_array.maxBufferElements(subarray);
62-
for (Map.Entry<String, Pair<Long, Long>> e : max_sizes.entrySet()) {
63-
System.out.println(
64-
e.getKey() + " (" + e.getValue().getFirst() + ", " + e.getValue().getSecond() + ")");
65-
}
6661

6762
// Create query
6863
Query query = new Query(my_sparse_array, TILEDB_READ);
6964
query.setLayout(TILEDB_GLOBAL_ORDER);
7065
query.setSubarray(subarray);
66+
HashMap<String, Pair<Long, Long>> max_sizes = query.getResultEstimations();
67+
for (Map.Entry<String, Pair<Long, Long>> e : max_sizes.entrySet()) {
68+
System.out.println(
69+
e.getKey() + " (" + e.getValue().getFirst() + ", " + e.getValue().getSecond() + ")");
70+
}
71+
7172
query.setBuffer(
7273
"a1", new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class));
7374
query.setBuffer(

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

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -707,85 +707,6 @@ public Pair<String, String> getNonEmptyDomainVarFromName(String name) throws Til
707707
new String((byte[]) start.toJavaArray()), new String((byte[]) end.toJavaArray()));
708708
}
709709

710-
/**
711-
* Compute an upper bound on the buffer elements needed to read a subarray.
712-
*
713-
* @param subarray Domain subarray
714-
* @return The maximum number of elements for each array attribute. If the Array is sparse, max
715-
* number of coordinates are also returned. Note that two numbers are returned per attribute.
716-
* The first is the maximum number of elements in the offset buffer (0 for fixed-sized
717-
* attributes and coordinates), the second is the maximum number of elements of the value
718-
* buffer.
719-
* @throws TileDBError A TileDB exception
720-
*/
721-
@Deprecated
722-
public HashMap<String, Pair<Long, Long>> maxBufferElements(NativeArray subarray)
723-
throws TileDBError {
724-
checkIsOpen();
725-
726-
HashMap<String, Pair<Long, Long>> ret = new HashMap<String, Pair<Long, Long>>();
727-
728-
uint64_tArray off_nbytes = new uint64_tArray(1);
729-
uint64_tArray val_nbytes = new uint64_tArray(1);
730-
731-
try (Domain domain = schema.getDomain()) {
732-
Types.typeCheck(subarray.getNativeType(), domain.getType());
733-
734-
for (long i = 0; i < schema.getAttributeNum(); i++) {
735-
try (Attribute attr = schema.getAttribute(i)) {
736-
String attrName = attr.getName();
737-
if (attr.isVar()) {
738-
ctx.handleError(
739-
tiledb.tiledb_array_max_buffer_size_var(
740-
ctx.getCtxp(),
741-
arrayp,
742-
attrName,
743-
subarray.toVoidPointer(),
744-
off_nbytes.cast(),
745-
val_nbytes.cast()));
746-
ret.put(
747-
attrName,
748-
new Pair(
749-
off_nbytes.getitem(0).longValue() / tiledb.tiledb_offset_size().longValue(),
750-
val_nbytes.getitem(0).longValue()
751-
/ tiledb.tiledb_datatype_size(attr.getType().toSwigEnum()).longValue()));
752-
} else {
753-
// fixed sized
754-
ctx.handleError(
755-
tiledb.tiledb_array_max_buffer_size(
756-
ctx.getCtxp(), arrayp, attrName, subarray.toVoidPointer(), val_nbytes.cast()));
757-
ret.put(
758-
attrName,
759-
new Pair(
760-
0l,
761-
val_nbytes.getitem(0).longValue()
762-
/ tiledb.tiledb_datatype_size(attr.getType().toSwigEnum()).longValue()));
763-
}
764-
}
765-
}
766-
ctx.handleError(
767-
tiledb.tiledb_array_max_buffer_size(
768-
ctx.getCtxp(),
769-
arrayp,
770-
tiledb.tiledb_coords(),
771-
subarray.toVoidPointer(),
772-
val_nbytes.cast()));
773-
774-
for (Dimension dim : domain.getDimensions()) {
775-
ret.put(
776-
dim.getName(),
777-
new Pair(
778-
0l,
779-
val_nbytes.getitem(0).longValue()
780-
/ tiledb.tiledb_datatype_size(dim.getType().toSwigEnum()).longValue()));
781-
}
782-
} finally {
783-
off_nbytes.delete();
784-
val_nbytes.delete();
785-
}
786-
return ret;
787-
}
788-
789710
/**
790711
* Get a metadata key-value item from an open array. The array must be opened in READ mode,
791712
* otherwise the function will error out.

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -349,82 +349,81 @@ public synchronized Pair<String, String> getRangeVar(int dimIdx, BigInteger rang
349349
* Retrieves the estimated result size for a fixed-sized attribute/dimension.
350350
*
351351
* @param ctx The TileDB Context
352-
* @param attribute The attribute name
352+
* @param column The attribute/dimension name
353353
* @return The estimated result size
354354
* @throws TileDBError
355355
*/
356-
public synchronized int getEstResultSize(Context ctx, String attribute) throws TileDBError {
356+
public synchronized long getEstResultSize(Context ctx, String column) throws TileDBError {
357357
SWIGTYPE_p_unsigned_long_long size = tiledb.new_ullp();
358358

359-
ctx.handleError(
360-
tiledb.tiledb_query_get_est_result_size(ctx.getCtxp(), queryp, attribute, size));
359+
ctx.handleError(tiledb.tiledb_query_get_est_result_size(ctx.getCtxp(), queryp, column, size));
361360

362-
return tiledb.ullp_value(size).intValue();
361+
return tiledb.ullp_value(size).longValue();
363362
}
364363

365364
/**
366365
* Retrieves the estimated result size for a var-sized attribute/dimension.
367366
*
368367
* @param ctx The TileDB Context
369-
* @param attribute The attribute name
368+
* @param column The attribute/dimension name
370369
* @return A Pair containing the estimated result size of the offsets and the data buffers
371370
* @throws TileDBError
372371
*/
373-
public synchronized Pair<Integer, Integer> getEstResultSizeVar(Context ctx, String attribute)
372+
public synchronized Pair<Long, Long> getEstResultSizeVar(Context ctx, String column)
374373
throws TileDBError {
375374
SWIGTYPE_p_unsigned_long_long offsetsSize = tiledb.new_ullp();
376375
SWIGTYPE_p_unsigned_long_long dataSize = tiledb.new_ullp();
377376

378377
ctx.handleError(
379378
tiledb.tiledb_query_get_est_result_size_var(
380-
ctx.getCtxp(), queryp, attribute, offsetsSize, dataSize));
379+
ctx.getCtxp(), queryp, column, offsetsSize, dataSize));
381380

382381
return new Pair(
383-
tiledb.ullp_value(offsetsSize).intValue(), tiledb.ullp_value(dataSize).intValue());
382+
tiledb.ullp_value(offsetsSize).longValue(), tiledb.ullp_value(dataSize).longValue());
384383
}
385384

386385
/**
387386
* Retrieves the estimated result size for a var-sized nullable attribute.
388387
*
389388
* @param ctx The TileDB Context
390-
* @param attribute The attribute name
389+
* @param column The attribute/dimension name
391390
* @return A Pair containing another Pair with the estimated result size of the offsets and the
392391
* data buffers, and the estimated result size of the validity buffer
393392
* @throws TileDBError
394393
*/
395-
public synchronized Pair<Pair<Integer, Integer>, Integer> getEstResultSizeVarNullable(
396-
Context ctx, String attribute) throws TileDBError {
394+
public synchronized Pair<Pair<Long, Long>, Long> getEstResultSizeVarNullable(
395+
Context ctx, String column) throws TileDBError {
397396
SWIGTYPE_p_unsigned_long_long size = tiledb.new_ullp();
398397
SWIGTYPE_p_unsigned_long_long offsets = tiledb.new_ullp();
399398
SWIGTYPE_p_unsigned_long_long validity = tiledb.new_ullp();
400399

401400
ctx.handleError(
402401
tiledb.tiledb_query_get_est_result_size_var_nullable(
403-
ctx.getCtxp(), queryp, attribute, offsets, size, validity));
402+
ctx.getCtxp(), queryp, column, offsets, size, validity));
404403

405404
return new Pair(
406-
new Pair(tiledb.ullp_value(offsets).intValue(), tiledb.ullp_value(size).intValue()),
407-
tiledb.ullp_value(validity).intValue());
405+
new Pair(tiledb.ullp_value(offsets).longValue(), tiledb.ullp_value(size).longValue()),
406+
tiledb.ullp_value(validity).longValue());
408407
}
409408

410409
/**
411410
* Retrieves the estimated result size for a fixed-sized nullable attribute.
412411
*
413412
* @param ctx The TileDB Context
414-
* @param attribute The attribute name
413+
* @param column The attribute/dimension name
415414
* @return The estimated result size
416415
* @throws TileDBError
417416
*/
418-
public synchronized Pair<Integer, Integer> getEstResultSizeNullable(Context ctx, String attribute)
417+
public synchronized Pair<Long, Long> getEstResultSizeNullable(Context ctx, String column)
419418
throws TileDBError {
420419
SWIGTYPE_p_unsigned_long_long size = tiledb.new_ullp();
421420
SWIGTYPE_p_unsigned_long_long validity = tiledb.new_ullp();
422421

423422
ctx.handleError(
424423
tiledb.tiledb_query_get_est_result_size_nullable(
425-
ctx.getCtxp(), queryp, attribute, size, validity));
424+
ctx.getCtxp(), queryp, column, size, validity));
426425

427-
return new Pair(tiledb.ullp_value(size).intValue(), tiledb.ullp_value(validity).intValue());
426+
return new Pair(tiledb.ullp_value(size).longValue(), tiledb.ullp_value(validity).longValue());
428427
}
429428

430429
/**
@@ -1647,8 +1646,8 @@ public short[] getValidityByteMap(String attribute) throws TileDBError {
16471646
* size estimate.
16481647
* @throws TileDBError
16491648
*/
1650-
public HashMap<String, Pair<Integer, Integer>> getResultEstimations() throws TileDBError {
1651-
HashMap<String, Pair<Integer, Integer>> estimations = new HashMap<>();
1649+
public HashMap<String, Pair<Long, Long>> getResultEstimations() throws TileDBError {
1650+
HashMap<String, Pair<Long, Long>> estimations = new HashMap<>();
16521651
String name;
16531652
try (ArraySchema schema = this.array.getSchema();
16541653
Domain domain = schema.getDomain(); ) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ private void arrayRead() throws Exception {
9393

9494
Array array = new Array(ctx, arrayURI);
9595

96-
// Calcuate maximum buffer sizes for the query results per attribute
97-
NativeArray subarray = new NativeArray(ctx, new int[] {1, 4, 1, 4}, Integer.class);
98-
HashMap<String, Pair<Long, Long>> max_sizes = array.maxBufferElements(subarray);
99-
10096
// Create query
10197
Query query = new Query(array, TILEDB_READ);
98+
HashMap<String, Pair<Long, Long>> max_sizes = query.getResultEstimations();
99+
102100
query.setLayout(TILEDB_ROW_MAJOR);
103101
query.setBuffer(
104102
"rows", new NativeArray(ctx, max_sizes.get("rows").getSecond().intValue(), Integer.class));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ private void arrayRead() throws Exception {
115115
Array my_dense_array = new Array(ctx, arrayURI);
116116
HashMap<String, Pair> dom = my_dense_array.nonEmptyDomain();
117117

118-
// Print maximum buffer elements for the query results per attribute
119118
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
120-
HashMap<String, Pair<Long, Long>> max_sizes = my_dense_array.maxBufferElements(subarray);
121119

122120
// Create query
123121
try (Query query = new Query(my_dense_array, TILEDB_READ)) {
124122
query.setLayout(TILEDB_ROW_MAJOR);
125123
query.setSubarray(subarray);
124+
HashMap<String, Pair<Long, Long>> max_sizes = new HashMap<>();
125+
max_sizes.put("a1", query.getEstResultSizeNullable(ctx, "a1"));
126+
max_sizes.put("a2", new Pair<>(0L, query.getEstResultSize(ctx, "a2")));
126127
query.setBufferNullable(
127128
"a1",
128129
new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class),

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,9 @@ public void denseArrayReadTest() throws Exception {
11571157
query.setBufferNullable("a1", a1Array, a1byteMap);
11581158
query.setBufferNullable("a2", a2Array, a2byteMap);
11591159

1160-
Pair<Integer, Integer> estimated = query.getEstResultSizeNullable(ctx, "a1");
1161-
Assert.assertEquals((int) estimated.getFirst(), 4);
1162-
Assert.assertEquals((int) estimated.getSecond(), 4);
1160+
Pair<Long, Long> estimated = query.getEstResultSizeNullable(ctx, "a1");
1161+
Assert.assertEquals((long) estimated.getFirst(), 4);
1162+
Assert.assertEquals((long) estimated.getSecond(), 4);
11631163

11641164
// Submit query
11651165
query.submit();
@@ -1289,11 +1289,10 @@ public void sparseArrayReadTest() throws Exception {
12891289
query.setBufferNullable("a1", a1Array, a1byteMap);
12901290
query.setBufferNullable("a2", a2Offsets, a2Array, a2byteMap);
12911291

1292-
Pair<Pair<Integer, Integer>, Integer> estimated =
1293-
query.getEstResultSizeVarNullable(ctx, "a2");
1294-
Assert.assertEquals(40, (int) estimated.getFirst().getFirst());
1295-
Assert.assertEquals(40, (int) estimated.getFirst().getFirst());
1296-
Assert.assertEquals(10, (int) estimated.getSecond());
1292+
Pair<Pair<Long, Long>, Long> estimated = query.getEstResultSizeVarNullable(ctx, "a2");
1293+
Assert.assertEquals(40, (long) estimated.getFirst().getFirst());
1294+
Assert.assertEquals(40, (long) estimated.getFirst().getFirst());
1295+
Assert.assertEquals(10, (long) estimated.getSecond());
12971296

12981297
// Submit query
12991298
query.submit();

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,7 @@ private void arrayRead() throws Exception {
160160
// "+e.getValue().getSecond()+")");
161161
// }
162162

163-
// Print maximum buffer elements for the query results per attribute
164163
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
165-
HashMap<String, Pair<Long, Long>> max_sizes = my_dense_array.maxBufferElements(subarray);
166-
167-
Assert.assertEquals(max_sizes.get("a1").getFirst(), (Long) 0l);
168-
Assert.assertEquals(max_sizes.get("a1").getSecond(), (Long) 16l);
169-
Assert.assertEquals(max_sizes.get("a2").getFirst(), (Long) 16l);
170-
Assert.assertEquals(max_sizes.get("a2").getSecond(), (Long) 56l);
171-
Assert.assertEquals(max_sizes.get("a3").getFirst(), (Long) 0l);
172-
Assert.assertEquals(max_sizes.get("a3").getSecond(), (Long) 32l);
173164

174165
// for (Map.Entry<String, Pair<Long,Long>> e : max_sizes.entrySet()){
175166
// System.out.println(e.getKey() + " ("+e.getValue().getFirst()+",
@@ -180,6 +171,8 @@ private void arrayRead() throws Exception {
180171
try (Query query = new Query(my_dense_array, TILEDB_READ)) {
181172
query.setLayout(TILEDB_GLOBAL_ORDER);
182173
query.setSubarray(subarray);
174+
HashMap<String, Pair<Long, Long>> max_sizes = query.getResultEstimations();
175+
183176
query.setBuffer(
184177
"a1", new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class));
185178
query.setBuffer(
@@ -251,13 +244,12 @@ private void arrayRead() throws Exception {
251244
private void arrayReadAsync() throws Exception {
252245
Array my_dense_array = new Array(ctx, arrayURI);
253246

254-
// Calcuate maximum buffer sizes for the query results per attribute
255247
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
256-
HashMap<String, Pair<Long, Long>> max_sizes = my_dense_array.maxBufferElements(subarray);
257248

258249
// Create query
259250
try (Query query = new Query(my_dense_array, TILEDB_READ)) {
260251
query.setLayout(TILEDB_GLOBAL_ORDER);
252+
HashMap<String, Pair<Long, Long>> max_sizes = query.getResultEstimations();
261253
query.setSubarray(subarray);
262254
query.setBuffer(
263255
"a1", new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class));

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private void arrayRead() throws Exception {
136136
// Print non-empty getDomain
137137
Array my_sparse_array = new Array(ctx, arrayURI);
138138
HashMap<String, Pair> dom = my_sparse_array.nonEmptyDomain();
139+
HashMap<String, Pair<Long, Long>> max_sizes = new HashMap<>();
139140

140141
Assert.assertEquals(dom.get("d1").getFirst(), 1l);
141142
Assert.assertEquals(dom.get("d1").getSecond(), 4l);
@@ -147,14 +148,7 @@ private void arrayRead() throws Exception {
147148
// e.getValue().getSecond() + ")");
148149
// }
149150

150-
// Print maximum buffer elements for the query results per attribute
151151
NativeArray subarray = new NativeArray(ctx, new long[] {1l, 4l, 1l, 4l}, Long.class);
152-
HashMap<String, Pair<Long, Long>> max_sizes = my_sparse_array.maxBufferElements(subarray);
153-
154-
Assert.assertEquals(max_sizes.get("a1").getFirst(), (Long) 0l);
155-
Assert.assertEquals(max_sizes.get("a1").getSecond(), (Long) 8l);
156-
Assert.assertEquals(max_sizes.get("a2").getFirst(), (Long) 8l);
157-
Assert.assertEquals(max_sizes.get("a2").getSecond(), (Long) 20l);
158152

159153
// for (Map.Entry<String, Pair<Long,Long>> e : max_sizes.entrySet()){
160154
// System.out.println(e.getKey() + " ("+e.getValue().getFirst()+",
@@ -165,6 +159,11 @@ private void arrayRead() throws Exception {
165159
try (Query query = new Query(my_sparse_array, TILEDB_READ)) {
166160
query.setLayout(TILEDB_GLOBAL_ORDER);
167161
query.setSubarray(subarray);
162+
max_sizes.put("d1", new Pair<>(0L, query.getEstResultSize(ctx, "d1")));
163+
max_sizes.put("d2", new Pair<>(0L, query.getEstResultSize(ctx, "d2")));
164+
max_sizes.put("a1", new Pair<>(0L, query.getEstResultSize(ctx, "a1")));
165+
max_sizes.put("a2", query.getEstResultSizeVar(ctx, "a2"));
166+
max_sizes.put("a3", query.getEstResultSizeVar(ctx, "a2"));
168167

169168
query.setBuffer(
170169
"d1", new NativeArray(ctx, max_sizes.get("d1").getSecond().intValue(), Long.class));

0 commit comments

Comments
 (0)