Skip to content

Commit

Permalink
Add subarray range expansion regression test
Browse files Browse the repository at this point in the history
This regression test demonstrates a bug in the subrray range logic when
a range has been expanded.
  • Loading branch information
davisp committed Aug 28, 2024
1 parent 1103f51 commit aa1fc4e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if (TILEDB_CPP_API)
list(APPEND SOURCES targets/sc-38300.cc)
list(APPEND SOURCES targets/sc-52975.cc)
list(APPEND SOURCES targets/sc-53334.cc)
list(APPEND SOURCES targets/sc-53970.cc)
endif()

add_executable(tiledb_regression
Expand Down
99 changes: 99 additions & 0 deletions test/regression/targets/sc-53970.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <climits>

#include <tiledb/tiledb>
#include <tiledb/tiledb_experimental>

#include <arm/types.h>
#include <test/support/tdb_catch.h>

using namespace tiledb;

static void create_array(const std::string& array_uri);
static void write_array(const std::string& array_uri);

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

// Test setup
create_array(array_uri);
write_array(array_uri);

Context ctx;
Array array(ctx, array_uri, TILEDB_READ);

std::vector<int64_t> dim = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
std::vector<float> attr = {
-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0};

Query query(ctx, array, TILEDB_READ);

Config cfg;
cfg["sm.var_offsets.bitsize"] = "64";
cfg["sm.var_offsets.mode"] = "elements";
cfg["sm.var_offsets.extra_element"] = "true";
query.set_config(cfg);

int64_t range1[] = {-1374262780975110845, -1374262780975110845};
int64_t range2[] = {-6603679540125901718, 0};

Subarray subarray(ctx, array);
subarray.add_range(0, range1[0], range1[1])
.add_range(0, range2[0], range2[1]);

query.set_layout(TILEDB_UNORDERED)
.set_subarray(subarray)
.set_data_buffer("dim", dim)
.set_data_buffer("attr", attr);
REQUIRE(query.submit() == Query::Status::COMPLETE);

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

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

void create_array(const std::string& array_uri) {
Context ctx;

auto obj = Object::object(ctx, array_uri);
if (obj.type() != Object::Type::Invalid) {
Object::remove(ctx, array_uri);
}

auto dim =
Dimension::create<int64_t>(ctx, "dim", {{INT64_MIN, INT64_MAX - 1}});

Domain dom(ctx);
dom.add_dimension(dim);

auto attr = Attribute::create<float>(ctx, "attr");

ArraySchema schema(ctx, TILEDB_SPARSE);

schema.set_order({{TILEDB_COL_MAJOR, TILEDB_COL_MAJOR}})
.set_domain(dom)
.add_attribute(attr)
.set_capacity(1713)
.set_allows_dups(true);

Array::create(array_uri, schema);
}

void write_array(const std::string& array_uri) {
Context ctx;
Array array(ctx, array_uri, TILEDB_WRITE);
Query query(ctx, array, TILEDB_WRITE);

std::vector<int64_t> dim = {0, -8672700570587565350};
std::vector<float> attr = {1507468.6, -0};

query.set_layout(TILEDB_UNORDERED)
.set_data_buffer("dim", dim)
.set_data_buffer("attr", attr);
REQUIRE(query.submit() == Query::Status::COMPLETE);
}

0 comments on commit aa1fc4e

Please sign in to comment.