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

Function GetJsonAs

cpp/src/arrow/util/simdjson_internal.h:281–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279
280template <typename SimdjsonValueType>
281Result<SimdjsonValueType> GetJsonAs(simdjson::ondemand::value& value) {
282 SimdjsonValueType typed_value{};
283 simdjson::error_code error_code;
284
285 if constexpr (std::same_as<SimdjsonValueType, SimdjsonNull>) {
286 // simdjson has no get<>() for null; probe it explicitly
287 bool is_null;
288 error_code = value.is_null().get(is_null);
289 if (error_code == simdjson::SUCCESS && !is_null) {
290 error_code = simdjson::INCORRECT_TYPE;
291 }
292 } else {
293 error_code = value.get(typed_value);
294 }
295
296 if (error_code != simdjson::SUCCESS) {
297 simdjson::ondemand::json_type json_type;
298 if (value.type().get(json_type) != simdjson::SUCCESS) {
299 if constexpr (std::same_as<SimdjsonValueType, SimdjsonNull>) {
300 return Status::Invalid("Expected null, got malformed JSON value");
301 } else {
302 return Status::Invalid("Expected ", JsonTypeName<SimdjsonValueType>(),
303 ", got malformed JSON value");
304 }
305 }
306
307 if constexpr (std::same_as<SimdjsonValueType, SimdjsonNull>) {
308 return Status::Invalid("Expected null, got JSON type ", JsonTypeName(json_type));
309 } else {
310 return Status::Invalid("Expected ", JsonTypeName<SimdjsonValueType>(),
311 ", got JSON type ", JsonTypeName(json_type));
312 }
313 }
314
315 return typed_value;
316}
317
318template <typename T>
319Result<T> GetJsonField(simdjson::ondemand::object& object, std::string_view key) {

Callers

nothing calls this directly

Calls 5

is_nullMethod · 0.80
JsonTypeNameFunction · 0.70
InvalidFunction · 0.50
getMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected