Skip to content

Commit

Permalink
Swap shared_ptr with const reference, hide internal columns when open…
Browse files Browse the repository at this point in the history
…ing an array for read unless explicity specify them
  • Loading branch information
XanthosXanthopoulos committed Nov 1, 2024
1 parent fbac212 commit eb47db2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
19 changes: 19 additions & 0 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,25 @@ void SOMAArray::reset(

if (!column_names.empty()) {
mq_->select_columns(column_names);
} else {
// Hide internal columns if any
std::vector<std::string> columns;
for (const auto& dim : this->tiledb_schema()->domain().dimensions()) {
columns.push_back(dim.name());
}

for (size_t i = 0; i < this->tiledb_schema()->attribute_num(); ++i) {
columns.push_back(this->tiledb_schema()->attribute(i).name());
}
auto is_internal = [](std::string name) {
return name.rfind(SOMA_GEOMETRY_DIMENSION_PREFIX, 0) == 0;
};

auto internal_end = std::remove_if(
columns.begin(), columns.end(), is_internal);
columns.erase(internal_end, columns.end());

mq_->select_columns(columns);
}

switch (result_order) {
Expand Down
10 changes: 4 additions & 6 deletions libtiledbsoma/src/utils/arrow_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_array(
} else if constexpr (std::is_same_v<T, Attribute>) {
child = arrow_schema->children[i] =
arrow_schema_from_tiledb_attribute(
arg, ctx, tiledb_array)
arg, *ctx, *tiledb_array)
.release();
}
},
Expand Down Expand Up @@ -425,9 +425,7 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_dimension(
}

std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_attribute(
Attribute& attribute,
std::shared_ptr<Context> ctx,
std::shared_ptr<Array> tiledb_array) {
Attribute& attribute, const Context& ctx, const Array& tiledb_array) {
std::unique_ptr<ArrowSchema> arrow_schema = std::make_unique<ArrowSchema>();
arrow_schema->format = strdup(
ArrowAdapter::to_arrow_format(attribute.type()).data());
Expand All @@ -454,10 +452,10 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_attribute(
arrow_schema->name));

auto enmr_name = AttributeExperimental::get_enumeration_name(
*ctx, attribute);
ctx, attribute);
if (enmr_name.has_value()) {
auto enmr = ArrayExperimental::get_enumeration(
*ctx, *tiledb_array, attribute.name());
ctx, tiledb_array, attribute.name());
auto dict = (ArrowSchema*)malloc(sizeof(ArrowSchema));
dict->format = strdup(
ArrowAdapter::to_arrow_format(enmr.type(), false).data());
Expand Down
4 changes: 1 addition & 3 deletions libtiledbsoma/src/utils/arrow_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ class ArrowAdapter {
* @return ArrowSchema
*/
static std::unique_ptr<ArrowSchema> arrow_schema_from_tiledb_attribute(
Attribute& attribute,
std::shared_ptr<Context> ctx,
std::shared_ptr<Array> tiledb_array);
Attribute& attribute, const Context& ctx, const Array& tiledb_array);

/**
* @brief Get members of the TileDB Schema in the form of a PlatformConfig
Expand Down
32 changes: 0 additions & 32 deletions libtiledbsoma/test/unit_soma_geometry_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,43 +313,11 @@ TEST_CASE("SOMAGeometryDataFrame: Roundtrip", "[SOMAGeometryDataFrame]") {
while (auto batch = soma_geometry->read_next()) {
auto arrbuf = batch.value();
auto d0span = arrbuf->at(dim_infos[0].name)->data<int64_t>();
auto d1span = arrbuf
->at(
SOMA_GEOMETRY_DIMENSION_PREFIX +
spatial_dim_infos[0].name + "__min")
->data<double_t>();
auto d2span = arrbuf
->at(
SOMA_GEOMETRY_DIMENSION_PREFIX +
spatial_dim_infos[0].name + "__max")
->data<double_t>();
auto d3span = arrbuf
->at(
SOMA_GEOMETRY_DIMENSION_PREFIX +
spatial_dim_infos[1].name + "__min")
->data<double_t>();
auto d4span = arrbuf
->at(
SOMA_GEOMETRY_DIMENSION_PREFIX +
spatial_dim_infos[1].name + "__max")
->data<double_t>();
auto wkbs = arrbuf->at(dim_infos[1].name)->binaries();
auto a0span = arrbuf->at(attr_infos[0].name)->data<double>();
CHECK(
std::vector<int64_t>({1}) ==
std::vector<int64_t>(d0span.begin(), d0span.end()));
CHECK(
std::vector<double_t>({0}) ==
std::vector<double_t>(d1span.begin(), d1span.end()));
CHECK(
std::vector<double_t>({1}) ==
std::vector<double_t>(d2span.begin(), d2span.end()));
CHECK(
std::vector<double_t>({0}) ==
std::vector<double_t>(d3span.begin(), d3span.end()));
CHECK(
std::vector<double_t>({1}) ==
std::vector<double_t>(d4span.begin(), d4span.end()));
CHECK(geometry::to_wkb(polygon) == wkbs[0]);
CHECK(
std::vector<double_t>({63}) ==
Expand Down

0 comments on commit eb47db2

Please sign in to comment.