Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-15611: [C++] Migrate arrow::ipc::internal::json::ArrayFromJSON to Result<> #12713

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/src/arrow/ipc/generate_fuzz_corpus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Result<std::shared_ptr<RecordBatch>> MakeMapBatch() {
[]
]
)";
RETURN_NOT_OK(ArrayFromJSON(map(int16(), int32()), json_input, &array));
ARROW_ASSIGN_OR_RAISE(array, ArrayFromJSON(map(int16(), int32()), json_input));
auto schema = ::arrow::schema({field("f0", array->type())});
return RecordBatch::Make(schema, array->length(), {array});
}
Expand Down
34 changes: 18 additions & 16 deletions cpp/src/arrow/ipc/json_simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,8 @@ Status GetConverter(const std::shared_ptr<DataType>& type,

} // namespace

Status ArrayFromJSON(const std::shared_ptr<DataType>& type, util::string_view json_string,
std::shared_ptr<Array>* out) {
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>& type,
util::string_view json_string) {
std::shared_ptr<Converter> converter;
RETURN_NOT_OK(GetConverter(type, &converter));

Expand All @@ -919,17 +919,19 @@ Status ArrayFromJSON(const std::shared_ptr<DataType>& type, util::string_view js

// The JSON document should be an array, append it
RETURN_NOT_OK(converter->AppendValues(json_doc));
return converter->Finish(out);
std::shared_ptr<Array> out;
RETURN_NOT_OK(converter->Finish(&out));
return out;
}

Status ArrayFromJSON(const std::shared_ptr<DataType>& type,
const std::string& json_string, std::shared_ptr<Array>* out) {
return ArrayFromJSON(type, util::string_view(json_string), out);
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>& type,
const std::string& json_string) {
return ArrayFromJSON(type, util::string_view(json_string));
}

Status ArrayFromJSON(const std::shared_ptr<DataType>& type, const char* json_string,
std::shared_ptr<Array>* out) {
return ArrayFromJSON(type, util::string_view(json_string), out);
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>& type,
const char* json_string) {
return ArrayFromJSON(type, util::string_view(json_string));
}

Status ChunkedArrayFromJSON(const std::shared_ptr<DataType>& type,
Expand All @@ -939,7 +941,7 @@ Status ChunkedArrayFromJSON(const std::shared_ptr<DataType>& type,
out_chunks.reserve(json_strings.size());
for (const std::string& chunk_json : json_strings) {
out_chunks.emplace_back();
RETURN_NOT_OK(ArrayFromJSON(type, chunk_json, &out_chunks.back()));
ARROW_ASSIGN_OR_RAISE(out_chunks.back(), ArrayFromJSON(type, chunk_json));
}
*out = std::make_shared<ChunkedArray>(std::move(out_chunks), type);
return Status::OK();
Expand All @@ -954,10 +956,10 @@ Status DictArrayFromJSON(const std::shared_ptr<DataType>& type,

const auto& dictionary_type = checked_cast<const DictionaryType&>(*type);

std::shared_ptr<Array> indices, dictionary;
RETURN_NOT_OK(ArrayFromJSON(dictionary_type.index_type(), indices_json, &indices));
RETURN_NOT_OK(
ArrayFromJSON(dictionary_type.value_type(), dictionary_json, &dictionary));
ARROW_ASSIGN_OR_RAISE(auto indices,
ArrayFromJSON(dictionary_type.index_type(), indices_json));
ARROW_ASSIGN_OR_RAISE(auto dictionary,
ArrayFromJSON(dictionary_type.value_type(), dictionary_json));

return DictionaryArray::FromArrays(type, std::move(indices), std::move(dictionary))
.Value(out);
Expand Down Expand Up @@ -995,8 +997,8 @@ Status DictScalarFromJSON(const std::shared_ptr<DataType>& type,
std::shared_ptr<Scalar> index;
std::shared_ptr<Array> dictionary;
RETURN_NOT_OK(ScalarFromJSON(dictionary_type.index_type(), index_json, &index));
RETURN_NOT_OK(
ArrayFromJSON(dictionary_type.value_type(), dictionary_json, &dictionary));
ARROW_ASSIGN_OR_RAISE(dictionary,
ArrayFromJSON(dictionary_type.value_type(), dictionary_json));

*out = DictionaryScalar::Make(std::move(index), std::move(dictionary));
return Status::OK();
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/ipc/json_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ namespace internal {
namespace json {

ARROW_EXPORT
Status ArrayFromJSON(const std::shared_ptr<DataType>&, const std::string& json,
std::shared_ptr<Array>* out);
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>&,
const std::string& json);

ARROW_EXPORT
Status ArrayFromJSON(const std::shared_ptr<DataType>&, util::string_view json,
std::shared_ptr<Array>* out);
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>&,
util::string_view json);

ARROW_EXPORT
Status ArrayFromJSON(const std::shared_ptr<DataType>&, const char* json,
std::shared_ptr<Array>* out);
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>&,
const char* json);

ARROW_EXPORT
Status ChunkedArrayFromJSON(const std::shared_ptr<DataType>& type,
Expand Down
Loading