Skip to content

Commit 9df364f

Browse files
committed
fill value API additions
1 parent 521ac3a commit 9df364f

File tree

2 files changed

+90
-42
lines changed

2 files changed

+90
-42
lines changed

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ public FilterList getFilterList() throws TileDBError {
261261
return filterlist;
262262
}
263263

264+
/**
265+
* Sets the default fill value for the input attribute. This value will be used for the input
266+
* attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell (in
267+
* either dense or sparse array) when values on the input attribute are missing (e.g., if the user
268+
* writes a subset of the attributes in a write operation).
269+
*
270+
* <p>Applicable to var-sized attributes.
271+
*
272+
* @param value The fill value
273+
* @param size The fill value size
274+
* @throws TileDBError
275+
*/
264276
public void setFillValue(NativeArray value, BigInteger size) throws TileDBError {
265277
try {
266278
ctx.handleError(
@@ -271,6 +283,44 @@ public void setFillValue(NativeArray value, BigInteger size) throws TileDBError
271283
}
272284
}
273285

286+
/**
287+
* Sets the default fill value for the input attribute. This value will be used for the input
288+
* attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell (in
289+
* either dense or sparse array) when values on the input attribute are missing (e.g., if the user
290+
* writes a subset of the attributes in a write operation).
291+
*
292+
* <p>Applicable to var-sized attributes.
293+
*
294+
* @param value The fill value
295+
* @throws TileDBError
296+
*/
297+
public void setFillValue(Object value) throws TileDBError {
298+
NativeArray array = new NativeArray(ctx, this.type.getNativeSize(), this.type.javaClass());
299+
array.setItem(0, value);
300+
301+
try {
302+
ctx.handleError(
303+
tiledb.tiledb_attribute_set_fill_value(
304+
ctx.getCtxp(),
305+
attributep,
306+
array.toVoidPointer(),
307+
BigInteger.valueOf(this.type.getNativeSize())));
308+
} catch (TileDBError err) {
309+
throw err;
310+
}
311+
}
312+
313+
/**
314+
* Gets the default fill value for the input attribute. This value will be used for the input
315+
* attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell (in
316+
* either dense or sparse array) when values on the input attribute are missing (e.g., if the user
317+
* writes a subset of the attributes in a write operation).
318+
*
319+
* <p>Applicable to both fixed-sized and var-sized attributes.
320+
*
321+
* @return A pair with the fill value and its size
322+
* @throws TileDBError
323+
*/
274324
public Pair<Object, Long> getFillValue() throws TileDBError {
275325

276326
try (NativeArray value = new NativeArray(ctx, this.type.getNativeSize(), this.type)) {
@@ -317,6 +367,34 @@ public void setFillValueNullable(NativeArray value, BigInteger size, boolean val
317367
}
318368
}
319369

370+
/**
371+
* Sets the default fill value for the input, nullable attribute. This value will be used for the
372+
* input attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell
373+
* (in either dense or sparse array) when values on the input attribute are missing (e.g., if the
374+
* user writes a subset of the attributes in a write operation).
375+
*
376+
* @param value The fill value to set.
377+
* @param valid The validity fill value, zero for a null value and non-zero for a valid attribute.
378+
* @throws TileDBError
379+
*/
380+
public void setFillValueNullable(Object value, boolean valid) throws TileDBError {
381+
382+
NativeArray valueArray = new NativeArray(ctx, this.type.getNativeSize(), this.type.javaClass());
383+
valueArray.setItem(0, value);
384+
385+
try {
386+
ctx.handleError(
387+
tiledb.tiledb_attribute_set_fill_value_nullable(
388+
ctx.getCtxp(),
389+
attributep,
390+
valueArray.toVoidPointer(),
391+
BigInteger.valueOf(this.type.getNativeSize()),
392+
valid ? (short) 1 : (short) 0));
393+
} catch (TileDBError err) {
394+
throw err;
395+
}
396+
}
397+
320398
/**
321399
* Gets the default fill value for the input, nullable attribute. This value will be used for the
322400
* input attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell

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

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,31 @@ public void testAttributeSetFillValue() throws Exception {
6666
try (Context ctx = new Context();
6767
Attribute a = new Attribute(ctx, "a2", Datatype.TILEDB_INT32)) {
6868

69-
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT32);
70-
71-
arr.setItem(0, 5);
72-
73-
a.setFillValue(arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()));
69+
a.setFillValue(5);
7470

7571
Assert.assertEquals(5, a.getFillValue().getFirst());
7672
Assert.assertEquals(
77-
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
78-
a.getFillValue().getSecond());
73+
BigInteger.valueOf(a.getType().getNativeSize()), a.getFillValue().getSecond());
7974
}
8075

8176
try (Context ctx = new Context();
8277
Attribute a = new Attribute(ctx, "a2", Datatype.TILEDB_INT64)) {
8378

84-
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT64);
85-
86-
arr.setItem(0, 5L);
87-
88-
a.setFillValue(arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()));
79+
a.setFillValue(5L);
8980

9081
Assert.assertEquals(5L, a.getFillValue().getFirst());
9182
Assert.assertEquals(
92-
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
93-
a.getFillValue().getSecond());
83+
BigInteger.valueOf(a.getType().getNativeSize()), a.getFillValue().getSecond());
9484
}
9585

9686
try (Context ctx = new Context();
9787
Attribute a = new Attribute(ctx, "a2", Datatype.TILEDB_CHAR)) {
9888

99-
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_CHAR);
100-
101-
arr.setItem(0, "c");
102-
103-
a.setFillValue(arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()));
89+
a.setFillValue((byte) 'c');
10490

10591
Assert.assertEquals((byte) 'c', a.getFillValue().getFirst());
10692
Assert.assertEquals(
107-
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
108-
a.getFillValue().getSecond());
93+
BigInteger.valueOf(a.getType().getNativeSize()), a.getFillValue().getSecond());
10994
}
11095
}
11196

@@ -116,16 +101,11 @@ public void testAttributeSetFillValueNullable() throws Exception {
116101

117102
a.setNullable(true);
118103

119-
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT32);
120-
121-
arr.setItem(0, 5);
122-
123-
a.setFillValueNullable(
124-
arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()), true);
104+
a.setFillValueNullable(5, true);
125105

126106
Assert.assertEquals(5, a.getFillValueNullable().getFirst());
127107
Assert.assertEquals(
128-
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
108+
BigInteger.valueOf(a.getType().getNativeSize()),
129109
a.getFillValueNullable().getSecond().getFirst());
130110

131111
Assert.assertEquals(true, a.getFillValueNullable().getSecond().getSecond());
@@ -136,16 +116,11 @@ public void testAttributeSetFillValueNullable() throws Exception {
136116

137117
a.setNullable(true);
138118

139-
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT64);
140-
141-
arr.setItem(0, 5L);
142-
143-
a.setFillValueNullable(
144-
arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()), false);
119+
a.setFillValueNullable(5L, false);
145120

146121
Assert.assertEquals(5L, a.getFillValueNullable().getFirst());
147122
Assert.assertEquals(
148-
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
123+
BigInteger.valueOf(a.getType().getNativeSize()),
149124
a.getFillValueNullable().getSecond().getFirst());
150125

151126
Assert.assertEquals(false, a.getFillValueNullable().getSecond().getSecond());
@@ -156,16 +131,11 @@ public void testAttributeSetFillValueNullable() throws Exception {
156131

157132
a.setNullable(true);
158133

159-
NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_CHAR);
160-
161-
arr.setItem(0, "c");
162-
163-
a.setFillValueNullable(
164-
arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()), false);
134+
a.setFillValueNullable((byte) 'c', false);
165135

166136
Assert.assertEquals((byte) 'c', a.getFillValueNullable().getFirst());
167137
Assert.assertEquals(
168-
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
138+
BigInteger.valueOf(a.getType().getNativeSize()),
169139
a.getFillValueNullable().getSecond().getFirst());
170140

171141
Assert.assertEquals(false, a.getFillValueNullable().getSecond().getSecond());

0 commit comments

Comments
 (0)