Skip to content

Commit 7fd6328

Browse files
bekadavis9KiterLuc
andauthored
Bug fix: update range end when merging overlapping subarray ranges. (#5268)
Bug fix: update range end when merging overlapping subarray ranges. Previously, when merging overlapping ranges, the new range end would _always_ be updated to that of the merged range. This was a _clear_ issue if one range was fully encompassed within another. For example, if range `{3, 4}` were merged into `{1, 10}`, the old behavior would produce a new range of `{1, 4}`. This PR fixes the bug simply, taking the larger of the two range ends on merge. [sc-53970] --- TYPE: BUG DESC: Update range end when merging overlapping subarray ranges. --------- Co-authored-by: KiterLuc <[email protected]> Co-authored-by: Luc Rancourt <[email protected]>
1 parent 84ff80c commit 7fd6328

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

test/regression/targets/sc-53970.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void write_array(const std::string& array_uri);
4141

4242
TEST_CASE(
4343
"Subarray range expansion bug",
44-
"[bug][sc53970][subarray-range-expansion][!shouldfail]") {
44+
"[bug][sc53970][subarray-range-expansion]") {
4545
std::string array_uri = "test_array_schema_dump";
4646

4747
// Test setup
@@ -78,7 +78,7 @@ TEST_CASE(
7878

7979
// The expected result are a single matching cell of (0, 1507468.6)
8080
REQUIRE(dim[0] == 0);
81-
REQUIRE(abs(attr[0] - 1507468.6) < 0.00000005);
81+
REQUIRE(abs(attr[0] - 1507468.6f) < 0.00000005);
8282

8383
// Check we didn't get any extra results
8484
REQUIRE(dim[1] == -1);

tiledb/sm/subarray/range_subset.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2017-2023 TileDB, Inc.
8+
* @copyright Copyright (c) 2017-2024 TileDB, Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -169,7 +169,10 @@ struct MergeStrategy<
169169
tail->start_as<T>() <= head_end;
170170

171171
if (can_merge) {
172-
head->set_end_fixed(tail->end_fixed());
172+
// Only update the end if the merging end is greater.
173+
if (tail->end_as<T>() > head->end_as<T>()) {
174+
head->set_end_fixed(tail->end_fixed());
175+
}
173176
merged_cells++;
174177
} else {
175178
head++;

tiledb/sm/subarray/test/unit_range_subset.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,36 @@ TEMPLATE_TEST_CASE_SIG(
528528
check_subset_range_values(range_subset, 3, data3[0], data3[1]);
529529
}
530530
}
531+
532+
SECTION("Overlapping, encompassing ranges") {
533+
// Note: this test is intended to duplicate regression test sc-53970,
534+
// validating that a range which is fully encompassed within another
535+
// will merge as expected.
536+
537+
// Add ranges.
538+
T data1[2] = {3, 3};
539+
T data2[2] = {1, 10};
540+
std::vector<Range> ranges = {
541+
Range(data1, 2 * sizeof(T)), Range(data2, 2 * sizeof(T))};
542+
for (auto range : ranges) {
543+
range_subset.add_range(range);
544+
}
545+
CHECK(range_subset.num_ranges() == 2);
546+
547+
// Sort and merge ranges.
548+
ThreadPool pool{2};
549+
range_subset.sort_and_merge_ranges(&pool, merge);
550+
551+
// Check range results.
552+
if (merge) {
553+
CHECK(range_subset.num_ranges() == 1);
554+
check_subset_range_values(range_subset, 0, data2[0], data2[1]);
555+
} else {
556+
CHECK(range_subset.num_ranges() == 2);
557+
check_subset_range_values(range_subset, 0, data2[0], data2[1]);
558+
check_subset_range_values(range_subset, 1, data1[0], data1[1]);
559+
}
560+
}
531561
}
532562

533563
TEST_CASE(

0 commit comments

Comments
 (0)