| 1687 | |
| 1688 | template <typename T> |
| 1689 | Status GetIntArray(const RjArray& json_array, const int32_t length, |
| 1690 | std::shared_ptr<Buffer>* out) { |
| 1691 | if (static_cast<rj::SizeType>(length) != json_array.Size()) { |
| 1692 | return Status::Invalid("Integer array had unexpected length ", json_array.Size(), |
| 1693 | " (expected ", length, ")"); |
| 1694 | } |
| 1695 | |
| 1696 | ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBuffer(length * sizeof(T), pool_)); |
| 1697 | |
| 1698 | T* values = reinterpret_cast<T*>(buffer->mutable_data()); |
| 1699 | |
| 1700 | for (auto [i, val] : Zip(Enumerate<rj::SizeType>, json_array)) { |
| 1701 | if constexpr (sizeof(T) < sizeof(int64_t)) { |
| 1702 | DCHECK(val.IsInt() || val.IsInt64()); |
| 1703 | if (val.IsInt()) { |
| 1704 | values[i] = static_cast<T>(val.GetInt()); |
| 1705 | } else { |
| 1706 | values[i] = static_cast<T>(val.GetInt64()); |
| 1707 | } |
| 1708 | } else { |
| 1709 | // Read 64-bit integers as strings, as JSON numbers cannot represent |
| 1710 | // them exactly. |
| 1711 | DCHECK(val.IsString()); |
| 1712 | |
| 1713 | using ArrowType = typename CTypeTraits<T>::ArrowType; |
| 1714 | if (!ParseValue<ArrowType>(val.GetString(), val.GetStringLength(), &values[i])) { |
| 1715 | return Status::Invalid("Failed to parse integer: '", |
| 1716 | std::string(val.GetString(), val.GetStringLength()), |
| 1717 | "'"); |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | *out = std::move(buffer); |
| 1723 | return Status::OK(); |
| 1724 | } |
| 1725 | |
| 1726 | template <typename T> |
| 1727 | Status CreateList(const std::shared_ptr<DataType>& type) { |