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
33 changes: 29 additions & 4 deletions src/main/java/io/tiledb/java/api/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,40 @@ public Pair<Object, Pair<Integer, Boolean>> getFillValueNullable() throws TileDB
}
}

public int setNullable(boolean isNullable) throws TileDBError {
/**
* * Sets the nullability of an attribute.
*
* @param isNullable true if the attribute is nullable, false otherwise
* @throws TileDBError
*/
public void setNullable(boolean isNullable) throws TileDBError {

short nullable = isNullable ? (short) 1 : (short) 0;

try {
int res;
ctx.handleError(
res = tiledb.tiledb_attribute_set_nullable(ctx.getCtxp(), this.attributep, nullable));
return res;
tiledb.tiledb_attribute_set_nullable(ctx.getCtxp(), this.attributep, nullable));
} catch (TileDBError err) {
throw err;
}
}

/**
* * Gets the nullability of an attribute.
*
* @return true if the attribute is nullable, false otherwise
* @throws TileDBError
*/
public boolean getNullable() throws TileDBError {
try {

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_UINT8);
SWIGTYPE_p_unsigned_char nullable = arr.getUint8_tArray().cast();

ctx.handleError(
tiledb.tiledb_attribute_get_nullable(ctx.getCtxp(), this.attributep, nullable));

return ((short) arr.getItem(0) == 1);
} catch (TileDBError err) {
throw err;
}
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/io/tiledb/java/api/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void arrayWrite() throws Exception {
public void arrayReadTest() throws Exception {
// Create array and query
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
ArraySchema schema = array.getSchema();
Query query = new Query(array, TILEDB_READ)) {

// Slice only rows 1, 2 and cols 2, 3, 4
Expand All @@ -131,6 +132,12 @@ public void arrayReadTest() throws Exception {
// Submit query
query.submit();

try (Attribute attr1 = schema.getAttribute(0);
Attribute attr2 = schema.getAttribute(1)) {
Assert.assertFalse(attr1.getNullable());
Assert.assertFalse(attr2.getNullable());
}

HashMap<String, Pair<Long, Long>> resultElements = query.resultBufferElements();

Assert.assertEquals(Long.valueOf(3), resultElements.get("a1").getSecond());
Expand Down Expand Up @@ -1097,6 +1104,7 @@ public void denseArrayReadTest() throws Exception {

// Create array and query
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
ArraySchema schema = array.getSchema();
Query query = new Query(array, TILEDB_READ)) {

// Fetch all cells
Expand All @@ -1121,6 +1129,12 @@ public void denseArrayReadTest() throws Exception {

HashMap<String, Pair<Long, Long>> resultElements = query.resultBufferElements();

try (Attribute a1 = schema.getAttribute(0);
Attribute a2 = schema.getAttribute(1)) {
Assert.assertTrue(a1.getNullable());
Assert.assertTrue(a2.getNullable());
}

Assert.assertEquals(Long.valueOf(4), resultElements.get("a1").getSecond());
Assert.assertEquals(Long.valueOf(4), resultElements.get("a2").getSecond());

Expand Down Expand Up @@ -1148,6 +1162,7 @@ public void denseArrayNIOReadTest() throws Exception {

// Create array and query
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
ArraySchema schema = array.getSchema();
Query query = new Query(array, TILEDB_READ)) {

// Fetch all cells
Expand Down Expand Up @@ -1189,6 +1204,12 @@ public void denseArrayNIOReadTest() throws Exception {
dimIdx++;
}

try (Attribute attr1 = schema.getAttribute(0);
Attribute attr2 = schema.getAttribute(1)) {
Assert.assertTrue(attr1.getNullable());
Assert.assertTrue(attr2.getNullable());
}

Assert.assertArrayEquals(new int[] {1, 1, 2, 2}, dim1);
Assert.assertArrayEquals(new int[] {1, 2, 1, 2}, dim2);
Assert.assertArrayEquals(new byte[] {'a', 'b', 'c', 'd'}, a1);
Expand Down Expand Up @@ -1217,6 +1238,7 @@ public void sparseArrayReadTest() throws Exception {

// Create array and query
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
ArraySchema schema = array.getSchema();
Query query = new Query(array, TILEDB_READ)) {

query.setLayout(TILEDB_ROW_MAJOR);
Expand All @@ -1239,6 +1261,12 @@ public void sparseArrayReadTest() throws Exception {
byte[] a2 = (byte[]) query.getBuffer("a2");
long[] a2Off = query.getVarBuffer("a2");

try (Attribute attr1 = schema.getAttribute(0);
Attribute attr2 = schema.getAttribute(1)) {
Assert.assertTrue(attr1.getNullable());
Assert.assertTrue(attr2.getNullable());
}

Assert.assertEquals(Long.valueOf(5), resultElements.get("a1").getSecond());
Assert.assertEquals(Long.valueOf(10), resultElements.get("a2").getSecond());

Expand All @@ -1260,6 +1288,7 @@ public void sparseArrayNIOReadTest() throws Exception {

// Create array and query
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
ArraySchema schema = array.getSchema();
Query query = new Query(array, TILEDB_READ)) {

query.setLayout(TILEDB_ROW_MAJOR);
Expand All @@ -1276,6 +1305,12 @@ public void sparseArrayNIOReadTest() throws Exception {
// Submit query
query.submit();

try (Attribute attr1 = schema.getAttribute(0);
Attribute attr2 = schema.getAttribute(1)) {
Assert.assertTrue(attr1.getNullable());
Assert.assertTrue(attr2.getNullable());
}

int[] a1Values = new int[5];
byte[] a1ByteMapValues = new byte[5];

Expand Down