Skip to content

Commit

Permalink
[c++] Resize for variant-indexed DataFrame [WIP] [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Aug 30, 2024
1 parent 68d9d3e commit 1bf7b10
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
37 changes: 37 additions & 0 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,43 @@ void SOMAArray::resize(const std::vector<int64_t>& newshape) {
schema_evolution.array_evolve(uri_);
}

void SOMAArray::resize_soma_joinid_if_dim(
const std::vector<int64_t>& newshape) {
if (mq_->query_type() != TILEDB_WRITE) {
throw TileDBSOMAError(
"[SOMAArray::resize] array must be opened in write mode");
}

ArraySchema schema = arr_->schema();
Domain domain = schema.domain();
unsigned ndim = domain.ndim();
if (newshape.size() != 1) {
throw TileDBSOMAError(fmt::format(
"[SOMAArray::resize]: newshape has dimension count {}; needed 1",
newshape.size(),
ndim));
}

auto tctx = ctx_->tiledb_ctx();
CurrentDomain old_current_domain = ArraySchemaExperimental::current_domain(
*tctx, schema);
NDRectangle ndrect = old_current_domain.ndrectangle();

CurrentDomain new_current_domain(*tctx);
ArraySchemaEvolution schema_evolution(*tctx);

for (unsigned i = 0; i < ndim; i++) {
if (domain.dimension(i).name() == "soma_joinid") {
ndrect.set_range<int64_t>(
domain.dimension(i).name(), 0, newshape[0] - 1);
}
}

new_current_domain.set_ndrectangle(ndrect);
schema_evolution.expand_current_domain(new_current_domain);
schema_evolution.array_evolve(uri_);
}

uint64_t SOMAArray::ndim() const {
return tiledb_schema()->domain().ndim();
}
Expand Down
16 changes: 16 additions & 0 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,22 @@ class SOMAArray : public SOMAObject {
*/
void resize(const std::vector<int64_t>& newshape);

/**
* @brief Increases the tiledbsoma shape up to at most the maxshape,
* resizing the soma_joinid dimension if it is a dimension.
*
* While SOMA SparseNDArray and DenseNDArray, along with default-indexed
* DataFrame, have int64_t dims, non-default-indexed DataFrame objects need
* not: it is only required that they have a dim _or_ an attr called
* soma_joinid. If soma_joinid is one of the dims, it will be resized while
* the others will be preserved. If soma_joinid is not one of the dims,
* nothing will be changed, as nothing _needs_ to be changed.
*
* @return Throws if the requested shape exceeds the array's create-time
* maxshape. Throws if the array does not have current-domain support.
*/
void resize_soma_joinid_if_dim(const std::vector<int64_t>& newshape);

/**
* @brief Get the number of dimensions.
*
Expand Down

0 comments on commit 1bf7b10

Please sign in to comment.