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

Function GetIntArray

cpp/src/arrow/integration/json_internal.cc:1719–2138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1717
1718 template <typename T>
1719 Status GetIntArray(const JsonArray& json_array, const int32_t length,
1720 std::shared_ptr<Buffer>* out) {
1721 if (static_cast<int32_t>(json_array.size()) != length) {
1722 return Status::Invalid("Integer array had unexpected length ", json_array.size(),
1723 " (expected ", length, ")");
1724 }
1725
1726 ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBuffer(length * sizeof(T), pool_));
1727
1728 T* values = reinterpret_cast<T*>(buffer->mutable_data());
1729
1730 for (auto [i, val] : Zip(Enumerate<size_t>, json_array)) {
1731 if constexpr (sizeof(T) < sizeof(int64_t)) {
1732 ARROW_ASSIGN_OR_RAISE(auto integer,
1733 internal::GetJsonInt(val, "value", "an integer"));
1734 values[i] = static_cast<T>(integer);
1735 } else {
1736 // Read 64-bit integers as strings, as JSON numbers cannot represent
1737 // them exactly.
1738 ARROW_ASSIGN_OR_RAISE(auto string,
1739 internal::ResolveSimdjsonResult(
1740 val.get_string(), "Expected integer value as string"));
1741
1742 using ArrowType = typename CTypeTraits<T>::ArrowType;
1743 if (!ParseValue<ArrowType>(string.data(), string.size(), &values[i])) {
1744 return Status::Invalid("Failed to parse integer: '", std::string(string), "'");
1745 }
1746 }
1747 }
1748
1749 *out = std::move(buffer);
1750 return Status::OK();
1751 }
1752
1753 template <typename T>
1754 Status CreateList(const std::shared_ptr<DataType>& type) {
1755 using offset_type = typename T::offset_type;
1756
1757 RETURN_NOT_OK(InitializeData(2));
1758
1759 RETURN_NOT_OK(GetNullBitmap());
1760 ARROW_ASSIGN_OR_RAISE(const auto json_offsets, GetMemberArray(obj_, "OFFSET"));
1761 RETURN_NOT_OK(
1762 GetIntArray<offset_type>(json_offsets, length_ + 1, &data_->buffers[1]));
1763 RETURN_NOT_OK(GetChildren(obj_, *type));
1764 return Status::OK();
1765 }
1766
1767 template <typename T>
1768 enable_if_var_size_list<T, Status> Visit(const T& type) {
1769 return CreateList<T>(type_);
1770 }
1771
1772 template <typename T>
1773 Status CreateListView(const std::shared_ptr<DataType>& type) {
1774 using offset_type = typename T::offset_type;
1775
1776 RETURN_NOT_OK(InitializeData(3));

Callers

nothing calls this directly

Calls 5

ZipClass · 0.85
AddDictionaryMethod · 0.80
InvalidFunction · 0.50
sizeMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected