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
78 changes: 78 additions & 0 deletions src/main/java/io/tiledb/java/api/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ public FilterList getFilterList() throws TileDBError {
return filterlist;
}

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

/**
* Sets the default fill value for the input attribute. This value will be used for the input
* attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell (in
* either dense or sparse array) when values on the input attribute are missing (e.g., if the user
* writes a subset of the attributes in a write operation).
*
* <p>Applicable to var-sized attributes.
*
* @param value The fill value
* @throws TileDBError
*/
public void setFillValue(Object value) throws TileDBError {
NativeArray array = new NativeArray(ctx, this.type.getNativeSize(), this.type.javaClass());
array.setItem(0, value);

try {
ctx.handleError(
tiledb.tiledb_attribute_set_fill_value(
ctx.getCtxp(),
attributep,
array.toVoidPointer(),
BigInteger.valueOf(this.type.getNativeSize())));
} catch (TileDBError err) {
throw err;
}
}

/**
* Gets the default fill value for the input attribute. This value will be used for the input
* attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell (in
* either dense or sparse array) when values on the input attribute are missing (e.g., if the user
* writes a subset of the attributes in a write operation).
*
* <p>Applicable to both fixed-sized and var-sized attributes.
*
* @return A pair with the fill value and its size
* @throws TileDBError
*/
public Pair<Object, Long> getFillValue() throws TileDBError {

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

/**
* Sets the default fill value for the input, nullable attribute. This value will be used for the
* input attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell
* (in either dense or sparse array) when values on the input attribute are missing (e.g., if the
* user writes a subset of the attributes in a write operation).
*
* @param value The fill value to set.
* @param valid The validity fill value, zero for a null value and non-zero for a valid attribute.
* @throws TileDBError
*/
public void setFillValueNullable(Object value, boolean valid) throws TileDBError {

NativeArray valueArray = new NativeArray(ctx, this.type.getNativeSize(), this.type.javaClass());
valueArray.setItem(0, value);

try {
ctx.handleError(
tiledb.tiledb_attribute_set_fill_value_nullable(
ctx.getCtxp(),
attributep,
valueArray.toVoidPointer(),
BigInteger.valueOf(this.type.getNativeSize()),
valid ? (short) 1 : (short) 0));
} catch (TileDBError err) {
throw err;
}
}

/**
* Gets the default fill value for the input, nullable attribute. This value will be used for the
* input attribute whenever querying (1) an empty cell in a dense array, or (2) a non-empty cell
Expand Down
54 changes: 12 additions & 42 deletions src/test/java/io/tiledb/java/api/AttributeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,31 @@ public void testAttributeSetFillValue() throws Exception {
try (Context ctx = new Context();
Attribute a = new Attribute(ctx, "a2", Datatype.TILEDB_INT32)) {

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT32);

arr.setItem(0, 5);

a.setFillValue(arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()));
a.setFillValue(5);

Assert.assertEquals(5, a.getFillValue().getFirst());
Assert.assertEquals(
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
a.getFillValue().getSecond());
BigInteger.valueOf(a.getType().getNativeSize()), a.getFillValue().getSecond());
}

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

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT64);

arr.setItem(0, 5L);

a.setFillValue(arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()));
a.setFillValue(5L);

Assert.assertEquals(5L, a.getFillValue().getFirst());
Assert.assertEquals(
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
a.getFillValue().getSecond());
BigInteger.valueOf(a.getType().getNativeSize()), a.getFillValue().getSecond());
}

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

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_CHAR);

arr.setItem(0, "c");

a.setFillValue(arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()));
a.setFillValue((byte) 'c');

Assert.assertEquals((byte) 'c', a.getFillValue().getFirst());
Assert.assertEquals(
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
a.getFillValue().getSecond());
BigInteger.valueOf(a.getType().getNativeSize()), a.getFillValue().getSecond());
}
}

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

a.setNullable(true);

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT32);

arr.setItem(0, 5);

a.setFillValueNullable(
arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()), true);
a.setFillValueNullable(5, true);

Assert.assertEquals(5, a.getFillValueNullable().getFirst());
Assert.assertEquals(
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
BigInteger.valueOf(a.getType().getNativeSize()),
a.getFillValueNullable().getSecond().getFirst());

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

a.setNullable(true);

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_INT64);

arr.setItem(0, 5L);

a.setFillValueNullable(
arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()), false);
a.setFillValueNullable(5L, false);

Assert.assertEquals(5L, a.getFillValueNullable().getFirst());
Assert.assertEquals(
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
BigInteger.valueOf(a.getType().getNativeSize()),
a.getFillValueNullable().getSecond().getFirst());

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

a.setNullable(true);

NativeArray arr = new NativeArray(ctx, 1, Datatype.TILEDB_CHAR);

arr.setItem(0, "c");

a.setFillValueNullable(
arr, BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()), false);
a.setFillValueNullable((byte) 'c', false);

Assert.assertEquals((byte) 'c', a.getFillValueNullable().getFirst());
Assert.assertEquals(
BigInteger.valueOf(arr.getNativeTypeSize() * arr.getSize()),
BigInteger.valueOf(a.getType().getNativeSize()),
a.getFillValueNullable().getSecond().getFirst());

Assert.assertEquals(false, a.getFillValueNullable().getSecond().getSecond());
Expand Down