| 881 | |
| 882 | template <typename IntType = int> |
| 883 | Result<IntType> GetMemberInt(const JsonObject& obj, std::string_view key) { |
| 884 | ARROW_ASSIGN_OR_RAISE( |
| 885 | auto value, internal::ResolveSimdjsonResult(obj[key], "Failed to get JSON field")); |
| 886 | ARROW_ASSIGN_OR_RAISE(auto integer, internal::GetJsonInt(value, key, "an integer")); |
| 887 | return static_cast<IntType>(integer); |
| 888 | } |
| 889 | |
| 890 | Result<bool> GetMemberBool(const JsonObject& obj, std::string_view key) { |
| 891 | ARROW_ASSIGN_OR_RAISE( |
| 892 | auto value, internal::ResolveSimdjsonResult(obj[key], "Failed to get JSON field")); |
| 893 | return internal::ResolveSimdjsonResult(value.get_bool(), "field was not a boolean"); |
| 894 | } |
| 895 | |
| 896 | Result<std::string> GetMemberString(const JsonObject& obj, std::string_view key) { |
| 897 | ARROW_ASSIGN_OR_RAISE( |
| 898 | auto value, internal::ResolveSimdjsonResult(obj[key], "Failed to get JSON field")); |
| 899 | ARROW_ASSIGN_OR_RAISE( |
| 900 | auto string_view, |
| 901 | internal::ResolveSimdjsonResult(value.get_string(), "field was not a string")); |
| 902 | return std::string(string_view); |
| 903 | } |
| 904 | |
| 905 | Result<JsonObject> GetMemberObject(const JsonObject& obj, std::string_view key) { |
| 906 | ARROW_ASSIGN_OR_RAISE( |
| 907 | auto value, internal::ResolveSimdjsonResult(obj[key], "Failed to get JSON field")); |
| 908 | return internal::ResolveSimdjsonResult(value.get_object(), "field was not an object"); |
| 909 | } |
| 910 | |
| 911 | Result<JsonArray> GetMemberArray(const JsonObject& obj, std::string_view key) { |
| 912 | ARROW_ASSIGN_OR_RAISE( |
| 913 | auto value, internal::ResolveSimdjsonResult(obj[key], "Failed to get JSON field")); |
| 914 | |
| 915 | return internal::GetJsonArray(value, key); |
| 916 | } |
| 917 | |
| 918 | Result<TimeUnit::type> GetMemberTimeUnit(const JsonObject& obj, std::string_view key) { |
| 919 | ARROW_ASSIGN_OR_RAISE(const auto unit_str, GetMemberString(obj, key)); |
| 920 | return GetUnitFromString(unit_str); |
| 921 | } |
| 922 | |
| 923 | Result<std::shared_ptr<DataType>> GetInteger(const JsonObject& json_type) { |
| 924 | ARROW_ASSIGN_OR_RAISE(const bool is_signed, GetMemberBool(json_type, "isSigned")); |
| 925 | ARROW_ASSIGN_OR_RAISE(const int bit_width, GetMemberInt<int>(json_type, "bitWidth")); |
| 926 | |
| 927 | switch (bit_width) { |
| 928 | case 8: |
| 929 | return is_signed ? int8() : uint8(); |
| 930 | case 16: |
| 931 | return is_signed ? int16() : uint16(); |
| 932 | case 32: |
| 933 | return is_signed ? int32() : uint32(); |
| 934 | case 64: |
| 935 | return is_signed ? int64() : uint64(); |
| 936 | } |
| 937 | return Status::Invalid("Invalid bit width: ", bit_width); |
| 938 | } |
| 939 | |
| 940 | Result<std::shared_ptr<DataType>> GetFloatingPoint(const JsonObject& json_type) { |
nothing calls this directly
no test coverage detected