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 3 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
10 changes: 10 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,16 @@ 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.
return "CurrentDomain of non-NDRectangle type";
johnkerl marked this conversation as resolved.
Show resolved Hide resolved
}
}

} // 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
10 changes: 8 additions & 2 deletions tiledb/sm/query/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "tiledb/sm/tile/writer_tile_tuple.h"

#include <cassert>
#include <format>
johnkerl marked this conversation as resolved.
Show resolved Hide resolved
#include <iostream>
#include <sstream>

Expand Down Expand Up @@ -859,8 +860,13 @@ 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.");
throw QueryException(std::format(
"A range {} on dimension '{}' was set outside of the current "
"domain {}.",
range_str(
range, array_schema_->domain().dimension_ptr(d)->type()),
array_schema_->domain().dimension_ptr(d)->name(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be current_domain()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the domain to get types. Those are wired through array_schema_ and current_domain both. I can get them either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihnorton correction: the domain is wired through the array_schema_ and the private ndrectangle_ of CurrentDomain.

It is an invariant that they be the same domain in both places.

If you want to pursue the latter then we need to connect a domain accessor in CurrentDomain which passes through the copy of the domain in its ndrectangle_. Personally I don't see the benefit to doing the latter.

cd->as_string()));
}
}
} else if (!all_ned_contained_in_current_domain) {
Expand Down
Loading