Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] Update dataframe unit-test writes in prep for polytype domainish accessors #3017

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions libtiledbsoma/test/unit_soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ struct VariouslyIndexedDataFrameFixture {
{.name = str_name, .tiledb_datatype = str_datatype});
}

std::vector<int64_t> make_i64_data() {
return std::vector<int64_t>({1, 2});
}
std::vector<uint32_t> make_u32_data() {
return std::vector<uint32_t>({1234, 5678});
}
std::vector<std::string> make_str_data() {
return std::vector<std::string>({"apple", "bat"});
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Helper methods for create/open/write/etc.

Expand Down Expand Up @@ -173,14 +163,30 @@ struct VariouslyIndexedDataFrameFixture {
auto soma_dataframe = SOMADataFrame::open(uri_, OpenMode::write, ctx_);

auto i64_data = std::vector<int64_t>({sjid_base + 1, sjid_base + 2});

auto u32_data = std::vector<uint32_t>({1234, 5678});
auto str_data = std::vector<std::string>({"apple", "bat"});
auto str_offsets = std::vector<uint64_t>({0, 5, 8});

// We like to think we're writing an array of strings ...
auto strings = std::vector<std::string>({"apple", "bat"});
// ... but really we're writing an array of characters along
// with offsets data.
//
// It would be possible here to just hard-code a string "applebat" and
// an offsets array {0, 5, 8}. The following bits simply automate that.
std::string char_data("");
std::vector<uint64_t> char_offsets(0);
uint64_t offset = 0;
for (auto e : strings) {
char_data += e;
char_offsets.push_back(offset);
offset += e.size();
}
char_offsets.push_back(offset);

soma_dataframe->set_column_data(
i64_name, i64_data.size(), i64_data.data());
soma_dataframe->set_column_data(
str_name, str_data.size(), str_data.data(), str_offsets.data());
str_name, strings.size(), char_data.data(), char_offsets.data());
soma_dataframe->set_column_data(
u32_name, u32_data.size(), u32_data.data());
soma_dataframe->write();
Expand Down
Loading