thisisnic commented on code in PR #49712:
URL: https://github.com/apache/arrow/pull/49712#discussion_r3197420245
##########
r/src/r_to_arrow.cpp:
##########
@@ -910,6 +910,49 @@ class RPrimitiveConverter<T, enable_if_string_like<T>>
}
};
+template <typename T>
+class RPrimitiveConverter<T, enable_if_string_view<T>>
+ : public PrimitiveConverter<T, RConverter> {
+ public:
+ Status Extend(SEXP x, int64_t size, int64_t offset = 0) override {
+ RVectorType rtype = GetVectorType(x);
+ if (rtype != STRING) {
+ return Status::Invalid("Expecting a character vector");
+ }
+ return UnsafeAppendUtf8Strings(arrow::r::utf8_strings(x), size, offset);
+ }
+
+ void DelayedExtend(SEXP values, int64_t size, RTasks& tasks) override {
+ auto task = [this, values, size]() { return this->Extend(values, size); };
+ tasks.Append(false, std::move(task));
+ }
+
+ private:
+ Status UnsafeAppendUtf8Strings(const cpp11::strings& s, int64_t size,
int64_t offset) {
+ RETURN_NOT_OK(this->primitive_builder_->Reserve(size - offset));
+ const SEXP* p_strings = reinterpret_cast<const SEXP*>(DATAPTR_RO(s)) +
offset;
+
+ int64_t total_length = 0;
+ for (R_xlen_t i = offset; i < size; i++, ++p_strings) {
+ SEXP si = *p_strings;
+ total_length += si == NA_STRING ? 0 : LENGTH(si);
+ }
+ RETURN_NOT_OK(this->primitive_builder_->ReserveData(total_length));
+
+ p_strings = reinterpret_cast<const SEXP*>(DATAPTR_RO(s)) + offset;
+ for (R_xlen_t i = offset; i < size; i++, ++p_strings) {
+ SEXP si = *p_strings;
+ if (si == NA_STRING) {
+ this->primitive_builder_->UnsafeAppendNull();
+ } else {
+ this->primitive_builder_->UnsafeAppend(CHAR(si), LENGTH(si));
+ }
+ }
+
+ return Status::OK();
+ }
+};
Review Comment:
I'm less confident about this entire block of code
--
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]