Skip to content

Commit eb47db2

Browse files
Swap shared_ptr with const reference, hide internal columns when opening an array for read unless explicity specify them
1 parent fbac212 commit eb47db2

File tree

4 files changed

+24
-41
lines changed

4 files changed

+24
-41
lines changed

libtiledbsoma/src/soma/soma_array.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,25 @@ void SOMAArray::reset(
250250

251251
if (!column_names.empty()) {
252252
mq_->select_columns(column_names);
253+
} else {
254+
// Hide internal columns if any
255+
std::vector<std::string> columns;
256+
for (const auto& dim : this->tiledb_schema()->domain().dimensions()) {
257+
columns.push_back(dim.name());
258+
}
259+
260+
for (size_t i = 0; i < this->tiledb_schema()->attribute_num(); ++i) {
261+
columns.push_back(this->tiledb_schema()->attribute(i).name());
262+
}
263+
auto is_internal = [](std::string name) {
264+
return name.rfind(SOMA_GEOMETRY_DIMENSION_PREFIX, 0) == 0;
265+
};
266+
267+
auto internal_end = std::remove_if(
268+
columns.begin(), columns.end(), is_internal);
269+
columns.erase(internal_end, columns.end());
270+
271+
mq_->select_columns(columns);
253272
}
254273

255274
switch (result_order) {

libtiledbsoma/src/utils/arrow_adapter.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_array(
392392
} else if constexpr (std::is_same_v<T, Attribute>) {
393393
child = arrow_schema->children[i] =
394394
arrow_schema_from_tiledb_attribute(
395-
arg, ctx, tiledb_array)
395+
arg, *ctx, *tiledb_array)
396396
.release();
397397
}
398398
},
@@ -425,9 +425,7 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_dimension(
425425
}
426426

427427
std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_attribute(
428-
Attribute& attribute,
429-
std::shared_ptr<Context> ctx,
430-
std::shared_ptr<Array> tiledb_array) {
428+
Attribute& attribute, const Context& ctx, const Array& tiledb_array) {
431429
std::unique_ptr<ArrowSchema> arrow_schema = std::make_unique<ArrowSchema>();
432430
arrow_schema->format = strdup(
433431
ArrowAdapter::to_arrow_format(attribute.type()).data());
@@ -454,10 +452,10 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::arrow_schema_from_tiledb_attribute(
454452
arrow_schema->name));
455453

456454
auto enmr_name = AttributeExperimental::get_enumeration_name(
457-
*ctx, attribute);
455+
ctx, attribute);
458456
if (enmr_name.has_value()) {
459457
auto enmr = ArrayExperimental::get_enumeration(
460-
*ctx, *tiledb_array, attribute.name());
458+
ctx, tiledb_array, attribute.name());
461459
auto dict = (ArrowSchema*)malloc(sizeof(ArrowSchema));
462460
dict->format = strdup(
463461
ArrowAdapter::to_arrow_format(enmr.type(), false).data());

libtiledbsoma/src/utils/arrow_adapter.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,7 @@ class ArrowAdapter {
243243
* @return ArrowSchema
244244
*/
245245
static std::unique_ptr<ArrowSchema> arrow_schema_from_tiledb_attribute(
246-
Attribute& attribute,
247-
std::shared_ptr<Context> ctx,
248-
std::shared_ptr<Array> tiledb_array);
246+
Attribute& attribute, const Context& ctx, const Array& tiledb_array);
249247

250248
/**
251249
* @brief Get members of the TileDB Schema in the form of a PlatformConfig

libtiledbsoma/test/unit_soma_geometry_dataframe.cc

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -313,43 +313,11 @@ TEST_CASE("SOMAGeometryDataFrame: Roundtrip", "[SOMAGeometryDataFrame]") {
313313
while (auto batch = soma_geometry->read_next()) {
314314
auto arrbuf = batch.value();
315315
auto d0span = arrbuf->at(dim_infos[0].name)->data<int64_t>();
316-
auto d1span = arrbuf
317-
->at(
318-
SOMA_GEOMETRY_DIMENSION_PREFIX +
319-
spatial_dim_infos[0].name + "__min")
320-
->data<double_t>();
321-
auto d2span = arrbuf
322-
->at(
323-
SOMA_GEOMETRY_DIMENSION_PREFIX +
324-
spatial_dim_infos[0].name + "__max")
325-
->data<double_t>();
326-
auto d3span = arrbuf
327-
->at(
328-
SOMA_GEOMETRY_DIMENSION_PREFIX +
329-
spatial_dim_infos[1].name + "__min")
330-
->data<double_t>();
331-
auto d4span = arrbuf
332-
->at(
333-
SOMA_GEOMETRY_DIMENSION_PREFIX +
334-
spatial_dim_infos[1].name + "__max")
335-
->data<double_t>();
336316
auto wkbs = arrbuf->at(dim_infos[1].name)->binaries();
337317
auto a0span = arrbuf->at(attr_infos[0].name)->data<double>();
338318
CHECK(
339319
std::vector<int64_t>({1}) ==
340320
std::vector<int64_t>(d0span.begin(), d0span.end()));
341-
CHECK(
342-
std::vector<double_t>({0}) ==
343-
std::vector<double_t>(d1span.begin(), d1span.end()));
344-
CHECK(
345-
std::vector<double_t>({1}) ==
346-
std::vector<double_t>(d2span.begin(), d2span.end()));
347-
CHECK(
348-
std::vector<double_t>({0}) ==
349-
std::vector<double_t>(d3span.begin(), d3span.end()));
350-
CHECK(
351-
std::vector<double_t>({1}) ==
352-
std::vector<double_t>(d4span.begin(), d4span.end()));
353321
CHECK(geometry::to_wkb(polygon) == wkbs[0]);
354322
CHECK(
355323
std::vector<double_t>({63}) ==

0 commit comments

Comments
 (0)