tadeja commented on code in PR #50310:
URL: https://github.com/apache/arrow/pull/50310#discussion_r3521371370


##########
cpp/src/arrow/array/data.h:
##########
@@ -271,6 +271,28 @@ struct ARROW_EXPORT ArrayData {
     return GetValues<T>(i, offset);
   }
 
+  /// \brief Access a buffer's data as a span
+  ///
+  /// \param i The buffer index
+  /// \param length The required length (in number of typed values) of the 
requested span
+  /// \pre i > 0
+  /// \pre length <= the length of the buffer (in number of values) that's 
expected for
+  /// this array type
+  /// \return A span<const T> of the requested length
+  template <typename T>
+  std::span<const T> GetSpan(int i, int64_t length) const {
+    if (!buffers[i]) {
+      return {};
+    }
+
+    const int64_t buffer_length = buffers[i]->size() / 
static_cast<int64_t>(sizeof(T));
+    assert(i > 0 && length + offset <= buffer_length);
+    ARROW_UNUSED(buffer_length);
+
+    return std::span<const T>(
+        reinterpret_cast<const T*>(buffers[i]->data()) + offset, length);
+        }

Review Comment:
   Thanks for pr, @VedantRalekar!
   These lines need clang-format fix per [Dev / Lint job 
logs](https://github.com/apache/arrow/actions/runs/28492088719/job/84481450503?pr=50310#step:5:45).
   See also 
[Styling](https://arrow.apache.org/docs/developers/guide/step_by_step/styling.html#pre-commit)
 and [Dev 
Guidelines](https://arrow.apache.org/docs/developers/cpp/development.html), you 
can run
    ```pre-commit run --show-diff-on-failure --color=always --all-files cpp```
   
   One optional point to consider - perhaps add a test in `array_test.cc` to 
cover `+ offset` and also the new null-buffer case?



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