Skip to content

fixing a bug when reading nullable attributes with nio buffers #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2023
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'io.tiledb'
version '0.17.0-SNAPSHOT'
version '0.17.2-SNAPSHOT'

repositories {
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion src/main/c/custom/tiledb_custom.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ extern "C" {
}
arg4 = *(uint8_t **)&jarg4;
arg5 = *(uint64_t **)&jarg5;
result = (int32_t)tiledb_query_set_validity_buffer(arg1,arg2,(char const *)arg3,arg4,arg5);
result = (int32_t)tiledb_query_set_validity_buffer(arg1,arg2,(char const *)arg3,(uint8_t *)buffer,arg5);
jresult = (jint)result;
if (arg3) jenv->ReleaseStringUTFChars(jarg3, (const char *)arg3);
return jresult;
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/io/tiledb/java/api/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,13 @@ public synchronized Query setValidityBuffer(String attr, NativeArray bytemap) th
uint64_tArray buffer_validity_bytemap_size = new uint64_tArray(1);
buffer_validity_bytemap_size.setitem(0, BigInteger.valueOf(bytemap.getNBytes()));

validityByteMaps_.put(attr, bytemap);
if (validityByteMaps_.containsKey(attr)) {
NativeArray byteMap = validityByteMaps_.get(attr);
if (byteMap != null) byteMap.close();
validityByteMaps_.put(attr, bytemap);
} else {
validityByteMaps_.put(attr, bytemap);
}
validityByteMapSizes_.put(attr, buffer_validity_bytemap_size);

ctx.handleError(
Expand All @@ -568,7 +574,7 @@ public synchronized Query setValidityBuffer(String attr, NativeArray bytemap) th
}

/**
* Sets a validity byte-map for a fixed-sized attribute.
* Sets a validity byte-map for an attribute.
*
* @param attr The attribute name.
* @param buffer NativeBuffer to be used for the attribute values.
Expand All @@ -594,6 +600,12 @@ public synchronized Query setValidityBuffer(String attr, ByteBuffer buffer) thro

buffer_validity_bytemap_size.setitem(0, BigInteger.valueOf(buffer.capacity()));

// Close previous buffers if they exist for this attribute
if (validityByteMaps_.containsKey(attr)) {
NativeArray prevBuff = validityByteMaps_.get(attr);
prevBuff.close();
}

validityByteMapsByteBuffers_.put(attr, buffer);
validityByteMapSizes_.put(attr, buffer_validity_bytemap_size);

Expand Down Expand Up @@ -1006,14 +1018,29 @@ public synchronized void resetBuffers() {
if (buffer.getSecond() != null) buffer.getSecond().clear();
}

for (NativeArray buffer : validityByteMaps_.values()) {
if (buffer != null) buffer.close();
}

for (ByteBuffer buffer : validityByteMapsByteBuffers_.values()) {
if (buffer != null) buffer.clear();
}

byteBuffers_.clear();
buffers_.clear();
validityByteMapsByteBuffers_.clear();
validityByteMaps_.clear();

for (Pair<uint64_tArray, uint64_tArray> size_pair : buffer_sizes_.values()) {
if (size_pair.getFirst() != null) size_pair.getFirst().delete();
if (size_pair.getSecond() != null) size_pair.getSecond().delete();
}
buffer_sizes_.clear();

for (uint64_tArray size : validityByteMapSizes_.values()) {
if (size != null) size.delete();
}
validityByteMapSizes_.clear();
}

public synchronized Query resetBufferSizes(Long val) {
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/tiledb/java/api/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ public void denseArrayReadTest() throws Exception {
}
}

public void denseArrayNIOReadTest() throws Exception { // TODO
@Test
public void denseArrayNIOReadTest() throws Exception {
denseArrayCreateNullableAttrs(true);
denseArrayWrite();

Expand Down Expand Up @@ -1363,7 +1364,8 @@ public void sparseArrayReadTest() throws Exception {
}
}

public void sparseArrayNIOReadTest() throws Exception { // TODO
@Test
public void sparseArrayNIOReadTest() throws Exception {
sparseArrayCreateNullableAttrs(true);
sparseArrayWrite();

Expand Down