Skip to content

Commit

Permalink
Fixed bug with sparse global order writes when the buffer sizes are zero
Browse files Browse the repository at this point in the history
PR #1248

(cherry picked from commit df093f1)
  • Loading branch information
stavrospapadopoulos authored and tdenniston committed May 16, 2019
1 parent 546e57a commit a063556
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
59 changes: 58 additions & 1 deletion test/src/unit-capi-sparse_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2770,4 +2770,61 @@ TEST_CASE_METHOD(
check_sorted_reads(
array_name, TILEDB_FILTER_BZIP2, TILEDB_ROW_MAJOR, TILEDB_COL_MAJOR);
}
}
}

TEST_CASE_METHOD(
SparseArrayFx,
"C API: Test sparse array, global order with 0-sized buffers",
"[capi][sparse][global-check][zero-buffers]") {
std::string array_name =
FILE_URI_PREFIX + FILE_TEMP_DIR + "sparse_write_global_check";
create_sparse_array(array_name);

// Create TileDB context
tiledb_ctx_t* ctx = nullptr;
REQUIRE(tiledb_ctx_alloc(nullptr, &ctx) == TILEDB_OK);

// 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 WRITE 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);

// Prepare attribute buffers
int a1[1];
char a2[1];
uint64_t a2_off[1];
float a3[1];
uint64_t coords[1];
uint64_t zero_size = 0;

// Set buffers with zero size
rc = tiledb_query_set_buffer(ctx, query, "a1", a1, &zero_size);
CHECK(rc == TILEDB_OK);
rc = tiledb_query_set_buffer_var(
ctx, query, "a2", a2_off, &zero_size, a2, &zero_size);
CHECK(rc == TILEDB_OK);
rc = tiledb_query_set_buffer(ctx, query, "a3", a3, &zero_size);
CHECK(rc == TILEDB_OK);
rc = tiledb_query_set_buffer(ctx, query, TILEDB_COORDS, coords, &zero_size);
CHECK(rc == TILEDB_OK);

// Submit query
CHECK(tiledb_query_submit(ctx, query) == TILEDB_OK);

// Close array
CHECK(tiledb_array_close(ctx, array) == TILEDB_OK);

// Clean up
tiledb_query_free(&query);
tiledb_array_free(&array);
tiledb_ctx_free(&ctx);
}
12 changes: 12 additions & 0 deletions tiledb/sm/query/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ Status Writer::check_coord_dups(const std::vector<uint64_t>& cell_pos) const {
auto coords_size = array_schema_->coords_size();
auto coords_num = cell_pos.size();

if (coords_num < 2)
return Status::Ok();

for (uint64_t i = 1; i < coords_num; ++i) {
if (!memcmp(
coords_buff + cell_pos[i] * coords_size,
Expand Down Expand Up @@ -456,6 +459,9 @@ Status Writer::check_coord_dups() const {
auto coords_size = array_schema_->coords_size();
auto coords_num = coords_buff_size / coords_size;

if (coords_num < 2)
return Status::Ok();

for (uint64_t i = 1; i < coords_num; ++i) {
if (!memcmp(
coords_buff + i * coords_size,
Expand Down Expand Up @@ -526,6 +532,9 @@ Status Writer::check_coord_oob() const {
auto dim_num = array_schema_->dim_num();
auto domain = (T*)array_schema_->domain()->domain();

if (coords_num == 0)
return Status::Ok();

// Check if all coordinates fall in the domain in parallel
auto statuses = parallel_for(0, coords_num, [&](uint64_t i) {
if (!utils::geometry::coords_in_rect<T>(
Expand Down Expand Up @@ -609,6 +618,9 @@ Status Writer::check_global_order() const {
auto dim_num = array_schema_->dim_num();
auto domain = array_schema_->domain();

if (coords_num < 2)
return Status::Ok();

// Check if all coordinates fall in the domain in parallel
auto statuses = parallel_for(0, coords_num - 1, [&](uint64_t i) {
auto tile_cmp = domain->tile_order_cmp<T>(
Expand Down

0 comments on commit a063556

Please sign in to comment.