Skip to content

Commit

Permalink
Merge internal dimension domains under soma_geometry domain (x_mi…
Browse files Browse the repository at this point in the history
…n, x_max, y_min, y_max) (#3299)
  • Loading branch information
XanthosXanthopoulos committed Nov 18, 2024
1 parent f0cd461 commit 87cef7c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
9 changes: 4 additions & 5 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
#ifndef SOMA_ARRAY
#define SOMA_ARRAY

#include <stdexcept> // for windows: error C2039: 'runtime_error': is not a member of 'std'

#include <future>
#include <stdexcept> // for windows: error C2039: 'runtime_error': is not a member of 'std'

#include <tiledb/tiledb>
#include <tiledb/tiledb_experimental>
Expand Down Expand Up @@ -997,7 +996,7 @@ class SOMAArray : public SOMAObject {
* @tparam T Domain datatype
* @return Pair of [lower, upper] inclusive bounds.
*/
ArrowTable get_soma_domain() {
virtual ArrowTable get_soma_domain() {

Check warning on line 999 in libtiledbsoma/src/soma/soma_array.h

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_array.h#L999

Added line #L999 was not covered by tests
if (has_current_domain()) {
return _get_core_current_domain();
} else {
Expand All @@ -1020,15 +1019,15 @@ class SOMAArray : public SOMAObject {
* @tparam T Domain datatype
* @return Pair of [lower, upper] inclusive bounds.
*/
ArrowTable get_soma_maxdomain() {
virtual ArrowTable get_soma_maxdomain() {

Check warning on line 1022 in libtiledbsoma/src/soma/soma_array.h

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_array.h#L1022

Added line #L1022 was not covered by tests
return _get_core_domain();
}

/**
* Returns the core non-empty domain in its entirety, as an Arrow
* table for return to Python/R.
*/
ArrowTable get_non_empty_domain() {
virtual ArrowTable get_non_empty_domain() {

Check warning on line 1030 in libtiledbsoma/src/soma/soma_array.h

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_array.h#L1030

Added line #L1030 was not covered by tests
return _get_core_domainish(Domainish::kind_non_empty_domain);
}

Expand Down
59 changes: 59 additions & 0 deletions libtiledbsoma/src/soma/soma_geometry_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ void SOMAGeometryDataFrame::set_array_data(
SOMAArray::set_array_data(std::move(arrow_schema), std::move(arrow_array));
}

ArrowTable SOMAGeometryDataFrame::get_soma_domain() {
return _reconstruct_geometry_domain(SOMAArray::get_soma_domain());

Check warning on line 188 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L187-L188

Added lines #L187 - L188 were not covered by tests
}

ArrowTable SOMAGeometryDataFrame::get_soma_maxdomain() {
return _reconstruct_geometry_domain(SOMAArray::get_soma_maxdomain());

Check warning on line 192 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L191-L192

Added lines #L191 - L192 were not covered by tests
}

ArrowTable SOMAGeometryDataFrame::get_non_empty_domain() {
return _reconstruct_geometry_domain(SOMAArray::get_non_empty_domain());

Check warning on line 196 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L195-L196

Added lines #L195 - L196 were not covered by tests
}

//===================================================================
//= private non-static
//===================================================================
Expand Down Expand Up @@ -364,4 +376,51 @@ ArrowTable SOMAGeometryDataFrame::_reconstruct_geometry_data_table(
return ArrowTable(std::move(arrow_array), std::move(arrow_schema));
}

ArrowTable SOMAGeometryDataFrame::_reconstruct_geometry_domain(

Check warning on line 379 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L379

Added line #L379 was not covered by tests
const ArrowTable& domain) {
std::unique_ptr<ArrowSchema> schema = std::make_unique<ArrowSchema>(
ArrowSchema{});
std::unique_ptr<ArrowArray> array = std::make_unique<ArrowArray>(
ArrowArray{});

Check warning on line 384 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L381-L384

Added lines #L381 - L384 were not covered by tests

int64_t internal_axes = 2 * spatial_column_names().size();

Check warning on line 386 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L386

Added line #L386 was not covered by tests

NANOARROW_THROW_NOT_OK(

Check warning on line 388 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L388

Added line #L388 was not covered by tests
ArrowSchemaInitFromType(schema.get(), NANOARROW_TYPE_STRUCT));
NANOARROW_THROW_NOT_OK(ArrowSchemaAllocateChildren(

Check warning on line 390 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L390

Added line #L390 was not covered by tests
schema.get(), domain.second->n_children - internal_axes + 1));
NANOARROW_THROW_NOT_OK(

Check warning on line 392 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L392

Added line #L392 was not covered by tests
ArrowArrayInitFromType(array.get(), NANOARROW_TYPE_STRUCT));
NANOARROW_THROW_NOT_OK(ArrowArrayAllocateChildren(

Check warning on line 394 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L394

Added line #L394 was not covered by tests
array.get(), domain.first->n_children - internal_axes + 1));

std::vector<std::string> dim_names = this->dimension_names();
auto is_internal = [](std::string name) {
return name.rfind(SOMA_GEOMETRY_DIMENSION_PREFIX, 0) == 0;

Check warning on line 399 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L397-L399

Added lines #L397 - L399 were not covered by tests
};
auto first_dim = static_cast<int64_t>(
std::find_if(begin(dim_names), end(dim_names), is_internal) -
dim_names.begin());

Check warning on line 403 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L401-L403

Added lines #L401 - L403 were not covered by tests

for (int64_t i = 0, orig_i = 0; i < schema->n_children; ++i, ++orig_i) {
ArrowSchemaMove(domain.second->children[orig_i], schema->children[i]);
ArrowArrayMove(domain.first->children[orig_i], array->children[i]);

Check warning on line 407 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L406-L407

Added lines #L406 - L407 were not covered by tests

if (i == first_dim) {
NANOARROW_THROW_NOT_OK(ArrowSchemaSetName(

Check warning on line 410 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L410

Added line #L410 was not covered by tests
schema->children[i], SOMA_GEOMETRY_COLUMN_NAME.c_str()));
std::vector<double_t> data;

Check warning on line 412 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L412

Added line #L412 was not covered by tests
for (; orig_i < i + internal_axes; orig_i += 2) {
data.push_back(
((double_t*)domain.first->children[orig_i]->buffers[1])[0]);
data.push_back(
((double_t*)domain.first->children[orig_i]->buffers[1])[1]);

Check warning on line 417 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L414-L417

Added lines #L414 - L417 were not covered by tests
}
array->children[i] = ArrowAdapter::make_arrow_array_child(data);

Check warning on line 419 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L419

Added line #L419 was not covered by tests
}
}

return ArrowTable(std::move(array), std::move(schema));

Check warning on line 423 in libtiledbsoma/src/soma/soma_geometry_dataframe.cc

View check run for this annotation

Codecov / codecov/patch

libtiledbsoma/src/soma/soma_geometry_dataframe.cc#L423

Added line #L423 was not covered by tests
}

} // namespace tiledbsoma
13 changes: 13 additions & 0 deletions libtiledbsoma/src/soma/soma_geometry_dataframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ class SOMAGeometryDataFrame : virtual public SOMAArray {
std::unique_ptr<ArrowSchema> arrow_schema,
std::unique_ptr<ArrowArray> arrow_array) override;

ArrowTable get_soma_domain() override;

ArrowTable get_soma_maxdomain() override;

ArrowTable get_non_empty_domain() override;

private:
//===================================================================
//= private non-static
Expand All @@ -260,6 +266,13 @@ class SOMAGeometryDataFrame : virtual public SOMAArray {
*/
ArrowTable _reconstruct_geometry_data_table(
ArrowTable original_data, const std::vector<ArrowTable>& wkb_data);

/**
* @brief Create a new ArrowTable by merging the internal spatial dimensions
* and setting the ``soma_geometry`` domain as the stacked domain of each
* spatial axis.
*/
ArrowTable _reconstruct_geometry_domain(const ArrowTable& domain);
};
} // namespace tiledbsoma

Expand Down
2 changes: 1 addition & 1 deletion libtiledbsoma/test/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ std::unique_ptr<ArrowSchema> create_index_cols_info_schema(

auto schema = ArrowAdapter::make_arrow_schema(names, tiledb_datatypes);

for (size_t i = 0; i < static_cast<size_t>(schema->n_children); ++i) {
for (int64_t i = 0; i < schema->n_children; ++i) {
if (strcmp(schema->children[i]->name, "soma_geometry")) {
nanoarrow::UniqueBuffer buffer;
ArrowMetadataBuilderInit(buffer.get(), nullptr);
Expand Down

0 comments on commit 87cef7c

Please sign in to comment.