Skip to content

Commit

Permalink
UINT32 mods in support of schema-printer PR #342 (#343)
Browse files Browse the repository at this point in the history
* uint32 mods in support of schema-printer PR #342

* unit-test cases for UINT32 attribute get/set fill value

* code-review feedback
  • Loading branch information
johnkerl authored Jan 7, 2022
1 parent 9643ec1 commit 7c9af4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions inst/tinytest/test_attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ val <- arr[]
expect_equal(val, array(rep(42, 4)))
expect_equal(tiledb_attribute_get_fill_value(attr), 42)

dom <- tiledb_domain(dims = tiledb_dim("rows", c(1L, 4L), 4L, "UINT32"))
attr <- tiledb_attr("a", type = "UINT32")
tiledb_attribute_set_fill_value(attr, 42L)
sch <- tiledb_array_schema(dom, attr)
uri <- tempfile()
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
tiledb_array_create(uri, sch)
arr <- tiledb_dense(uri)
val <- arr[]
## when fill value has been set, expect value
expect_equal(val, array(rep(42, 4)))
expect_equal(tiledb_attribute_get_fill_value(attr), 42)

attr <- tiledb_attr("b", type = "CHAR", ncells = NA)
tiledb_attribute_set_fill_value(attr, "abc")
sch <- tiledb_array_schema(dom, attr)
Expand Down
12 changes: 11 additions & 1 deletion src/libtiledb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ SEXP libtiledb_dim_get_tile_extent(XPtr<tiledb::Dimension> dim) {
return IntegerVector({static_cast<int32_t>(t),});
}
default:
Rcpp::stop("invalid tiledb_dim domain type");
Rcpp::stop("invalid tiledb_dim domain type (%d)", dim_type);
}
}

Expand Down Expand Up @@ -1298,6 +1298,9 @@ XPtr<tiledb::Attribute> libtiledb_attribute(XPtr<tiledb::Context> ctx,
if (attr_dtype == TILEDB_INT32) {
using DType = tiledb::impl::tiledb_to_type<TILEDB_INT32>::type;
attr = XPtr<tiledb::Attribute>(new tiledb::Attribute(tiledb::Attribute::create<DType>(*ctx.get(), name)), false);
} else if (attr_dtype == TILEDB_UINT32) {
using DType = tiledb::impl::tiledb_to_type<TILEDB_UINT32>::type;
attr = XPtr<tiledb::Attribute>(new tiledb::Attribute(tiledb::Attribute::create<DType>(*ctx.get(), name)), false);
} else if (attr_dtype == TILEDB_FLOAT64) {
using DType = tiledb::impl::tiledb_to_type<TILEDB_FLOAT64>::type;
attr = XPtr<tiledb::Attribute>(new tiledb::Attribute(tiledb::Attribute::create<DType>(*ctx.get(), name)), false);
Expand Down Expand Up @@ -1423,6 +1426,10 @@ void libtiledb_attribute_set_fill_value(XPtr<tiledb::Attribute> attr, SEXP val)
IntegerVector v(val);
if (v.size() > 1) Rcpp::stop("Setting fill values only supports scalar values for now.");
attr->set_fill_value((void*) &(v[0]), static_cast<uint64_t>(sizeof(int32_t)));
} else if (dtype == TILEDB_UINT32) {
IntegerVector v(val);
if (v.size() > 1) Rcpp::stop("Setting fill values only supports scalar values for now.");
attr->set_fill_value((void*) &(v[0]), static_cast<uint64_t>(sizeof(uint32_t)));
} else if (dtype == TILEDB_FLOAT64) {
NumericVector v(val);
if (v.size() > 1) Rcpp::stop("Setting fill values only supports scalar values for now.");
Expand Down Expand Up @@ -1451,6 +1458,9 @@ SEXP libtiledb_attribute_get_fill_value(XPtr<tiledb::Attribute> attr) {
if (dtype == TILEDB_INT32) {
int32_t v = *(const int32_t*)valptr;
return wrap(v);
} else if (dtype == TILEDB_UINT32) {
uint32_t v = *(const uint32_t*)valptr;
return wrap(v);
} else if (dtype == TILEDB_FLOAT64) {
double v = *(const double*)valptr;
return wrap(v);
Expand Down

0 comments on commit 7c9af4c

Please sign in to comment.