pitrou commented on code in PR #50653:
URL: https://github.com/apache/arrow/pull/50653#discussion_r3655832903


##########
cpp/src/arrow/json/from_string.cc:
##########
@@ -124,20 +134,18 @@ Status GetConverter(const std::shared_ptr<DataType>&,
 template <class Derived>
 class ConcreteConverter : public JSONConverter {
  public:
-  Result<int64_t> SizeOfJSONArray(const rj::Value& json_obj) {
-    if (!json_obj.IsArray()) {
-      return JSONTypeError("array", json_obj.GetType());
-    }
-    return json_obj.Size();
-  }
-
-  Status AppendValues(const rj::Value& json_array) final {
+  Result<int32_t> AppendValues(sj::array& json_array) final {
     auto self = static_cast<Derived*>(this);
-    ARROW_ASSIGN_OR_RAISE(auto size, SizeOfJSONArray(json_array));
-    for (uint32_t i = 0; i < size; ++i) {
-      RETURN_NOT_OK(self->AppendValue(json_array[i]));
+    int32_t num_elements = 0;
+    for (auto element : json_array) {
+      sj::value value;
+      if (element.get(value) != simdjson::SUCCESS) {
+        return Status::Invalid("Could not iterate elements of JSON array");
+      }

Review Comment:
   Do we want to produce more informative error messages using 
`simdjson::error_message`?



##########
cpp/src/arrow/json/from_string.cc:
##########
@@ -360,22 +443,22 @@ class DecimalConverter final
 
   Status Init() override { return this->MakeConcreteBuilder(&builder_); }
 
-  Status AppendValue(const rj::Value& json_obj) override {
-    if (json_obj.IsNull()) {
+  Status AppendValue(sj::value& json_obj) override {
+    if (json_obj.is_null()) {
       return this->AppendNull();
     }
-    if (json_obj.IsString()) {
+    std::string_view string_value;
+    if (json_obj.get<std::string_view>(string_value) == simdjson::SUCCESS) {

Review Comment:
   Why do we need the explicit type parameter here, while it's implicit in 
other places?



##########
cpp/src/arrow/json/from_string.cc:
##########
@@ -980,15 +1125,28 @@ Result<std::shared_ptr<Array>> ArrayFromJSONString(const 
std::shared_ptr<DataTyp
   std::shared_ptr<JSONConverter> converter;
   RETURN_NOT_OK(GetConverter(type, &converter));
 
-  rj::Document json_doc;
-  json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
-  if (json_doc.HasParseError()) {
-    return Status::Invalid("JSON parse error at offset ", 
json_doc.GetErrorOffset(), ": ",
-                           GetParseError_En(json_doc.GetParseError()));
+  // TODO we should not copy the whole string. Maybe we can move the 
requirement of
+  // padding to users of this function

Review Comment:
   Not really, this is a convenience function, it should be as user-friendly as 
possible.



##########
cpp/src/arrow/json/from_string.cc:
##########
@@ -246,46 +256,119 @@ enable_if_unsigned_integer<T, Status> 
ConvertNumber(const rj::Value& json_obj,
     }
   } else {
     *out = static_cast<typename T::c_type>(0);
-    return JSONTypeError("unsigned int", json_obj.GetType());
+    return JSONTypeError("unsigned int", json_obj.type());
+  }
+}
+
+// Match the std::string_view against NaN, Inf, Infinity with optional leading 
minus
+bool NonFiniteDoubleFromString(std::string_view str, double* out) {

Review Comment:
   Not very important since these are internal helper functions, but you may 
return `std::optional<double>` instead.



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