Skip to content

Commit 3129b29

Browse files
support dimension domains that don't start from 0
1 parent 35b0e9d commit 3129b29

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
@@ -613,12 +613,12 @@ TEST_CASE(
613613
cleanup();
614614

615615
// Remove the array at the end of this test.
616-
// ScopedExecutor deferred(cleanup);
616+
ScopedExecutor deferred(cleanup);
617617

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

624624
auto a1 = tiledb::Attribute::create<int32_t>(ctx, "a");
@@ -631,7 +631,7 @@ TEST_CASE(
631631

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

650650
Array array(ctx, array_name, TILEDB_READ);
651651
tiledb::Subarray sub(ctx, array);
652-
sub.set_subarray({0, 8});
652+
sub.set_subarray({1, 9});
653653
std::vector<int32_t> a(9);
654654
Query query(ctx, array, TILEDB_READ);
655655
query.set_subarray(sub).set_layout(TILEDB_ROW_MAJOR).set_data_buffer("a", a);
@@ -674,7 +674,7 @@ TEST_CASE(
674674
// Read data to validate correctness
675675
Array array2(ctx, array_name, TILEDB_READ);
676676
tiledb::Subarray sub2(ctx, array2);
677-
sub2.set_subarray({0, 8});
677+
sub2.set_subarray({1, 9});
678678
std::vector<int32_t> a2(9);
679679
Query query2(ctx, array2, TILEDB_READ);
680680
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
@@ -94,7 +94,8 @@ GlobalOrderWriter::GlobalOrderWriter(
9494
, processed_conditions_(processed_conditions)
9595
, fragment_size_(fragment_size)
9696
, current_fragment_size_(0)
97-
, rows_written_(0) {
97+
, rows_written_(0)
98+
, start_(0) {
9899
// Check the layout is global order.
99100
if (layout_ != Layout::GLOBAL_ORDER) {
100101
throw GlobalOrderWriterException(
@@ -1463,16 +1464,6 @@ NDRange GlobalOrderWriter::ndranges_after_split(uint64_t num) {
14631464

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

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

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

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

15011512
// add rows written to the cache
15021513
rows_written_ += rows_of_tiles_to_write;
1514+
start_ = end + 1;
15031515

15041516
return nd;
15051517
}

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)