Skip to content

Commit

Permalink
Merge pull request #1615 from TileDB-Inc/ss/fix-global-order-write-se…
Browse files Browse the repository at this point in the history
…cond-pass

Fix global order writes setting additional buffers
  • Loading branch information
Shelnutt2 committed Apr 27, 2020
2 parents 0cfb85b + 1fb695f commit 4b4b502
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 1 deletion.
136 changes: 136 additions & 0 deletions test/src/unit-capi-sparse_array.cc
Expand Up @@ -6866,4 +6866,140 @@ TEST_CASE_METHOD(
tiledb_query_free(&query);

remove_array(array_name);
}

TEST_CASE_METHOD(
SparseArrayFx,
"Sparse array: 2D, multi write global order",
"[capi][sparse][2D][multi-write]") {
// Create and write array
std::string array_name =
FILE_URI_PREFIX + FILE_TEMP_DIR + "sparse_split_coords_read_subset";
create_sparse_array(array_name);

std::vector<uint64_t> d1 = {1, 1, 2, 2};
uint64_t d1_size = d1.size() * sizeof(uint64_t);
std::vector<uint64_t> d2 = {1, 2, 1, 2};
uint64_t d2_size = d2.size() * sizeof(uint64_t);
std::vector<int> a1 = {1, 2, 3, 4};
uint64_t a1_size = a1.size() * sizeof(int);
std::vector<uint64_t> a2_off = {
0, sizeof(char), 3 * sizeof(char), 6 * sizeof(char)};

uint64_t a2_off_size = a2_off.size() * sizeof(uint64_t);
std::vector<char> a2_val = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd'};
uint64_t a2_val_size = a2_val.size() * sizeof(char);
std::vector<float> a3 = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f};
uint64_t a3_size = a3.size() * sizeof(float);
tiledb::test::QueryBuffers buffers;
buffers["d1"] = tiledb::test::QueryBuffer({&d1[0], d1_size, nullptr, 0});
buffers["d2"] = tiledb::test::QueryBuffer({&d2[0], d2_size, nullptr, 0});
buffers["a1"] = tiledb::test::QueryBuffer({&a1[0], a1_size, nullptr, 0});
buffers["a2"] = tiledb::test::QueryBuffer(
{&a2_off[0], a2_off_size, &a2_val[0], a2_val_size});
buffers["a3"] = tiledb::test::QueryBuffer({&a3[0], a3_size, nullptr, 0});

// Open array
tiledb_array_t* array;
int rc = tiledb_array_alloc(ctx_, array_name.c_str(), &array);
CHECK(rc == TILEDB_OK);
rc = tiledb_array_open(ctx_, array, TILEDB_WRITE);
CHECK(rc == TILEDB_OK);

// Create query
tiledb_query_t* query;
rc = tiledb_query_alloc(ctx_, array, TILEDB_WRITE, &query);
CHECK(rc == TILEDB_OK);
rc = tiledb_query_set_layout(ctx_, query, TILEDB_GLOBAL_ORDER);
CHECK(rc == TILEDB_OK);

// Set buffers
for (const auto& b : buffers) {
if (b.second.var_ == nullptr) { // Fixed-sized
rc = tiledb_query_set_buffer(
ctx_,
query,
b.first.c_str(),
b.second.fixed_,
(uint64_t*)&(b.second.fixed_size_));
CHECK(rc == TILEDB_OK);
} else { // Var-sized
rc = tiledb_query_set_buffer_var(
ctx_,
query,
b.first.c_str(),
(uint64_t*)b.second.fixed_,
(uint64_t*)&(b.second.fixed_size_),
b.second.var_,
(uint64_t*)&(b.second.var_size_));
CHECK(rc == TILEDB_OK);
}
}

// Submit query
rc = tiledb_query_submit(ctx_, query);
CHECK(rc == TILEDB_OK);

// Create new buffers of smaller size to test being able to write multiple
// buffer sizes
std::vector<uint64_t> d1_2 = {3, 3};
uint64_t d1_size_2 = d1_2.size() * sizeof(uint64_t);
std::vector<uint64_t> d2_2 = {1, 2};
uint64_t d2_size_2 = d2_2.size() * sizeof(uint64_t);

std::vector<int> a1_2 = {5, 6};
uint64_t a1_size_2 = a1_2.size() * sizeof(int);
std::vector<uint64_t> a2_off_2 = {0, 2 * sizeof(char)};

uint64_t a2_off_size_2 = a2_off_2.size() * sizeof(uint64_t);
std::vector<char> a2_val_2 = {'e', 'e', 'f', 'f', 'f', 'f'};
uint64_t a2_val_size_2 = a2_val_2.size() * sizeof(char);
std::vector<float> a3_2 = {5.1f, 5.2f, 6.1f, 6.2f};
uint64_t a3_size_2 = a3_2.size() * sizeof(float);
tiledb::test::QueryBuffers buffers2;
buffers2["d1"] = tiledb::test::QueryBuffer({&d1_2[0], d1_size_2, nullptr, 0});
buffers2["d2"] = tiledb::test::QueryBuffer({&d2_2[0], d2_size_2, nullptr, 0});
buffers2["a1"] = tiledb::test::QueryBuffer({&a1_2[0], a1_size_2, nullptr, 0});
buffers2["a2"] = tiledb::test::QueryBuffer(
{&a2_off_2[0], a2_off_size_2, &a2_val_2[0], a2_val_size_2});
buffers2["a3"] = tiledb::test::QueryBuffer({&a3_2[0], a3_size_2, nullptr, 0});

// Set buffers
for (const auto& b : buffers2) {
if (b.second.var_ == nullptr) { // Fixed-sized
rc = tiledb_query_set_buffer(
ctx_,
query,
b.first.c_str(),
b.second.fixed_,
(uint64_t*)&(b.second.fixed_size_));
CHECK(rc == TILEDB_OK);
} else { // Var-sized
rc = tiledb_query_set_buffer_var(
ctx_,
query,
b.first.c_str(),
(uint64_t*)b.second.fixed_,
(uint64_t*)&(b.second.fixed_size_),
b.second.var_,
(uint64_t*)&(b.second.var_size_));
CHECK(rc == TILEDB_OK);
}
}

// Submit query
rc = tiledb_query_submit(ctx_, query);
CHECK(rc == TILEDB_OK);

// Finalize query
rc = tiledb_query_finalize(ctx_, query);
CHECK(rc == TILEDB_OK);

// Close array
rc = tiledb_array_close(ctx_, array);
CHECK(rc == TILEDB_OK);

// Clean up
tiledb_array_free(&array);
tiledb_query_free(&query);
}
10 changes: 9 additions & 1 deletion tiledb/sm/query/writer.cc
Expand Up @@ -1348,8 +1348,12 @@ Status Writer::global_write() {
}

// No cells to be written
if (tile_num == 0)
if (tile_num == 0) {
// reset coord buffer marker at end of global write
// this will allow for the user to properly set the next write batch
coord_buffer_is_set_ = false;
return Status::Ok();
}

// Set new number of tiles in the fragment metadata
auto new_num_tiles = frag_meta->tile_index_base() + tile_num;
Expand All @@ -1368,6 +1372,10 @@ Status Writer::global_write() {
// Increment the tile index base for the next global order write.
frag_meta->set_tile_index_base(new_num_tiles);

// reset coord buffer marker at end of global write
// this will allow for the user to properly set the next write batch
coord_buffer_is_set_ = false;

return Status::Ok();
}

Expand Down

0 comments on commit 4b4b502

Please sign in to comment.