Skip to content

Commit

Permalink
iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Aug 30, 2024
1 parent 4ec86e8 commit cc30a6b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
7 changes: 7 additions & 0 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,13 @@ class SOMAArray : public SOMAObject {
*/
std::optional<TimestampRange> timestamp();

/**
* Exposed for testing purposes.
*/
CurrentDomain get_current_domain() {
return _get_current_domain();
}

private:
//===================================================================
//= private non-static
Expand Down
5 changes: 2 additions & 3 deletions libtiledbsoma/src/utils/arrow_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,8 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema(
// nullptr)
//
// Fortunately, these are ASCII dims and we can range
// these accordingly. These are minimum and maximum
// values, avoiding the extremes 0x00 and 0xff.
ndrect.set_range(col_name, "\x01", "\xfe");
// these accordingly.
ndrect.set_range(col_name, "", "\xff");
} else {
const void* buff = index_column_array->children[i]
->buffers[1];
Expand Down
63 changes: 57 additions & 6 deletions libtiledbsoma/test/unit_soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ TEST_CASE("SOMADataFrame: variant-indexed dataframe 1") {
helper::create_arrow_schema_and_index_columns(
dim_infos, attr_infos);

// Create
SOMADataFrame::create(
uri,
std::move(schema),
Expand All @@ -437,7 +438,27 @@ TEST_CASE("SOMADataFrame: variant-indexed dataframe 1") {
std::move(index_columns.second)),
ctx);

auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::write, ctx);
// Check current domain
auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::read, ctx);

CurrentDomain current_domain = soma_dataframe->get_current_domain();
if (!use_current_domain) {
REQUIRE(current_domain.is_empty());
} else {
REQUIRE(!current_domain.is_empty());
REQUIRE(current_domain.type() == TILEDB_NDRECTANGLE);
NDRectangle ndrect = current_domain.ndrectangle();

std::array<int64_t, 2> dim_1_range = ndrect.range<int64_t>(
dim_1_name);
REQUIRE(dim_1_range[0] == (int64_t)0);
REQUIRE(dim_1_range[1] == (int64_t)soma_joinid_dim_max);
}

soma_dataframe->close();

// Write
soma_dataframe = SOMADataFrame::open(uri, OpenMode::write, ctx);

std::vector<int64_t> dim_1_data({1, 2});
std::vector<uint32_t> dim_2_data({1234, 5678});
Expand All @@ -455,15 +476,15 @@ TEST_CASE("SOMADataFrame: variant-indexed dataframe 1") {
}

TEST_CASE("SOMADataFrame: variant-indexed dataframe 2") {
LOG_SET_LEVEL("debug");
int64_t soma_joinid_dim_max = 100;
auto use_current_domain = GENERATE(false, true);
std::ostringstream section;
section << "- use_current_domain=" << use_current_domain;
SECTION(section.str()) {
// LOG_SET_LEVEL("debug");
auto ctx = std::make_shared<SOMAContext>();
std::string uri = "mem://unit-test-variant-indexed-dataframe-1";
// std::string uri = "/tmp/fooze";
// std::string uri = use_current_domain? "/tmp/fooze2" : "/tmp/fooze1";
std::string dim_1_name = "soma_joinid";
std::string dim_2_name = "mystring";
std::string attr_1_name = "myuint32";
Expand Down Expand Up @@ -492,6 +513,7 @@ TEST_CASE("SOMADataFrame: variant-indexed dataframe 2") {
helper::create_arrow_schema_and_index_columns(
dim_infos, attr_infos);

// Create
SOMADataFrame::create(
uri,
std::move(schema),
Expand All @@ -500,9 +522,39 @@ TEST_CASE("SOMADataFrame: variant-indexed dataframe 2") {
std::move(index_columns.second)),
ctx);

auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::write, ctx);
// Check current domain
auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::read, ctx);

CurrentDomain current_domain = soma_dataframe->get_current_domain();
if (!use_current_domain) {
REQUIRE(current_domain.is_empty());
} else {
REQUIRE(!current_domain.is_empty());
REQUIRE(current_domain.type() == TILEDB_NDRECTANGLE);
NDRectangle ndrect = current_domain.ndrectangle();

std::array<int64_t, 2> dim_1_range = ndrect.range<int64_t>(
dim_1_name);
REQUIRE(dim_1_range[0] == (int64_t)0);
REQUIRE(dim_1_range[1] == (int64_t)soma_joinid_dim_max);

std::array<std::string, 2> dim_2_range = ndrect.range<std::string>(
dim_2_name);
// Can we write ASCII values in this range?
REQUIRE(dim_2_range[0] < " ");
REQUIRE(dim_2_range[1] > "~");
// Can we write empty strings in this range?
REQUIRE(dim_2_range[0] <= "");
REQUIRE(dim_2_range[1] >= "");
}

soma_dataframe->close();

// Write
soma_dataframe = SOMADataFrame::open(uri, OpenMode::write, ctx);

std::vector<int64_t> dim_1_data({1, 2});
// std::vector<std::string> dim_2_data({"", ""});
std::vector<std::string> dim_2_data({"apple", "bat"});
std::vector<uint32_t> attr_1_data({1234, 5678});
soma_dataframe->set_column_data(
Expand All @@ -518,15 +570,14 @@ TEST_CASE("SOMADataFrame: variant-indexed dataframe 2") {
}

TEST_CASE("SOMADataFrame: variant-indexed dataframe 3") {
LOG_SET_LEVEL("debug");
int64_t other_dim_max = 10000;
auto use_current_domain = GENERATE(false, true);
std::ostringstream section;
section << "- use_current_domain=" << use_current_domain;
SECTION(section.str()) {
// LOG_SET_LEVEL("debug");
auto ctx = std::make_shared<SOMAContext>();
std::string uri = "mem://unit-test-variant-indexed-dataframe-1";
// std::string uri = "/tmp/fooze";
std::string dim_1_name = "mystring";
std::string dim_2_name = "myuint32";
std::string attr_1_name = "soma_joinid";
Expand Down

0 comments on commit cc30a6b

Please sign in to comment.