Skip to content
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
17 changes: 12 additions & 5 deletions src/main/java/io/tiledb/java/api/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public QueryStatus getQueryStatus() throws TileDBError {
*/
public QueryStatus submit() throws TileDBError {
ctx.handleError(tiledb.tiledb_query_submit(ctx.getCtxp(), queryp));

// Set the actual number of bytes received to each ByteBuffer
for (String attribute : byteBuffers_.keySet()) {
int nbytes = this.buffer_sizes_.get(attribute).getSecond().getitem(0).intValue();
this.byteBuffers_.get(attribute).limit(nbytes);
}

return getQueryStatus();
}

Expand Down Expand Up @@ -502,11 +509,6 @@ public synchronized ByteBuffer setBuffer(String attr, long bufferElements) throw

ByteBuffer buffer = ByteBuffer.allocateDirect(size);

// Set the byte order to the native system's native order
buffer.order(ByteOrder.nativeOrder());

this.byteBuffers_.put(attr, buffer);

this.setBuffer(attr, buffer);

return buffer;
Expand Down Expand Up @@ -537,9 +539,14 @@ public synchronized ByteBuffer setBuffer(String attr, ByteBuffer buffer) throws

this.byteBuffers_.put(attr, buffer);

uint64_tArray offsets_array_size = new uint64_tArray(1);
uint64_tArray values_array_size = new uint64_tArray(1);

offsets_array_size.setitem(0, BigInteger.valueOf(0));
values_array_size.setitem(0, BigInteger.valueOf(buffer.capacity()));

buffer_sizes_.put(attr, new Pair<>(offsets_array_size, values_array_size));

ctx.handleError(
tiledb.tiledb_query_set_buffer_nio(
ctx.getCtxp(), queryp, attr, buffer, values_array_size.cast()));
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/io/tiledb/java/api/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,44 @@ public void queryTestNIOReadArray() throws Exception {
new int[] {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, d2_result);
}

@Test
public void queryTestNIOReadArrayArbitrarySize() throws Exception {
Array array = new Array(ctx, arrayURI, TILEDB_READ);

Query query = new Query(array, TILEDB_READ);

int bufferSize = 4;

ByteBuffer d1 = query.setBuffer("rows", ByteBuffer.allocateDirect(10));
ByteBuffer d2 = query.setBuffer("cols", ByteBuffer.allocateDirect(10));

query.addRange(0, 1, 4);
query.addRange(1, 1, 4);

query.setLayout(TILEDB_ROW_MAJOR);

int[] d1_result = new int[16];
int[] d2_result = new int[16];
int idx = 0;

while (query.getQueryStatus() != QueryStatus.TILEDB_COMPLETED) {
query.submit();

while (d1.hasRemaining() && d2.hasRemaining()) {
d1_result[idx] = d1.getInt();
d2_result[idx] = d2.getInt();
idx++;
}
d1.clear();
d2.clear();
}

Assert.assertArrayEquals(
new int[] {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}, d1_result);
Assert.assertArrayEquals(
new int[] {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, d2_result);
}

@Test
public void arrayReadTest() throws Exception {
// Create array and query
Expand Down