Skip to content

Commit

Permalink
[c++] exists should take in SOMAContext (#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Jul 16, 2024
1 parent 18df8bb commit d9b6470
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions libtiledbsoma/src/soma/soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ std::unique_ptr<SOMADataFrame> SOMADataFrame::open(
mode, uri, ctx, column_names, result_order, timestamp);
}

bool SOMADataFrame::exists(std::string_view uri) {
bool SOMADataFrame::exists(
std::string_view uri, std::shared_ptr<SOMAContext> ctx) {
try {
auto obj = SOMAObject::open(
uri, OpenMode::read, std::make_shared<SOMAContext>());
auto obj = SOMAObject::open(uri, OpenMode::read, ctx);
return "SOMADataFrame" == obj->type();
} catch (TileDBSOMAError& e) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion libtiledbsoma/src/soma/soma_dataframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class SOMADataFrame : public SOMAArray {
* @brief Check if the SOMADataFrame exists at the URI.
*
* @param uri URI to create the SOMADataFrame
* @param ctx SOMAContext
*/
static bool exists(std::string_view uri);
static bool exists(std::string_view uri, std::shared_ptr<SOMAContext> ctx);

//===================================================================
//= public non-static
Expand Down
6 changes: 3 additions & 3 deletions libtiledbsoma/src/soma/soma_dense_ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ std::unique_ptr<SOMADenseNDArray> SOMADenseNDArray::open(
mode, uri, ctx, column_names, result_order, timestamp);
}

bool SOMADenseNDArray::exists(std::string_view uri) {
bool SOMADenseNDArray::exists(
std::string_view uri, std::shared_ptr<SOMAContext> ctx) {
try {
auto obj = SOMAObject::open(
uri, OpenMode::read, std::make_shared<SOMAContext>());
auto obj = SOMAObject::open(uri, OpenMode::read, ctx);
return "SOMADenseNDArray" == obj->type();
} catch (TileDBSOMAError& e) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion libtiledbsoma/src/soma/soma_dense_ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class SOMADenseNDArray : public SOMAArray {
* @brief Check if the SOMADenseNDArray exists at the URI.
*
* @param uri URI to create the SOMADenseNDArray
* @param ctx SOMAContext
*/
static bool exists(std::string_view uri);
static bool exists(std::string_view uri, std::shared_ptr<SOMAContext> ctx);

//===================================================================
//= public non-static
Expand Down
6 changes: 3 additions & 3 deletions libtiledbsoma/src/soma/soma_sparse_ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ std::unique_ptr<SOMASparseNDArray> SOMASparseNDArray::open(
mode, uri, ctx, column_names, result_order, timestamp);
}

bool SOMASparseNDArray::exists(std::string_view uri) {
bool SOMASparseNDArray::exists(
std::string_view uri, std::shared_ptr<SOMAContext> ctx) {
try {
auto obj = SOMAObject::open(
uri, OpenMode::read, std::make_shared<SOMAContext>());
auto obj = SOMAObject::open(uri, OpenMode::read, ctx);
return "SOMASparseNDArray" == obj->type();
} catch (TileDBSOMAError& e) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions libtiledbsoma/src/soma/soma_sparse_ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class SOMASparseNDArray : public SOMAArray {
/**
* @brief Check if the SOMASparseNDArray exists at the URI.
*
* @param uri URI to create the SOMASparseNDArray
* @param ctx SOMAContext
*/
static bool exists(std::string_view uri);
static bool exists(std::string_view uri, std::shared_ptr<SOMAContext> ctx);

//===================================================================
//= public non-static
Expand Down
6 changes: 6 additions & 0 deletions libtiledbsoma/test/unit_soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ TEST_CASE("SOMADataFrame: basic") {
auto ctx = std::make_shared<SOMAContext>();
std::string uri = "mem://unit-test-dataframe-basic";

REQUIRE(!SOMADataFrame::exists(uri, ctx));

auto [schema, index_columns] = helper::create_arrow_schema();
SOMADataFrame::create(
uri,
Expand All @@ -44,6 +46,10 @@ TEST_CASE("SOMADataFrame: basic") {
std::move(index_columns.first), std::move(index_columns.second)),
ctx);

REQUIRE(SOMADataFrame::exists(uri, ctx));
REQUIRE(!SOMASparseNDArray::exists(uri, ctx));
REQUIRE(!SOMADenseNDArray::exists(uri, ctx));

auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::read, ctx);
REQUIRE(soma_dataframe->uri() == uri);
REQUIRE(soma_dataframe->ctx() == ctx);
Expand Down
6 changes: 6 additions & 0 deletions libtiledbsoma/test/unit_soma_dense_ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ TEST_CASE("SOMADenseNDArray: basic") {
auto ctx = std::make_shared<SOMAContext>();
std::string uri = "mem://unit-test-dense-ndarray-basic";

REQUIRE(!SOMADenseNDArray::exists(uri, ctx));

auto index_columns = helper::create_column_index_info();
SOMADenseNDArray::create(
uri,
Expand All @@ -46,6 +48,10 @@ TEST_CASE("SOMADenseNDArray: basic") {
PlatformConfig(),
TimestampRange(0, 2));

REQUIRE(SOMADenseNDArray::exists(uri, ctx));
REQUIRE(!SOMADataFrame::exists(uri, ctx));
REQUIRE(!SOMASparseNDArray::exists(uri, ctx));

auto soma_dense = SOMADenseNDArray::open(uri, OpenMode::read, ctx);
REQUIRE(soma_dense->uri() == uri);
REQUIRE(soma_dense->ctx() == ctx);
Expand Down
6 changes: 6 additions & 0 deletions libtiledbsoma/test/unit_soma_sparse_ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ TEST_CASE("SOMASparseNDArray: basic") {
auto ctx = std::make_shared<SOMAContext>();
std::string uri = "mem://unit-test-sparse-ndarray-basic";

REQUIRE(!SOMASparseNDArray::exists(uri, ctx));

auto index_columns = helper::create_column_index_info();
SOMASparseNDArray::create(
uri,
Expand All @@ -46,6 +48,10 @@ TEST_CASE("SOMASparseNDArray: basic") {
PlatformConfig(),
TimestampRange(0, 2));

REQUIRE(SOMASparseNDArray::exists(uri, ctx));
REQUIRE(!SOMADataFrame::exists(uri, ctx));
REQUIRE(!SOMADenseNDArray::exists(uri, ctx));

auto soma_sparse = SOMASparseNDArray::open(uri, OpenMode::read, ctx);
REQUIRE(soma_sparse->uri() == uri);
REQUIRE(soma_sparse->ctx() == ctx);
Expand Down

0 comments on commit d9b6470

Please sign in to comment.