Copilot commented on code in PR #49712:
URL: https://github.com/apache/arrow/pull/49712#discussion_r3317683294
##########
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 {
Review Comment:
Pre-reserving the sum of all string bytes makes `string_view()` fail once
the column's total payload exceeds 2GB, even though StringView arrays can span
multiple data buffers as long as each individual value is below the 2GB limit.
`StringHeapBuilder::Reserve()` rejects a single reservation larger than
`int32_t::max()`, so this should reserve per value or in bounded chunks (or use
the safe `Append` path) instead of reserving `total_length` at once.
--
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]