kou commented on code in PR #46696:
URL: https://github.com/apache/arrow/pull/46696#discussion_r2124975825
##########
cpp/src/arrow/json/from_string.cc:
##########
@@ -1030,13 +1029,13 @@ Status DictArrayFromJSONString(const
std::shared_ptr<DataType>& type,
ArrayFromJSONString(dictionary_type.index_type(),
indices_json));
ARROW_ASSIGN_OR_RAISE(auto dictionary,
ArrayFromJSONString(dictionary_type.value_type(),
dictionary_json));
-
- return DictionaryArray::FromArrays(type, std::move(indices),
std::move(dictionary))
- .Value(out);
+ ARROW_ASSIGN_OR_RAISE(auto out, DictionaryArray::FromArrays(type,
std::move(indices),
+
std::move(dictionary)));
+ return out;
Review Comment:
Cam we simplify this?
```suggestion
return DictionaryArray::FromArrays(type, std::move(indices),
std::move(dictionary)));
```
##########
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);
/// \endcode
ARROW_EXPORT
-Status ScalarFromJSONString(const std::shared_ptr<DataType>&, std::string_view
json,
- std::shared_ptr<Scalar>* out);
+Result<std::shared_ptr<Scalar>> ScalarFromJSONString(const
std::shared_ptr<DataType>&,
+ std::string_view json);
/// \brief Create a DictionaryScalar from a JSON string
/// \code {.cpp}
-/// std::shared_ptr<Scalar> scalar;
-/// DictScalarFromJSONString(dictionary(int32(), utf8()), "3", R"(["k1", "k2",
"k3",
-/// "k4"])", &scalar);
+/// std::shared_ptr<Scalar> dict_scalar =
+/// DictScalarFromJSONString(dictionary(int32(), utf8()), "3", R"(["k1",
"k2", "k3",
+/// "k4"])", &scalar);
Review Comment:
Ditto.
##########
cpp/src/arrow/json/from_string.cc:
##########
@@ -1051,28 +1050,28 @@ Status ScalarFromJSONString(const
std::shared_ptr<DataType>& type,
RETURN_NOT_OK(converter->AppendValue(json_doc));
RETURN_NOT_OK(converter->Finish(&array));
DCHECK_EQ(array->length(), 1);
- return array->GetScalar(0).Value(out);
+ ARROW_ASSIGN_OR_RAISE(auto out, array->GetScalar(0));
+ return out;
}
-Status DictScalarFromJSONString(const std::shared_ptr<DataType>& type,
- std::string_view index_json,
- std::string_view dictionary_json,
- std::shared_ptr<Scalar>* out) {
+Result<std::shared_ptr<Scalar>> DictScalarFromJSONString(
+ const std::shared_ptr<DataType>& type, std::string_view index_json,
+ std::string_view dictionary_json) {
if (type->id() != Type::DICTIONARY) {
return Status::TypeError("DictScalarFromJSONString requires dictionary
type, got ",
*type);
}
const auto& dictionary_type = checked_cast<const DictionaryType&>(*type);
- std::shared_ptr<Scalar> index;
std::shared_ptr<Array> dictionary;
- RETURN_NOT_OK(ScalarFromJSONString(dictionary_type.index_type(), index_json,
&index));
+ ARROW_ASSIGN_OR_RAISE(auto index,
+ ScalarFromJSONString(dictionary_type.index_type(),
index_json));
ARROW_ASSIGN_OR_RAISE(
dictionary, ArrayFromJSONString(dictionary_type.value_type(),
dictionary_json));
- *out = DictionaryScalar::Make(std::move(index), std::move(dictionary));
- return Status::OK();
+ auto out = DictionaryScalar::Make(std::move(index), std::move(dictionary));
+ return out;
Review Comment:
Can we simplify this?
```suggestion
return DictionaryScalar::Make(std::move(index), std::move(dictionary));
```
##########
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:
`Result<...>` is returned.
##########
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();
Review Comment:
In general, error should be handled instead of using `ValueOrDie()`. So it
may be better that we don't use `ValueOrDie()` in examples:
```suggestion
/// Result<std::shared_ptr<ChunkedArray>> chunked_array_result =
/// ChunkedArrayFromJSONString(int64(), {R"([5, 10])", R"([null])",
R"([16])"});
```
##########
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:
Ditto.
--
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]