Skip to content

Commit 9156e5d

Browse files
davispKiterLuc
andauthored
Add subarray range expansion regression test. (#5267)
This regression test demonstrates a bug in the subrray range logic when a range has been expanded. [sc-53970] --- TYPE: NO_HISTORY DESC: Add subarray range expansion regression test. --------- Co-authored-by: KiterLuc <[email protected]> Co-authored-by: Luc Rancourt <[email protected]>
1 parent 223aad8 commit 9156e5d

File tree

4 files changed

+130
-5
lines changed

4 files changed

+130
-5
lines changed

test/regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ if (TILEDB_CPP_API)
5454
list(APPEND SOURCES targets/sc-52975.cc)
5555
list(APPEND SOURCES targets/sc-53334.cc)
5656
list(APPEND SOURCES targets/sc-53791.cc)
57+
list(APPEND SOURCES targets/sc-53970.cc)
5758
endif()
5859

5960
add_executable(tiledb_regression

test/regression/targets/sc-52975.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ std::vector<uint8_t> get_attr_validity();
4747
std::vector<std::pair<int8_t, int8_t>> get_subarrays();
4848

4949
TEST_CASE(
50-
"PJD: Attempt to reproduce bug",
51-
"[reproducer][bug][scXXXXX][!shouldfail]") {
50+
"SC-52975: Subarray values lead to incorrect read.",
51+
"[reproducer][bug][sc52975][!shouldfail]") {
5252
std::string array_uri = "test_reproducer";
5353

5454
std::size_t successes = 0;

test/regression/targets/sc-53334.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
* THE SOFTWARE.
2727
*
2828
* @section DESCRIPTION
29-
*
30-
* When run, this program will create a simple 2D sparse array, write some data
31-
* to it in global order, and read the data back with aggregates.
3229
*/
3330

3431
#include <stdio.h>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* @file sc-53970.cc
3+
*
4+
* @section LICENSE
5+
*
6+
* The MIT License
7+
*
8+
* @copyright Copyright (c) 2024 TileDB, Inc.
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in
18+
* all copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
* THE SOFTWARE.
27+
*
28+
* @section DESCRIPTION
29+
*/
30+
#include <climits>
31+
32+
#include <tiledb/tiledb>
33+
#include <tiledb/tiledb_experimental>
34+
35+
#include <test/support/tdb_catch.h>
36+
37+
using namespace tiledb;
38+
39+
static void create_array(const std::string& array_uri);
40+
static void write_array(const std::string& array_uri);
41+
42+
TEST_CASE(
43+
"Subarray range expansion bug",
44+
"[bug][sc53970][subarray-range-expansion][!shouldfail]") {
45+
std::string array_uri = "test_array_schema_dump";
46+
47+
// Test setup
48+
create_array(array_uri);
49+
write_array(array_uri);
50+
51+
Context ctx;
52+
Array array(ctx, array_uri, TILEDB_READ);
53+
54+
std::vector<int64_t> dim = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
55+
std::vector<float> attr = {
56+
-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
57+
58+
Query query(ctx, array, TILEDB_READ);
59+
60+
Config cfg;
61+
cfg["sm.var_offsets.bitsize"] = "64";
62+
cfg["sm.var_offsets.mode"] = "elements";
63+
cfg["sm.var_offsets.extra_element"] = "true";
64+
query.set_config(cfg);
65+
66+
int64_t range1[] = {-1374262780975110845, -1374262780975110845};
67+
int64_t range2[] = {-6603679540125901718, 0};
68+
69+
Subarray subarray(ctx, array);
70+
subarray.add_range(0, range1[0], range1[1])
71+
.add_range(0, range2[0], range2[1]);
72+
73+
query.set_layout(TILEDB_UNORDERED)
74+
.set_subarray(subarray)
75+
.set_data_buffer("dim", dim)
76+
.set_data_buffer("attr", attr);
77+
REQUIRE(query.submit() == Query::Status::COMPLETE);
78+
79+
// The expected result are a single matching cell of (0, 1507468.6)
80+
REQUIRE(dim[0] == 0);
81+
REQUIRE(abs(attr[0] - 1507468.6) < 0.00000005);
82+
83+
// Check we didn't get any extra results
84+
REQUIRE(dim[1] == -1);
85+
REQUIRE(attr[1] == -1.0);
86+
}
87+
88+
void create_array(const std::string& array_uri) {
89+
Context ctx;
90+
91+
auto obj = Object::object(ctx, array_uri);
92+
if (obj.type() != Object::Type::Invalid) {
93+
Object::remove(ctx, array_uri);
94+
}
95+
96+
auto dim =
97+
Dimension::create<int64_t>(ctx, "dim", {{INT64_MIN, INT64_MAX - 1}});
98+
99+
Domain dom(ctx);
100+
dom.add_dimension(dim);
101+
102+
auto attr = Attribute::create<float>(ctx, "attr");
103+
104+
ArraySchema schema(ctx, TILEDB_SPARSE);
105+
106+
schema.set_order({{TILEDB_COL_MAJOR, TILEDB_COL_MAJOR}})
107+
.set_domain(dom)
108+
.add_attribute(attr)
109+
.set_capacity(1713)
110+
.set_allows_dups(true);
111+
112+
Array::create(array_uri, schema);
113+
}
114+
115+
void write_array(const std::string& array_uri) {
116+
Context ctx;
117+
Array array(ctx, array_uri, TILEDB_WRITE);
118+
Query query(ctx, array, TILEDB_WRITE);
119+
120+
std::vector<int64_t> dim = {0, -8672700570587565350};
121+
std::vector<float> attr = {1507468.6f, -0.0f};
122+
123+
query.set_layout(TILEDB_UNORDERED)
124+
.set_data_buffer("dim", dim)
125+
.set_data_buffer("attr", attr);
126+
REQUIRE(query.submit() == Query::Status::COMPLETE);
127+
}

0 commit comments

Comments
 (0)