You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "amoeba (via GitHub)" <gi...@apache.org> on 2025/06/03 23:26:05 UTC

Re: [PR] GH-46439: [C++] Use result pattern for all FromJSONString Helpers [arrow]

amoeba commented on code in PR #46696:
URL: https://github.com/apache/arrow/pull/46696#discussion_r2125110261


##########
cpp/src/arrow/json/from_string.h:
##########
@@ -68,52 +68,45 @@ Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataTyp
 /// \brief Create a ChunkedArray from a JSON string
 ///
 /// \code {.cpp}
-/// std::shared_ptr<ChunkedArray> chunked_array;
-/// ChunkedArrayFromJSONString(
-///   int64(), {R"([5, 10])", R"([null])", R"([16])"}, &chunked_array
-/// );
+/// std::shared_ptr<ChunkedArray> chunked_array =
+///     ChunkedArrayFromJSONString(int64(), {R"([5, 10])", R"([null])", R"([16])"})
+///         .ValueOrDie();
 /// \endcode
 ARROW_EXPORT
-Status ChunkedArrayFromJSONString(const std::shared_ptr<DataType>& type,
-                                  const std::vector<std::string>& json_strings,
-                                  std::shared_ptr<ChunkedArray>* out);
+Result<std::shared_ptr<ChunkedArray>> ChunkedArrayFromJSONString(
+    const std::shared_ptr<DataType>& type, const std::vector<std::string>& json_strings);
 
 /// \brief Create a DictionaryArray from a JSON string
 ///
 /// \code {.cpp}
-/// std::shared_ptr<Array> array;
-/// DictArrayFromJSONString(
-///   dictionary(int32(), utf8()),
-///   "[0, 1, 0, 2, 0, 3]", R"(["k1", "k2", "k3", "k4"])",
-///   &array
-/// );
+/// std::shared_ptr<Array> dict_array =
+///     DictArrayFromJSONString(dictionary(int32(), utf8()), "[0, 1, 0, 2, 0, 3]",
+///     R"(["k1", "k2", "k3", "k4"])");

Review Comment:
   Fixed in 0faf15a471e328f1434094f1a55611b0c88e0a55.



##########
cpp/src/arrow/json/from_string.h:
##########
@@ -68,52 +68,45 @@ Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataTyp
 /// \brief Create a ChunkedArray from a JSON string
 ///
 /// \code {.cpp}
-/// std::shared_ptr<ChunkedArray> chunked_array;
-/// ChunkedArrayFromJSONString(
-///   int64(), {R"([5, 10])", R"([null])", R"([16])"}, &chunked_array
-/// );
+/// std::shared_ptr<ChunkedArray> chunked_array =
+///     ChunkedArrayFromJSONString(int64(), {R"([5, 10])", R"([null])", R"([16])"})
+///         .ValueOrDie();
 /// \endcode
 ARROW_EXPORT
-Status ChunkedArrayFromJSONString(const std::shared_ptr<DataType>& type,
-                                  const std::vector<std::string>& json_strings,
-                                  std::shared_ptr<ChunkedArray>* out);
+Result<std::shared_ptr<ChunkedArray>> ChunkedArrayFromJSONString(
+    const std::shared_ptr<DataType>& type, const std::vector<std::string>& json_strings);
 
 /// \brief Create a DictionaryArray from a JSON string
 ///
 /// \code {.cpp}
-/// std::shared_ptr<Array> array;
-/// DictArrayFromJSONString(
-///   dictionary(int32(), utf8()),
-///   "[0, 1, 0, 2, 0, 3]", R"(["k1", "k2", "k3", "k4"])",
-///   &array
-/// );
+/// std::shared_ptr<Array> dict_array =
+///     DictArrayFromJSONString(dictionary(int32(), utf8()), "[0, 1, 0, 2, 0, 3]",
+///     R"(["k1", "k2", "k3", "k4"])");
 /// \endcode
 ARROW_EXPORT
-Status DictArrayFromJSONString(const std::shared_ptr<DataType>&,
-                               std::string_view indices_json,
-                               std::string_view dictionary_json,
-                               std::shared_ptr<Array>* out);
+Result<std::shared_ptr<Array>> DictArrayFromJSONString(const std::shared_ptr<DataType>&,
+                                                       std::string_view indices_json,
+                                                       std::string_view dictionary_json);
 
 /// \brief Create a Scalar from a JSON string
 /// \code {.cpp}
-/// std::shared_ptr<Scalar> scalar;
-/// ScalarFromJSONString(float64(), "42", &scalar);
+/// std::shared_ptr<Scalar> scalar =
+///     ScalarFromJSONString(float64(), "42", &scalar);

Review Comment:
   Fixed in 0faf15a471e328f1434094f1a55611b0c88e0a55.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org