This is an automated email from the ASF dual-hosted git repository.

bkietz pushed a commit to branch feature/format-string-view
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 2aaccd1b8c4ca9b7e52864bd50a8c0370672827a
Author: Tobias Zagorni <[email protected]>
AuthorDate: Tue Oct 18 17:21:14 2022 +0200

    implement inline visitor for StringView/BinaryView
---
 cpp/src/arrow/visit_data_inline.h | 53 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/cpp/src/arrow/visit_data_inline.h 
b/cpp/src/arrow/visit_data_inline.h
index 7d37698f14..b6996d188c 100644
--- a/cpp/src/arrow/visit_data_inline.h
+++ b/cpp/src/arrow/visit_data_inline.h
@@ -155,6 +155,59 @@ struct ArraySpanInlineVisitor<T, enable_if_base_binary<T>> 
{
   }
 };
 
+// BinaryView, StringView...
+template <typename T>
+struct ArraySpanInlineVisitor<T, enable_if_binary_view_like<T>> {
+  using c_type = std::string_view;
+
+  template <typename ValidFunc, typename NullFunc>
+  static Status VisitStatus(const ArraySpan& arr, ValidFunc&& valid_func,
+                            NullFunc&& null_func) {
+    if (arr.length == 0) {
+      return Status::OK();
+    }
+    const StringHeader* headers;
+    if (arr.buffers[1].data == NULLPTR) {
+      headers = NULLPTR;
+    } else {
+      // Do not apply the array offset to the values array; the value_offsets
+      // index the non-sliced values array.
+      headers = arr.GetValues<StringHeader>(1);
+    }
+    return VisitBitBlocks(
+        arr.buffers[0].data, arr.offset, arr.length,
+        [&](int64_t (index)) {
+          return valid_func(static_cast<std::string_view>(headers[index]));
+        },
+        [&]() {
+          return null_func();
+        });
+  }
+
+  template <typename ValidFunc, typename NullFunc>
+  static void VisitVoid(const ArraySpan& arr, ValidFunc&& valid_func,
+                        NullFunc&& null_func) {
+    if (arr.length == 0) {
+      return;
+    }
+    const StringHeader* headers;
+    if (arr.buffers[1].data == NULLPTR) {
+      headers = NULLPTR;
+    } else {
+      // Do not apply the array offset to the values array; the value_offsets
+      // index the non-sliced values array.
+      headers = arr.GetValues<StringHeader>(1);
+    }
+
+    VisitBitBlocksVoid(
+        arr.buffers[0].data, arr.offset, arr.length,
+        [&](int64_t (index)) {
+          valid_func(static_cast<std::string_view>(headers[index]));
+        },
+        std::forward<NullFunc>(null_func));
+  }
+};
+
 // FixedSizeBinary, Decimal128
 template <typename T>
 struct ArraySpanInlineVisitor<T, enable_if_fixed_size_binary<T>> {

Reply via email to