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


##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -91,6 +94,122 @@ Result<T> 
ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
   return value;
 }
 
+inline const char* JsonTypeName(simdjson::dom::element_type type) {
+  switch (type) {
+    case simdjson::dom::element_type::ARRAY:
+      return "array";
+    case simdjson::dom::element_type::OBJECT:
+      return "object";
+    case simdjson::dom::element_type::INT64:
+    case simdjson::dom::element_type::UINT64:
+    case simdjson::dom::element_type::DOUBLE:
+    case simdjson::dom::element_type::BIGINT:
+      return "number";
+    case simdjson::dom::element_type::STRING:
+      return "string";
+    case simdjson::dom::element_type::BOOL:
+      return "boolean";
+    case simdjson::dom::element_type::NULL_VALUE:
+      return "null";
+  }
+  return "unknown";
+}
+
+inline Result<simdjson::dom::array> GetJsonArray(simdjson::dom::element value,
+                                                 std::string_view name) {
+  if (!value.is_array()) {
+    return Status::Invalid(name, " must be an array, got ", 
JsonTypeName(value.type()));
+  }
+  return ResolveSimdjsonResult(value.get_array(), "Failed to get JSON array");
+}
+
+inline Result<int64_t> GetJsonInt(simdjson::dom::element value, 
std::string_view name,
+                                  std::string_view expected) {
+  if (!value.is_int64()) {
+    return Status::Invalid(name, " must contain ", expected, ", got ",
+                           JsonTypeName(value.type()));
+  }
+  return ResolveSimdjsonResult(value.get_int64(), "Failed to get JSON 
integer");
+}
+
+inline Result<simdjson::dom::object> ParseJsonObject(simdjson::dom::parser& 
parser,
+                                                     const std::string& json) {
+  return ResolveSimdjsonResult(parser.parse(json).get_object(),
+                               "Invalid serialized JSON data");

Review Comment:
   Updated PR desc



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