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


##########
cpp/src/arrow/integration/json_internal.cc:
##########
@@ -1332,6 +1401,97 @@ class ArrayReader {
     return FinishBuilder(&builder);
   }
 
+  template <typename ViewType>
+  enable_if_binary_view_like<ViewType, Status> Visit(const ViewType& type) {
+    ARROW_ASSIGN_OR_RAISE(const auto json_views, GetDataArray(obj_, "VIEWS"));
+    ARROW_ASSIGN_OR_RAISE(const auto json_variadic_bufs,
+                          GetMemberArray(obj_, "VARIADIC_DATA_BUFFERS"));
+
+    using internal::Zip;
+    using util::span;
+
+    BufferVector buffers;
+    buffers.resize(json_variadic_bufs.Size() + 2);
+    for (auto [json_buf, buf] : Zip(json_variadic_bufs, 
span{buffers}.subspan(2))) {
+      auto hex_string = GetStringView(json_buf);
+      ARROW_ASSIGN_OR_RAISE(
+          buf, AllocateBuffer(static_cast<int64_t>(hex_string.size()) / 2, 
pool_));
+      RETURN_NOT_OK(ParseHexValues(hex_string, buf->mutable_data()));
+    }
+
+    TypedBufferBuilder<bool> validity_builder{pool_};
+    RETURN_NOT_OK(validity_builder.Resize(length_));
+    for (bool is_valid : is_valid_) {
+      validity_builder.UnsafeAppend(is_valid);
+    }
+    ARROW_ASSIGN_OR_RAISE(buffers[0], validity_builder.Finish());
+
+    ARROW_ASSIGN_OR_RAISE(
+        buffers[1], AllocateBuffer(length_ * sizeof(BinaryViewType::c_type), 
pool_));
+
+    span views{buffers[1]->mutable_data_as<BinaryViewType::c_type>(),
+               static_cast<size_t>(length_)};
+
+    int64_t null_count = 0;
+    for (auto [json_view, s, is_valid] : Zip(json_views, views, is_valid_)) {
+      if (!is_valid) {
+        s = {};
+        ++null_count;
+        continue;
+      }
+
+      DCHECK(json_view.IsObject());
+      const auto& json_view_obj = json_view.GetObject();
+
+      auto json_size = json_view_obj.FindMember("SIZE");
+      RETURN_NOT_INT("SIZE", json_size, json_view_obj);
+      DCHECK_GE(json_size->value.GetInt64(), 0);
+      auto size = static_cast<int32_t>(json_size->value.GetInt64());
+
+      if (size <= BinaryViewType::kInlineSize) {
+        auto json_inlined = json_view_obj.FindMember("INLINED");
+        RETURN_NOT_STRING("INLINED", json_inlined, json_view_obj);
+        s.inlined = {size, {}};
+
+        if constexpr (ViewType::is_utf8) {
+          DCHECK_LE(json_inlined->value.GetStringLength(), 
BinaryViewType::kInlineSize);

Review Comment:
   https://github.com/apache/arrow/issues/38186



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