Skip to content

Commit b1f930f

Browse files
committed
added getNullable method
1 parent 9382a44 commit b1f930f

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,40 @@ public Pair<Object, Pair<Integer, Boolean>> getFillValueNullable() throws TileDB
459459
}
460460
}
461461

462-
public int setNullable(boolean isNullable) throws TileDBError {
462+
/**
463+
* * Sets the nullability of an attribute.
464+
*
465+
* @param isNullable true if the attribute is nullable, false otherwise
466+
* @throws TileDBError
467+
*/
468+
public void setNullable(boolean isNullable) throws TileDBError {
463469

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

466472
try {
467-
int res;
468473
ctx.handleError(
469-
res = tiledb.tiledb_attribute_set_nullable(ctx.getCtxp(), this.attributep, nullable));
470-
return res;
474+
tiledb.tiledb_attribute_set_nullable(ctx.getCtxp(), this.attributep, nullable));
475+
} catch (TileDBError err) {
476+
throw err;
477+
}
478+
}
479+
480+
/**
481+
* * Gets the nullability of an attribute.
482+
*
483+
* @return true if the attribute is nullable, false otherwise
484+
* @throws TileDBError
485+
*/
486+
public boolean getNullable() throws TileDBError {
487+
try {
488+
489+
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_UINT8);
490+
SWIGTYPE_p_unsigned_char nullable = arr.getUint8_tArray().cast();
491+
492+
ctx.handleError(
493+
tiledb.tiledb_attribute_get_nullable(ctx.getCtxp(), this.attributep, nullable));
494+
495+
return ((short) arr.getItem(0) == 1);
471496
} catch (TileDBError err) {
472497
throw err;
473498
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public void arrayWrite() throws Exception {
106106
public void arrayReadTest() throws Exception {
107107
// Create array and query
108108
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
109+
ArraySchema schema = array.getSchema();
109110
Query query = new Query(array, TILEDB_READ)) {
110111

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

135+
try (Attribute attr1 = schema.getAttribute(0);
136+
Attribute attr2 = schema.getAttribute(1)) {
137+
Assert.assertFalse(attr1.getNullable());
138+
Assert.assertFalse(attr2.getNullable());
139+
}
140+
134141
HashMap<String, Pair<Long, Long>> resultElements = query.resultBufferElements();
135142

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

10981105
// Create array and query
10991106
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
1107+
ArraySchema schema = array.getSchema();
11001108
Query query = new Query(array, TILEDB_READ)) {
11011109

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

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

1132+
try (Attribute a1 = schema.getAttribute(0);
1133+
Attribute a2 = schema.getAttribute(1)) {
1134+
Assert.assertTrue(a1.getNullable());
1135+
Assert.assertTrue(a2.getNullable());
1136+
}
1137+
11241138
Assert.assertEquals(Long.valueOf(4), resultElements.get("a1").getSecond());
11251139
Assert.assertEquals(Long.valueOf(4), resultElements.get("a2").getSecond());
11261140

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

11491163
// Create array and query
11501164
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
1165+
ArraySchema schema = array.getSchema();
11511166
Query query = new Query(array, TILEDB_READ)) {
11521167

11531168
// Fetch all cells
@@ -1189,6 +1204,12 @@ public void denseArrayNIOReadTest() throws Exception {
11891204
dimIdx++;
11901205
}
11911206

1207+
try (Attribute attr1 = schema.getAttribute(0);
1208+
Attribute attr2 = schema.getAttribute(1)) {
1209+
Assert.assertTrue(attr1.getNullable());
1210+
Assert.assertTrue(attr2.getNullable());
1211+
}
1212+
11921213
Assert.assertArrayEquals(new int[] {1, 1, 2, 2}, dim1);
11931214
Assert.assertArrayEquals(new int[] {1, 2, 1, 2}, dim2);
11941215
Assert.assertArrayEquals(new byte[] {'a', 'b', 'c', 'd'}, a1);
@@ -1217,6 +1238,7 @@ public void sparseArrayReadTest() throws Exception {
12171238

12181239
// Create array and query
12191240
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
1241+
ArraySchema schema = array.getSchema();
12201242
Query query = new Query(array, TILEDB_READ)) {
12211243

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

1264+
try (Attribute attr1 = schema.getAttribute(0);
1265+
Attribute attr2 = schema.getAttribute(1)) {
1266+
Assert.assertTrue(attr1.getNullable());
1267+
Assert.assertTrue(attr2.getNullable());
1268+
}
1269+
12421270
Assert.assertEquals(Long.valueOf(5), resultElements.get("a1").getSecond());
12431271
Assert.assertEquals(Long.valueOf(10), resultElements.get("a2").getSecond());
12441272

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

12611289
// Create array and query
12621290
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
1291+
ArraySchema schema = array.getSchema();
12631292
Query query = new Query(array, TILEDB_READ)) {
12641293

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

1308+
try (Attribute attr1 = schema.getAttribute(0);
1309+
Attribute attr2 = schema.getAttribute(1)) {
1310+
Assert.assertTrue(attr1.getNullable());
1311+
Assert.assertTrue(attr2.getNullable());
1312+
}
1313+
12791314
int[] a1Values = new int[5];
12801315
byte[] a1ByteMapValues = new byte[5];
12811316

0 commit comments

Comments
 (0)