Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show errant values in current-domain out-of-bounds error message #5421

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/src/test-cppapi-current-domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ TEST_CASE_METHOD(
CHECK_THROWS_WITH(
query_read2.submit(),
Catch::Matchers::ContainsSubstring(
"A range was set outside of the current domain."));
"was set outside of the current domain"));

tiledb::Query query_read3(ctx_, array_read, TILEDB_READ);
tiledb::Subarray subarray_read3(ctx_, array_read);
Expand All @@ -483,7 +483,7 @@ TEST_CASE_METHOD(
CHECK_THROWS_WITH(
query_read3.submit(),
Catch::Matchers::ContainsSubstring(
"A range was set outside of the current domain."));
"was set outside of the current domain"));

array_read.close();

Expand Down Expand Up @@ -588,7 +588,7 @@ TEST_CASE_METHOD(
.set_data_buffer("a", a_with_cd2)
.set_data_buffer("dim1", dim1_with_cd2);
auto matcher = Catch::Matchers::ContainsSubstring(
"A range was set outside of the current domain.");
"was set outside of the current domain");
REQUIRE_THROWS_WITH(query_for_cd2.submit(), matcher);
array_with_cd2.close();

Expand Down
11 changes: 11 additions & 0 deletions tiledb/sm/array_schema/current_domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ void CurrentDomain::expand_to_tiles(
}
}

std::string CurrentDomain::as_string() const {
if (type_ == CurrentDomainType::NDRECTANGLE) {
return ndrectangle_->as_string();
} else {
// As of 2025-01-09 there is no other such type. When/if we do make such a
// type, we'd need to configure it to return a description of itself.
throw std::runtime_error(
"CurrentDomain::as_string of non-NDRectangle type is not implemented");
}
}

} // namespace tiledb::sm

std::ostream& operator<<(
Expand Down
8 changes: 8 additions & 0 deletions tiledb/sm/array_schema/current_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ class CurrentDomain {
*/
void expand_to_tiles(const Domain& domain, NDRange& query_ndrange) const;

/**
* Returns a human-readable display of the current domain. Nominal use is
* to improve readability / actionability of out-of-bounds error messages.
*
* @return A string.
*/
std::string as_string() const;

private:
/* ********************************* */
/* PRIVATE ATTRIBUTES */
Expand Down
14 changes: 14 additions & 0 deletions tiledb/sm/array_schema/ndrectangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ Datatype NDRectangle::range_dtype_for_name(const std::string& name) const {
return range_dtype(idx);
}

std::string NDRectangle::as_string() const {
std::stringstream ss;
ss << "[";
for (uint32_t i = 0; i < get_ndranges().size(); ++i) {
if (i > 0) {
ss << ",";
}
auto dtype = domain()->dimension_ptr(i)->type();
ss << range_str(get_range(i), dtype);
}
ss << "]";
return ss.str();
}

} // namespace tiledb::sm

std::ostream& operator<<(std::ostream& os, const tiledb::sm::NDRectangle& ndr) {
Expand Down
8 changes: 8 additions & 0 deletions tiledb/sm/array_schema/ndrectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ class NDRectangle {
*/
Datatype range_dtype_for_name(const std::string& name) const;

/**
* Returns a human-readable display of the NDRectangle. Nominal use is
* to improve readability / actionability of out-of-bounds error messages.
*
* @return A string.
*/
std::string as_string() const;

private:
/* ********************************* */
/* PRIVATE ATTRIBUTES */
Expand Down
14 changes: 12 additions & 2 deletions tiledb/sm/query/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,18 @@ Status Query::process() {
// Make sure all ranges are contained in the current domain.
for (auto& range : subarray_.ranges_for_dim(d)) {
if (!cd->includes(d, range)) {
throw QueryException(
"A range was set outside of the current domain.");
// No std::format:
// https://github.com/TileDB-Inc/TileDB/pull/5421#discussion_r1909405876
std::stringstream ss;
ss << "A range ";
ss << range_str(
range, array_schema_->domain().dimension_ptr(d)->type());
ss << " on dimension '";
ss << array_schema_->domain().dimension_ptr(d)->name();
ss << "' was set outside of the current domain ";
ss << cd->as_string();
ss << ".";
throw QueryException(ss.str());
}
}
} else if (!all_ned_contained_in_current_domain) {
Expand Down
Loading