Skip to content

Add support for getting a dtype of ndrectangle.#5229

Merged
KiterLuc merged 1 commit intodevfrom
rbin/ch52012/ndrectangle_dtype
Aug 8, 2024
Merged

Add support for getting a dtype of ndrectangle.#5229
KiterLuc merged 1 commit intodevfrom
rbin/ch52012/ndrectangle_dtype

Conversation

@robertbindar
Copy link
Copy Markdown
Contributor

@robertbindar robertbindar commented Aug 6, 2024

Users wrapping the current domain APIs are requesting:
tiledb_datatype_t NDRectangle::range_dtype(const std::string& dim_name) and
tiledb_datatype_t NDRectangle::range_dtype(uint32_t dim_idx) (and the CAPI counterparts)
so that the underlying TileDB datatype of a range/dimension can be queried closer to the
call site of functions like e.g. range where a conversion from tiledb_datatype_t to static c++ type is most of the time needed.

[sc-52012]


TYPE: FEATURE
DESC: Add support for getting a dtype of ndrectangle.

@robertbindar robertbindar force-pushed the rbin/ch52012/ndrectangle_dtype branch 2 times, most recently from 89d6a98 to d91f05d Compare August 6, 2024 14:06
* @param dim_idx The dimension index.
* @return The datatype of the range.
*/
tiledb_datatype_t range_dtype(unsigned dim_idx) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are other accessors that double up everything in terms of dimension index and name. Could we have an accessor that uses name too as I wrote the rest of my implementation in terms of the dimension name. (Yes, I know, I could wrap this but while we are at making this complete may as well make it fully complete.)

Copy link
Copy Markdown
Contributor

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

LGTM, and I second @eddelbuettel 's request for a by-name accessor (either on this PR, or a subsequent PR, makes no difference to me)

Copy link
Copy Markdown
Contributor

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

As bonus it wouldn't hurt to drop examples into

examples/c_api/current_domain.c
examples/cpp_api/current_domain.cc

such as (for example in the C++ case)

