From c33cbc8d978adfb8a367a8dc930b90ddab6d24f2 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 15 Sep 2023 19:19:02 +0000 Subject: [PATCH 1/3] ihn/bugfix --- apis/python/src/tiledbsoma/pytiledbsoma.cc | 10 +++++----- apis/r/src/rinterface.cpp | 2 +- apis/r/src/riterator.cpp | 2 +- libtiledbsoma/src/soma/soma_array.cc | 2 +- libtiledbsoma/src/utils/arrow_adapter.h | 8 +++++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/apis/python/src/tiledbsoma/pytiledbsoma.cc b/apis/python/src/tiledbsoma/pytiledbsoma.cc index 1e2ff3762c..cccd35c61a 100644 --- a/apis/python/src/tiledbsoma/pytiledbsoma.cc +++ b/apis/python/src/tiledbsoma/pytiledbsoma.cc @@ -129,9 +129,9 @@ py::object to_table(SOMAArray& sr, std::shared_ptr array_buffers) arrays.append(to_array(column)); }else{ arrays.append(pa_dict_from_arrays( - to_array(column), - get_enum(sr, name), - py::none(), + to_array(column), + get_enum(sr, name), + py::none(), get_enum_is_ordered(sr, name))); } } @@ -640,11 +640,11 @@ PYBIND11_MODULE(pytiledbsoma, m) { .def("nnz", &SOMAArray::nnz, py::call_guard()) .def_property_readonly("shape", &SOMAArray::shape) - + .def("get_enum", get_enum) .def("get_enum_is_ordered", get_enum_is_ordered) - + .def("get_enum_label_on_attr", &SOMAArray::get_enum_label_on_attr); } } // namespace tiledbsoma diff --git a/apis/r/src/rinterface.cpp b/apis/r/src/rinterface.cpp index b3bd33670c..082ebdb92f 100644 --- a/apis/r/src/rinterface.cpp +++ b/apis/r/src/rinterface.cpp @@ -148,7 +148,7 @@ Rcpp::List soma_array_reader(const std::string& uri, auto buf = sr_data->get()->at(names[i]); // this is pair of array and schema pointer - auto pp = tdbs::ArrowAdapter::to_arrow(buf); + auto pp = tdbs::ArrowAdapter::to_arrow(buf, true); memcpy((void*) chldschemaxp, pp.second.get(), sizeof(ArrowSchema)); memcpy((void*) chldarrayxp, pp.first.get(), sizeof(ArrowArray)); diff --git a/apis/r/src/riterator.cpp b/apis/r/src/riterator.cpp index 45e10413e8..3fc2bb12ec 100644 --- a/apis/r/src/riterator.cpp +++ b/apis/r/src/riterator.cpp @@ -216,7 +216,7 @@ Rcpp::List sr_next(Rcpp::XPtr sr) { auto buf = sr_data->get()->at(names[i]); // this is pair of array and schema pointer - auto pp = tdbs::ArrowAdapter::to_arrow(buf); + auto pp = tdbs::ArrowAdapter::to_arrow(buf, true); memcpy((void*) chldschemaxp, pp.second.get(), sizeof(ArrowSchema)); memcpy((void*) chldarrayxp, pp.first.get(), sizeof(ArrowArray)); diff --git a/libtiledbsoma/src/soma/soma_array.cc b/libtiledbsoma/src/soma/soma_array.cc index fc03b2f344..cb243f81e8 100644 --- a/libtiledbsoma/src/soma/soma_array.cc +++ b/libtiledbsoma/src/soma/soma_array.cc @@ -571,4 +571,4 @@ void SOMAArray::validate( } } -} // namespace tiledbsoma \ No newline at end of file +} // namespace tiledbsoma diff --git a/libtiledbsoma/src/utils/arrow_adapter.h b/libtiledbsoma/src/utils/arrow_adapter.h index 7f5ccd99cf..bf7c0d3488 100644 --- a/libtiledbsoma/src/utils/arrow_adapter.h +++ b/libtiledbsoma/src/utils/arrow_adapter.h @@ -86,7 +86,7 @@ class ArrowAdapter { * * @return auto [Arrow array, Arrow schema] */ - static auto to_arrow(std::shared_ptr column) { + static auto to_arrow(std::shared_ptr column, bool use_enum=false) { std::unique_ptr schema = std::make_unique(); std::unique_ptr array = std::make_unique(); @@ -153,8 +153,10 @@ class ArrowAdapter { column->data_to_bitmap(); } - // If we have an enumeration, fill a dictionary - if (column->has_enumeration()) { + // If we have an enumeration, fill a dictionary. + // The Python callpath handles this separately. The R callpath needs us + // to do this. TODO: uniformize this at the callsites. + if (column->has_enumeration() && use_enum) { auto enumvec = column->get_enumeration(); ArrowSchema* dict_sch = new ArrowSchema; From a34d754767e559f4c1e4054a4471e4cfd3f52166 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 15 Sep 2023 21:22:09 +0000 Subject: [PATCH 2/3] unit-test update --- libtiledbsoma/src/soma/managed_query.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libtiledbsoma/src/soma/managed_query.cc b/libtiledbsoma/src/soma/managed_query.cc index 29910bebca..ec81f5b372 100644 --- a/libtiledbsoma/src/soma/managed_query.cc +++ b/libtiledbsoma/src/soma/managed_query.cc @@ -225,6 +225,9 @@ std::shared_ptr ManagedQuery::results() { auto enumeration = ArrayExperimental::get_enumeration( *ctx_, *array_, enumname.value()); auto enumvec = enumeration.as_vector(); + if (!buffers_->contains(attrname)) { + continue; + } auto colbuf = buffers_->at(attrname); colbuf->add_enumeration(enumvec); LOG_DEBUG(fmt::format( From ad6ae4dff16e26dce8c1cefdb7d45048a5ece508 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 15 Sep 2023 17:27:14 -0400 Subject: [PATCH 3/3] lint --- libtiledbsoma/src/soma/managed_query.cc | 2 +- libtiledbsoma/src/utils/arrow_adapter.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libtiledbsoma/src/soma/managed_query.cc b/libtiledbsoma/src/soma/managed_query.cc index ec81f5b372..10a1b39fcc 100644 --- a/libtiledbsoma/src/soma/managed_query.cc +++ b/libtiledbsoma/src/soma/managed_query.cc @@ -226,7 +226,7 @@ std::shared_ptr ManagedQuery::results() { *ctx_, *array_, enumname.value()); auto enumvec = enumeration.as_vector(); if (!buffers_->contains(attrname)) { - continue; + continue; } auto colbuf = buffers_->at(attrname); colbuf->add_enumeration(enumvec); diff --git a/libtiledbsoma/src/utils/arrow_adapter.h b/libtiledbsoma/src/utils/arrow_adapter.h index bf7c0d3488..03f0a557d7 100644 --- a/libtiledbsoma/src/utils/arrow_adapter.h +++ b/libtiledbsoma/src/utils/arrow_adapter.h @@ -86,7 +86,8 @@ class ArrowAdapter { * * @return auto [Arrow array, Arrow schema] */ - static auto to_arrow(std::shared_ptr column, bool use_enum=false) { + static auto to_arrow( + std::shared_ptr column, bool use_enum = false) { std::unique_ptr schema = std::make_unique(); std::unique_ptr array = std::make_unique();