thisisnic commented on code in PR #54458:
URL: https://github.com/apache/arrow/pull/54458#discussion_r4658390762
##########
r/R/extension.R:
##########
@@ -122,7 +122,14 @@ ExtensionType <- R6Class(
# available from C++. We need this in order to produce the correct
# R6 subclass when a shared_ptr<ExtensionType> is returned to R.
r6_class = function() {
- ExtensionType__r6_class(self)
+ if (ExtensionType__is_r_type(self)) {
+ ExtensionType__r6_class(self)
+ } else {
+ # Not created from R (e.g., a canonical extension type registered by
+ # libarrow such as arrow.uuid), so there is no R6 subclass to
+ # dispatch to: fall back to this class
+ ExtensionType
Review Comment:
:robot: Fixed in e6bca4ac88: `ExtensionType__MakeArray()` now sets the
extension type on a shallow copy of the data before calling `MakeArray()`, and
there is a test that wraps `arrow.uuid` storage.
##########
r/src/array_to_vector.cpp:
##########
@@ -1279,7 +1279,11 @@ class Converter_Extension : public Converter {
auto extension_type =
dynamic_cast<const RExtensionType*>(chunked_array_->type().get());
if (extension_type == nullptr) {
- Rf_error("Converter_Extension can't be used with a non-R extension
type");
+ // Not an extension type created from R (e.g., a canonical extension type
+ // such as arrow.uuid registered by libarrow itself), so there is no
R-level
+ // as_vector() to call: convert the storage arrays instead, which is what
+ // the default ExtensionType$as_vector() does.
+ return ConvertStorage();
Review Comment:
:robot: Fixed in 1a24b2c6a8. This turned out not to be specific to extension
types, as fields converted with ALTREP had the same problem, so
`Converter_Struct` now builds its field converters from flattened chunks. Tests
cover plain fields, a field with an extension type defined in R, and an
`arrow.uuid` field.
##########
r/src/array_to_vector.cpp:
##########
@@ -1308,6 +1312,23 @@ class Converter_Extension : public Converter {
R_xlen_t start, R_xlen_t n, size_t chunk_index)
const {
return Status::OK();
}
+
+ private:
+ SEXP ConvertStorage() const {
+ const auto& extension_type =
+ checked_cast<const arrow::ExtensionType&>(*chunked_array_->type());
+ ArrayVector storage_chunks;
+ storage_chunks.reserve(chunked_array_->num_chunks());
+ for (const auto& chunk : chunked_array_->chunks()) {
+ storage_chunks.push_back(
+ checked_cast<const arrow::ExtensionArray&>(*chunk).storage());
+ }
+ auto storage = std::make_shared<ChunkedArray>(std::move(storage_chunks),
+
extension_type.storage_type());
+ // The outer conversion's task group isn't reachable from Allocate(), so
the
+ // storage is converted serially here, as RExtensionType::Convert() does
+ return Converter::Convert(storage, false);
Review Comment:
:robot: Fixed in 1a24b2c6a8: extension types not created from R are now
converted through a single storage converter for the whole column, so every
list element gets the same R type. There is a test using `arrow.opaque` with
`int64` storage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]