Reranko05 commented on code in PR #51396:
URL: https://github.com/apache/arrow/pull/51396#discussion_r4380878991


##########
cpp/examples/arrow/simdjson_row_converter.cc:
##########
@@ -75,101 +88,180 @@ arrow::Result<std::optional<simdjson::dom::element>> 
GetField(
   return value;
 }
 
-// Append a JSON value to an Arrow builder according to the expected Arrow 
type.
-// This example only handles the types used by the example schema; extend this
-// switch when adapting it to schemas with additional Arrow types.
-arrow::Status AppendJsonValue(simdjson::dom::element value,
-                              const std::shared_ptr<arrow::DataType>& type,
-                              arrow::ArrayBuilder* builder);
-
-arrow::Status AppendJsonStruct(simdjson::dom::element value,
-                               const arrow::StructType& type,
-                               arrow::StructBuilder* builder) {
-  ARROW_ASSIGN_OR_RAISE(auto object,
-                        Unwrap(value.get_object(), "Failed to get JSON 
object"));
-
-  for (int i = 0; i < type.num_fields(); ++i) {
-    const auto& field = type.field(i);
-
-    ARROW_ASSIGN_OR_RAISE(auto child, GetField(object, field->name()));
-
-    if (!child.has_value()) {
-      ARROW_RETURN_NOT_OK(builder->child_builder(i)->AppendNull());
-    } else {
-      ARROW_RETURN_NOT_OK(
-          AppendJsonValue(*child, field->type(), 
builder->child_builder(i).get()));
+// A JSON value, or std::nullopt if it is missing.
+using JsonValue = std::optional<simdjson::dom::element>;

Review Comment:
   I tested with a missing `metrics` field, and conversion succeeds, producing 
an Arrow null without errors. I think using a simdjson null value instead might 
require more code than the current `std::optional` approach. Could you explain 
how you'd implement this using the DOM API?



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