bkietz commented on code in PR #37792:
URL: https://github.com/apache/arrow/pull/37792#discussion_r1352844014


##########
cpp/src/arrow/array/util.cc:
##########
@@ -642,29 +665,36 @@ class RepeatedArrayFactory {
 
   template <typename T>
   enable_if_base_binary<T, Status> Visit(const T&) {
-    std::shared_ptr<Buffer> value =
-        checked_cast<const typename TypeTraits<T>::ScalarType&>(scalar_).value;
+    const std::shared_ptr<Buffer>& value = scalar<T>().value;
     std::shared_ptr<Buffer> values_buffer, offsets_buffer;
     RETURN_NOT_OK(CreateBufferOf(value->data(), value->size(), 
&values_buffer));
     auto size = static_cast<typename T::offset_type>(value->size());
     RETURN_NOT_OK(CreateOffsetsBuffer(size, &offsets_buffer));
-    out_ = std::make_shared<typename TypeTraits<T>::ArrayType>(length_, 
offsets_buffer,
-                                                               values_buffer);
+    out_ = std::make_shared<typename TypeTraits<T>::ArrayType>(
+        length_, std::move(offsets_buffer), std::move(values_buffer));
+    return Status::OK();
+  }
+
+  template <typename T>
+  enable_if_binary_view_like<T, Status> Visit(const T& type) {
+    std::string_view value{*scalar<T>().value};
+    auto s = util::ToIndexOffsetBinaryView(value, 0, 0);
+    RETURN_NOT_OK(FinishFixedWidth(&s, sizeof(s)));
+    if (!s.is_inline()) {
+      out_->data()->buffers.push_back(scalar<T>().value);
+    }

Review Comment:
   It is tested in `TestArray.TestMakeArrayFromScalar` for inlined and 
non-inlined views. For non-inlined views, there is a single data buffer: the 
buffer which holds the BinaryViewScalar's value. We just need to write N views 
referring to that buffer. So each buffer index is 0 and each offset is 0



-- 
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]

Reply via email to