Skip to content

Commit 647f526

Browse files
support dimension domains that don't start from 0
1 parent cccbe44 commit 647f526

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

test/src/unit-cppapi-max-fragment-size.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,12 @@ TEST_CASE(
614614
cleanup();
615615

616616
// Remove the array at the end of this test.
617-
// ScopedExecutor deferred(cleanup);
617+
ScopedExecutor deferred(cleanup);
618618

619619
// Create an array with exactly 9 tiles and tile extend 1
620620
Domain domain(ctx);
621621
ArraySchema schema(ctx, TILEDB_DENSE);
622-
auto d1 = tiledb::Dimension::create<int32_t>(ctx, "d1", {{0, 8}}, 3);
622+
auto d1 = tiledb::Dimension::create<int32_t>(ctx, "d1", {{1, 9}}, 3);
623623
domain.add_dimension(d1);
624624

625625
auto a1 = tiledb::Attribute::create<int32_t>(ctx, "a");
@@ -632,7 +632,7 @@ TEST_CASE(
632632

633633
// Populate array with data from 1 to 9
634634
int value = 0;
635-
for (int i = 0; i < 9; i += 3) {
635+
for (int i = 1; i < 10; i += 3) {
636636
Array array(ctx, array_name, TILEDB_WRITE);
637637
Query query(ctx, array);
638638
query.set_layout(TILEDB_ROW_MAJOR);
@@ -650,7 +650,7 @@ TEST_CASE(
650650

651651
Array array(ctx, array_name, TILEDB_READ);
652652
tiledb::Subarray sub(ctx, array);
653-
sub.set_subarray({0, 8});
653+
sub.set_subarray({1, 9});
654654
std::vector<int32_t> a(9);
655655
Query query(ctx, array, TILEDB_READ);
656656
query.set_subarray(sub).set_layout(TILEDB_ROW_MAJOR).set_data_buffer("a", a);
@@ -675,7 +675,7 @@ TEST_CASE(
675675
// Read data to validate correctness
676676
Array array2(ctx, array_name, TILEDB_READ);
677677
tiledb::Subarray sub2(ctx, array2);
678-
sub2.set_subarray({0, 8});
678+
sub2.set_subarray({1, 9});
679679
std::vector<int32_t> a2(9);
680680
Query query2(ctx, array2, TILEDB_READ);
681681
query2.set_subarray(sub2)

tiledb/sm/query/writers/global_order_writer.cc

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ GlobalOrderWriter::GlobalOrderWriter(
9595
, processed_conditions_(processed_conditions)
9696
, fragment_size_(fragment_size)
9797
, current_fragment_size_(0)
98-
, rows_written_(0) {
98+
, rows_written_(0)
99+
, start_(0) {
99100
// Check the layout is global order.
100101
if (layout_ != Layout::GLOBAL_ORDER) {
101102
throw GlobalOrderWriterException(
@@ -1464,16 +1465,6 @@ NDRange GlobalOrderWriter::ndranges_after_split(uint64_t num) {
14641465

14651466
// Calculate how many tiles each row can hold
14661467
uint64_t tiles_per_row = num_tiles_per_row(domain);
1467-
auto dim_num = domain.dim_num();
1468-
auto dim{domain.dimension_ptr(0)};
1469-
1470-
auto l = [&](auto T) {
1471-
return static_cast<uint64_t>(dim->tile_extent().rvalue_as<decltype(T)>());
1472-
};
1473-
1474-
uint64_t tile_extent = apply_with_type(l, dim->type());
1475-
NDRange nd;
1476-
nd.reserve(dim_num);
14771468

14781469
if (num % tiles_per_row != 0) {
14791470
throw GlobalOrderWriterException(
@@ -1485,13 +1476,33 @@ NDRange GlobalOrderWriter::ndranges_after_split(uint64_t num) {
14851476
// Calculate how many rows we will write in the current fragment
14861477
uint64_t rows_of_tiles_to_write = num / tiles_per_row;
14871478

1488-
// Create the range for the index dim (first).
1489-
int start = rows_written_ * tile_extent;
1490-
int end = start + (rows_of_tiles_to_write * tile_extent) - 1;
1491-
Range range(&start, &end, sizeof(int));
1479+
// Create NDRange object and reserve for dims
1480+
auto dim_num = domain.dim_num();
1481+
NDRange nd;
1482+
nd.reserve(dim_num);
1483+
1484+
// Calculate the range for the index dim (first).
1485+
auto dim{domain.dimension_ptr(0)};
1486+
auto dim_dom = dim->domain();
1487+
auto l = [&](auto T) {
1488+
return static_cast<uint64_t>(dim->tile_extent().rvalue_as<decltype(T)>());
1489+
};
1490+
uint64_t tile_extent = apply_with_type(l, dim->type());
1491+
1492+
// Calculate start and end
1493+
if (rows_written_ == 0) {
1494+
// It means that the start has not been set yet. Set it to the minimum value
1495+
// of the expanded domain for that dim
1496+
auto dim_dom_data = (const uint64_t*)dim_dom.data();
1497+
start_ = dim_dom_data[0];
1498+
}
1499+
uint64_t end = start_ + (rows_of_tiles_to_write * tile_extent) - 1;
1500+
1501+
// Add range
1502+
Range range(&start_, &end, sizeof(int));
14921503
nd.emplace_back(range);
14931504

1494-
// Use the domain as ranges for the rest of the dims
1505+
// For the rest of the dims, use their domains as ranges. No split there.
14951506
for (unsigned d = 1; d < dim_num; ++d) {
14961507
// begin from second dim
14971508
auto dim{array_schema_.dimension_ptr(d)};
@@ -1501,6 +1512,7 @@ NDRange GlobalOrderWriter::ndranges_after_split(uint64_t num) {
15011512

15021513
// add rows written to the cache
15031514
rows_written_ += rows_of_tiles_to_write;
1515+
start_ = end + 1;
15041516

15051517
return nd;
15061518
}

tiledb/sm/query/writers/global_order_writer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ class GlobalOrderWriter : public WriterBase {
221221
*/
222222
uint64_t rows_written_;
223223

224+
/**
225+
* This is the start for the dim range in case we need to split in multiple
226+
* fragments in Dense arrays
227+
*/
228+
uint64_t start_;
229+
224230
/* ********************************* */
225231
/* PRIVATE METHODS */
226232
/* ********************************* */

0 commit comments

Comments
 (0)