diff --git a/examples/cpp_api/current_domain.cc b/examples/cpp_api/current_domain.cc
index 0ba8f3373..a1626478b 100644
--- a/examples/cpp_api/current_domain.cc
+++ b/examples/cpp_api/current_domain.cc
@@ -107,6 +107,15 @@ void print_current_domain(Context& ctx) {
   // Get the current domain's NDRectangle
   NDRectangle ndrect = current_domain.ndrectangle();

+  tiledb_datatype_t dtype = ndrect.range_dtype(0);
+  const char* name;
+  auto st = tiledb_datatype_to_str(dtype, &name);
+  if (st == TILEDB_OK) {
+    std::cout << "Current domain dtype: " << name << std::endl;
+  } else {
+    std::cout << "Could not retrieve dtype name for" << dtype << std::endl;
+  }
+
   // Get the range of the rectangle's first dimension
   std::array<int32_t, 2> range = ndrect.range<int32_t>("d1");

Comment thread tiledb/sm/cpp_api/ndrectangle.h Outdated
* @param dim_name The dimension name.
* @return The datatype of the range.
*/
tiledb_datatype_t range_dtype_from_name(const std::string& dim_name) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🙇

Copy link
Copy Markdown
Contributor

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

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

Thanks!

@robertbindar robertbindar force-pushed the rbin/ch52012/ndrectangle_dtype branch 3 times, most recently from fcc96b4 to 29de8cb Compare August 6, 2024 15:56
@robertbindar robertbindar force-pushed the rbin/ch52012/ndrectangle_dtype branch from 29de8cb to 6c0b6f5 Compare August 6, 2024 15:59
Copy link
Copy Markdown
Member

@teo-tsirpanis teo-tsirpanis left a comment

Choose a reason for hiding this comment

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

This is very likely sufficient for the C# API, thanks!

The term dtype is nowhere else being used in the C or C++ API, we should better call it just get_type for consistency.

@eddelbuettel
Copy link
Copy Markdown
Contributor

I think datatype is used in a few places and tiledb_datatype_t also cements it a little.

@teo-tsirpanis
Copy link
Copy Markdown
Member

Indeed, but function names use type.

/** Returns the attribute datatype. */
tiledb_datatype_t type() const {
auto& ctx = ctx_.get();
tiledb_datatype_t type;
ctx.handle_error(
tiledb_attribute_get_type(ctx.ptr().get(), attr_.get(), &type));
return type;
}

/** Returns the dimension datatype. */
tiledb_datatype_t type() const {
tiledb_datatype_t type;
auto& ctx = ctx_.get();
ctx.handle_error(
tiledb_dimension_get_type(ctx.ptr().get(), dim_.get(), &type));
return type;
}

/** Returns the domain type. */
tiledb_datatype_t type() const {
auto& ctx = ctx_.get();
tiledb_datatype_t type;
ctx.handle_error(
tiledb_domain_get_type(ctx.ptr().get(), domain_.get(), &type));
return type;
}

* @param dim_idx The dimension index.
* @return The datatype of the range.
*/
tiledb_datatype_t range_dtype(unsigned dim_idx) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we actually make the C++ APIs public? Are there use cases for them outside of helping with type validation in the range getters and setters? I think those should be better served by an API to get the whole domain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@teo-tsirpanis in Slack/Shortcut our discussion was to not expose the entire domain, but rather, subaccessors such as range_dtype and ndim individually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should also update range and set_range to use the new APIs.

@robertbindar
Copy link
Copy Markdown
Contributor Author

get_type

@teo-tsirpanis get_type is used in the current domain API and returns NDRECTANGLE, it's an unfortunate overload of the word type, I think get_dtype makes things a little less confusing.

@eddelbuettel
Copy link
Copy Markdown
Contributor

But dtype is used only as a variable not in a signature:

$ grep dtype tiledb/sm/cpp_api/*
tiledb/sm/cpp_api/enumeration_experimental.h:    tiledb_datatype_t dtype = type.value_or(DataT::tiledb_type);
tiledb/sm/cpp_api/enumeration_experimental.h:          dtype,
tiledb/sm/cpp_api/enumeration_experimental.h:          dtype,
tiledb/sm/cpp_api/enumeration_experimental.h:    tiledb_datatype_t dtype = type.value_or(DataT::tiledb_type);
tiledb/sm/cpp_api/enumeration_experimental.h:        dtype,
$ 

I would find get_datatype cleaner.

@KiterLuc KiterLuc changed the title Add support for getting a dtype of ndrectangle Add support for getting a dtype of ndrectangle, Aug 8, 2024
@KiterLuc
Copy link
Copy Markdown
Contributor

KiterLuc commented Aug 8, 2024

@robertbindar could we beef up the description of the PR here? More precisely, I'd like to include the motivations that lead to us needing the extra API.

@KiterLuc KiterLuc merged commit 58dbc08 into dev Aug 8, 2024
@KiterLuc KiterLuc deleted the rbin/ch52012/ndrectangle_dtype branch August 8, 2024 10:24
@KiterLuc KiterLuc changed the title Add support for getting a dtype of ndrectangle, Add support for getting a dtype of ndrectangle. Aug 8, 2024
@eddelbuettel
Copy link
Copy Markdown
Contributor

I cannot change the feeling that naming it range_dtype() is a bit of an anti-pattern as the token 'dtype' is not used in any other interface so far. But hey it's merged so we'll use it.

KiterLuc pushed a commit that referenced this pull request Aug 8, 2024
This PR adds capi and cppapi support for querying the number of
slots/dimensions/axes of a current domain ndrectangle.

Depends on #5229 to be merged first.

---
TYPE: FEATURE
DESC: Add dim num support for ndrectangle.
@KiterLuc
Copy link
Copy Markdown
Contributor

KiterLuc commented Aug 8, 2024

@eddelbuettel If it's just a naming change, I'm happy to take it before we release. @robertbindar let's open a discussion in the core team channel to choose a name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants