Skip to content

Commit

Permalink
[c++] Refactor SOMAArray and SOMAGroup to inherit from `SOMAObjec…
Browse files Browse the repository at this point in the history
…t` (#2124)

* Use `-mmacosx-version-min=11.0`
* Drop test for arch in R `configure`
---------
Co-authored-by: Dirk Eddelbuettel <[email protected]>
  • Loading branch information
nguyenv authored Feb 12, 2024
1 parent fae2ac1 commit 57347c0
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 958 deletions.
2 changes: 1 addition & 1 deletion apis/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def run(self):
CXX_FLAGS.append(f'-Wl,-rpath,{str(tiledb_dir / "lib")}')

if sys.platform == "darwin":
CXX_FLAGS.append("-mmacosx-version-min=10.14")
CXX_FLAGS.append("-mmacosx-version-min=11.0")

if os.name == "posix" and sys.platform != "darwin":
LIB_DIRS.append(str(libtiledbsoma_dir / "lib" / "x86_64-linux-gnu"))
Expand Down
2 changes: 1 addition & 1 deletion apis/r/configure
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tools/build_libtiledbsoma.sh
pkgincl="-I../inst/tiledb/include -I../inst/tiledbsoma/include"
pkglibs="-ltiledb -L../inst/tiledb/lib -ltiledbsoma -L../inst/tiledbsoma/lib"
rpath="-Wl,-rpath,'\$\$ORIGIN/../tiledb/lib' -Wl,-rpath,'\$\$ORIGIN/../tiledbsoma/lib'"
macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["machine"] == "x86_64" && Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=10.14") else cat("")'`
macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=11.0") else cat("")'`

sed -e "s|@tiledb_include@|$pkgincl |" \
-e "s|@tiledb_libs@|$pkglibs|" \
Expand Down
3 changes: 2 additions & 1 deletion libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void SOMAArray::fill_metadata_cache() {
}
}

const std::string& SOMAArray::uri() const {
const std::string SOMAArray::uri() const {
return uri_;
};

Expand All @@ -189,6 +189,7 @@ void SOMAArray::open(
arr_->close();
arr_->open(tdb_mode);
}
reset(column_names(), batch_size_, result_order_);
}

void SOMAArray::close() {
Expand Down
44 changes: 27 additions & 17 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
#include "enums.h"
#include "logger_public.h"
#include "managed_query.h"
#include "soma_object.h"

namespace tiledbsoma {
using namespace tiledb;

class SOMAArray {
class SOMAArray : public SOMAObject {
public:
//===================================================================
//= public static
Expand Down Expand Up @@ -167,17 +168,36 @@ class SOMAArray {
ResultOrder result_order,
std::optional<std::pair<uint64_t, uint64_t>> timestamp = std::nullopt);

SOMAArray(const SOMAArray& other)
: ctx_(other.ctx_)
, config_(other.config_)
, uri_(other.uri_)
, name_(other.name_)
, batch_size_(other.batch_size_)
, result_order_(other.result_order_)
, metadata_(other.metadata_)
, timestamp_(other.timestamp_)
, mq_(std::make_unique<ManagedQuery>(
other.arr_, other.ctx_, other.name_))
, arr_(other.arr_)
, first_read_next_(other.first_read_next_)
, submitted_(other.submitted_) {
}

SOMAArray(const SOMAObject& other)
: SOMAObject(other) {
}

SOMAArray() = delete;
SOMAArray(const SOMAArray&) = delete;
SOMAArray(SOMAArray&&) = default;
SOMAArray(SOMAArray&&) = delete;
~SOMAArray() = default;

/**
* @brief Get URI of the SOMAArray.
*
* @return std::string URI
*/
const std::string& uri() const;
const std::string uri() const;

/**
* @brief Get Ctx of the SOMAArray.
Expand All @@ -193,19 +213,6 @@ class SOMAArray {
*/
std::map<std::string, std::string> config();

std::optional<std::string> soma_object_type() {
auto soma_object_type = this->get_metadata("soma_object_type");

if (!soma_object_type.has_value())
return std::nullopt;

const char* dtype = (const char*)std::get<MetadataInfo::value>(
*soma_object_type);
uint32_t sz = std::get<MetadataInfo::num>(*soma_object_type);

return std::string(dtype, sz);
}

/**
* Open the SOMAArray object.
*
Expand Down Expand Up @@ -709,6 +716,9 @@ class SOMAArray {
// SOMAArray URI
std::string uri_;

// SOMAArray name for debugging
std::string_view name_;

// Batch size
std::string batch_size_;

Expand Down
17 changes: 10 additions & 7 deletions libtiledbsoma/src/soma/soma_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,22 @@ void SOMACollection::set(

std::shared_ptr<SOMAObject> SOMACollection::get(const std::string& key) {
auto member = group_->get_member(key);
std::string soma_object_type = this->type();
std::optional<std::string> soma_object_type = this->type();

if (soma_object_type.compare("SOMACollection") == 0)
if (!soma_object_type)
throw TileDBSOMAError("Saw invalid SOMA object.");

if (soma_object_type->compare("SOMACollection") == 0)
return SOMACollection::open(member.uri(), OpenMode::read);
else if (soma_object_type.compare("SOMAExperiment") == 0)
else if (soma_object_type->compare("SOMAExperiment") == 0)
return SOMAExperiment::open(member.uri(), OpenMode::read);
else if (soma_object_type.compare("SOMAMeasurement") == 0)
else if (soma_object_type->compare("SOMAMeasurement") == 0)
return SOMAMeasurement::open(member.uri(), OpenMode::read);
else if (soma_object_type.compare("SOMADataFrame") == 0)
else if (soma_object_type->compare("SOMADataFrame") == 0)
return SOMADataFrame::open(member.uri(), OpenMode::read);
else if (soma_object_type.compare("SOMASparseNDArray") == 0)
else if (soma_object_type->compare("SOMASparseNDArray") == 0)
return SOMASparseNDArray::open(member.uri(), OpenMode::read);
else if (soma_object_type.compare("SOMADenseNDArray") == 0)
else if (soma_object_type->compare("SOMADenseNDArray") == 0)
return SOMADenseNDArray::open(member.uri(), OpenMode::read);

throw TileDBSOMAError("Saw invalid SOMA object.");
Expand Down
9 changes: 0 additions & 9 deletions libtiledbsoma/src/soma/soma_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ class SOMACollection : public SOMAObject {
return group_->is_open();
}

/**
* Return the constant "SOMACollection".
*
* @return std::string
*/
const std::string type() const {
return "SOMACollection";
}

/**
* Get the SOMACollection URI.
*/
Expand Down
90 changes: 9 additions & 81 deletions libtiledbsoma/src/soma/soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
* This file defines the SOMADataFrame class.
*/

#include <filesystem>

#include <tiledb/tiledb>
#include "array_buffers.h"
#include "soma_dataframe.h"

namespace tiledbsoma {
Expand Down Expand Up @@ -84,96 +80,28 @@ std::unique_ptr<SOMADataFrame> SOMADataFrame::open(
mode, uri, ctx, column_names, result_order, timestamp);
}

//===================================================================
//= public non-static
//===================================================================

SOMADataFrame::SOMADataFrame(
OpenMode mode,
std::string_view uri,
std::shared_ptr<Context> ctx,
std::vector<std::string> column_names,
ResultOrder result_order,
std::optional<std::pair<uint64_t, uint64_t>> timestamp) {
std::string array_name = std::filesystem::path(uri).filename().string();
array_ = std::make_shared<SOMAArray>(
mode,
uri,
array_name, // label used when debugging
ctx,
column_names,
"auto", // batch_size,
result_order,
timestamp);
}

void SOMADataFrame::open(
OpenMode mode, std::optional<std::pair<uint64_t, uint64_t>> timestamp) {
array_->open(mode, timestamp);
}

void SOMADataFrame::close() {
array_->close();
}

bool SOMADataFrame::exists(std::string_view uri) {
try {
auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::read);
auto soma_object_type = soma_dataframe->get_metadata(
"soma_object_type");

if (!soma_object_type.has_value())
return false;

const char* dtype = (const char*)std::get<MetadataInfo::value>(
*soma_object_type);

uint32_t sz = std::get<MetadataInfo::num>(*soma_object_type);

return std::string(dtype, sz) == "SOMADataFrame";
} catch (std::exception& e) {
return "SOMADataFrame" == SOMAObject::open(uri, OpenMode::read)->type();
} catch (TileDBSOMAError& e) {
return false;
}
}

bool SOMADataFrame::is_open() const {
return array_->is_open();
}

const std::string SOMADataFrame::uri() const {
return array_->uri();
}

std::shared_ptr<Context> SOMADataFrame::ctx() {
return array_->ctx();
}

std::map<std::string, std::string> SOMADataFrame::config() {
return array_->config();
}
//===================================================================
//= public non-static
//===================================================================

std::unique_ptr<ArrowSchema> SOMADataFrame::schema() const {
return array_->arrow_schema();
}

std::shared_ptr<ArraySchema> SOMADataFrame::tiledb_schema() const {
return array_->tiledb_schema();
return this->arrow_schema();
}

const std::vector<std::string> SOMADataFrame::index_column_names() const {
return array_->dimension_names();
}

int64_t SOMADataFrame::count() const {
return array_->nnz();
}

std::optional<std::shared_ptr<ArrayBuffers>> SOMADataFrame::read_next() {
return array_->read_next();
return this->dimension_names();
}

void SOMADataFrame::write(std::shared_ptr<ArrayBuffers> buffers) {
array_->write(buffers);
uint64_t SOMADataFrame::count() {
return this->nnz();
}

} // namespace tiledbsoma
Loading

0 comments on commit 57347c0

Please sign in to comment.