MCPcopy Create free account
hub / github.com/apache/arrow / ArrayFromJSONString

Function ArrayFromJSONString

cpp/src/arrow/json/from_string.cc:1034–1063  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1032} // namespace
1033
1034Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataType>& type,
1035 std::string_view json_string) {
1036 std::shared_ptr<JSONConverter> converter;
1037 RETURN_NOT_OK(GetConverter(type, &converter));
1038
1039 simdjson::padded_string padded_string{json_string};
1040
1041 sj::parser parser;
1042 sj::document json_doc;
1043 auto error = parser.iterate(padded_string).get(json_doc);
1044 if (error) {
1045 return Status::Invalid("JSON parse error: ", simdjson::error_message(error));
1046 }
1047 sj::value json_obj;
1048 if (auto error_code = json_doc.get_value().get(json_obj);
1049 error_code != simdjson::SUCCESS) {
1050 return Status::Invalid("JSON parse error: ", simdjson::error_message(error_code));
1051 }
1052 ARROW_ASSIGN_OR_RAISE(auto array, internal::GetJsonAs<sj::array>(json_obj));
1053
1054 // The JSON document should be an array, append it
1055 RETURN_NOT_OK(converter->AppendValues(array));
1056 // The parser is lazy and does not look past the end of the array by itself
1057 if (!json_doc.at_end()) {
1058 return Status::Invalid("JSON parse error: trailing content after JSON array");
1059 }
1060 std::shared_ptr<Array> out;
1061 RETURN_NOT_OK(converter->Finish(&out));
1062 return out;
1063}
1064
1065Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataType>& type,
1066 const std::string& json_string) {

Callers 14

SliceArrayFromJSONFunction · 0.85
TestSessionFunction · 0.85
DictScalarFromJSONStringFunction · 0.85
TYPED_TEST_PFunction · 0.85
TESTFunction · 0.85
TestDecimalBasicFunction · 0.85
TestIntegerListMethod · 0.85
TestIntegerListErrorsMethod · 0.85
TestNullListMethod · 0.85
TestIntegerListListMethod · 0.85

Calls 6

GetConverterFunction · 0.70
InvalidFunction · 0.50
getMethod · 0.45
get_valueMethod · 0.45
AppendValuesMethod · 0.45
FinishMethod · 0.45

Tested by 8

TestSessionFunction · 0.68
TYPED_TEST_PFunction · 0.68
TESTFunction · 0.68
TestDecimalBasicFunction · 0.68
TestIntegerListMethod · 0.68
TestIntegerListErrorsMethod · 0.68
TestNullListMethod · 0.68
TestIntegerListListMethod · 0.68