mapleFU commented on code in PR #46730:
URL: https://github.com/apache/arrow/pull/46730#discussion_r2159268798


##########
cpp/src/arrow/array/builder_binary.h:
##########
@@ -645,6 +664,58 @@ class ARROW_EXPORT BinaryViewBuilder : public ArrayBuilder 
{
     UnsafeAppend(value.data(), static_cast<int64_t>(value.size()));
   }
 
+  /// \brief Append a buffer of raw bytes to the internal data heap
+  ///
+  /// This method is used to add out-of-line data buffers to the builder.
+  /// The size of the buffer must be larger than TypeClass::kInlineSize.
+  ///
+  /// \param[in] value Pointer to the raw byte data.
+  /// \param[in] length The number of bytes in the buffer.
+  /// \return A Result containing the index of the newly appended buffer on 
success,
+  ///         or a Status error if the length is too small or allocation fails.
+  Result<int32_t> AppendBuffer(const uint8_t* value, const int64_t length) {
+    if (ARROW_PREDICT_FALSE(length <= TypeClass::kInlineSize)) {
+      return Status::Invalid(
+          "The size of buffer to append should be larger than kInlineSize");
+    }
+    ARROW_RETURN_NOT_OK(data_heap_builder_.FinishLastBlock());
+    ARROW_ASSIGN_OR_RAISE(auto v,
+                          data_heap_builder_.Append</*Safe=*/true>(value, 
length));
+    return v.ref.buffer_index;
+  }
+
+  Result<int32_t> AppendBuffer(const char* value, const int64_t length) {
+    return AppendBuffer(reinterpret_cast<const uint8_t*>(value), length);
+  }
+
+  Result<int32_t> AppendBuffer(const std::string& value) {
+    return AppendBuffer(value.data(), static_cast<int64_t>(value.size()));
+  }
+
+  Result<int32_t> AppendBuffer(const std::string_view value) {
+    return AppendBuffer(value.data(), static_cast<int64_t>(value.size()));
+  }
+
+  Status AppendViewFromBuffer(const int32_t buffer_idx, const int32_t start,
+                              const int32_t length) {
+    ARROW_RETURN_NOT_OK(Reserve(1));
+    UnsafeAppendToBitmap(true);
+    ARROW_ASSIGN_OR_RAISE(const auto v, 
data_heap_builder_.GetViewFromBuffer<true>(
+                                            buffer_idx, start, length));
+    data_builder_.UnsafeAppend(v);
+    return Status::OK();
+  }
+
+  /// \pre The caller must ensure that:
+  ///      - `buffer_idx` is a valid index for buffer.
+  ///      - `start` and `length` define a valid range within the specified 
buffer.
+  void UnsafeAppendViewFromBuffer(const int32_t buffer_idx, const int32_t 
start,
+                                  const int32_t length) {
+    UnsafeAppendToBitmap(true);
+    const auto v = data_heap_builder_.GetViewFromBuffer<false>(buffer_idx, 
start, length);

Review Comment:
   ```suggestion
       const auto v = 
data_heap_builder_.GetViewFromBuffer</*Safe=*/false>(buffer_idx, start, length);
   ```



##########
cpp/src/arrow/array/builder_binary.h:
##########
@@ -645,6 +664,58 @@ class ARROW_EXPORT BinaryViewBuilder : public ArrayBuilder 
{
     UnsafeAppend(value.data(), static_cast<int64_t>(value.size()));
   }
 
+  /// \brief Append a buffer of raw bytes to the internal data heap
+  ///
+  /// This method is used to add out-of-line data buffers to the builder.
+  /// The size of the buffer must be larger than TypeClass::kInlineSize.
+  ///
+  /// \param[in] value Pointer to the raw byte data.
+  /// \param[in] length The number of bytes in the buffer.
+  /// \return A Result containing the index of the newly appended buffer on 
success,
+  ///         or a Status error if the length is too small or allocation fails.
+  Result<int32_t> AppendBuffer(const uint8_t* value, const int64_t length) {
+    if (ARROW_PREDICT_FALSE(length <= TypeClass::kInlineSize)) {
+      return Status::Invalid(
+          "The size of buffer to append should be larger than kInlineSize");
+    }
+    ARROW_RETURN_NOT_OK(data_heap_builder_.FinishLastBlock());
+    ARROW_ASSIGN_OR_RAISE(auto v,
+                          data_heap_builder_.Append</*Safe=*/true>(value, 
length));
+    return v.ref.buffer_index;
+  }
+
+  Result<int32_t> AppendBuffer(const char* value, const int64_t length) {
+    return AppendBuffer(reinterpret_cast<const uint8_t*>(value), length);
+  }
+
+  Result<int32_t> AppendBuffer(const std::string& value) {
+    return AppendBuffer(value.data(), static_cast<int64_t>(value.size()));
+  }
+
+  Result<int32_t> AppendBuffer(const std::string_view value) {
+    return AppendBuffer(value.data(), static_cast<int64_t>(value.size()));
+  }
+
+  Status AppendViewFromBuffer(const int32_t buffer_idx, const int32_t start,
+                              const int32_t length) {
+    ARROW_RETURN_NOT_OK(Reserve(1));
+    UnsafeAppendToBitmap(true);
+    ARROW_ASSIGN_OR_RAISE(const auto v, 
data_heap_builder_.GetViewFromBuffer<true>(

Review Comment:
   ```suggestion
       ARROW_ASSIGN_OR_RAISE(const auto v, 
data_heap_builder_.GetViewFromBuffer</*Safe=*/true>(
   ```



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