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


##########
cpp/src/arrow/extension/tensor_internal.cc:
##########
@@ -32,16 +32,120 @@ namespace arrow::internal {
 
 namespace {
 
-// Names indexed by rapidjson::Type enum value:
-// kNullType=0, kFalseType=1, kTrueType=2, kObjectType=3,
-// kArrayType=4, kStringType=5, kNumberType=6.
-constexpr const char* kJsonTypeNames[] = {"Null",  "False",  "True",  "Object",
-                                          "Array", "String", "Number"};
+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";
+}
+
+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");
+}
+
+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");
+}
 
 }  // namespace
 
-const char* JsonTypeName(const ::arrow::rapidjson::Value& v) {
-  return kJsonTypeNames[v.GetType()];
+Result<simdjson::dom::object> ParseJsonObject(simdjson::dom::parser& parser,
+                                              const std::string& json) {
+  return ResolveSimdjsonResult(parser.parse(json).get_object(),
+                               "Invalid serialized JSON data");
+}
+
+Result<std::optional<simdjson::dom::element>> GetOptionalJsonField(
+    const simdjson::dom::object& object, std::string_view key) {
+  auto field = object.at_key(key);

Review Comment:
   Added comment.



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