diff --git a/c_glib/arrow-glib/input-stream.cpp b/c_glib/arrow-glib/input-stream.cpp index 52c79993e4ca..606b4819b25c 100644 --- a/c_glib/arrow-glib/input-stream.cpp +++ b/c_glib/arrow-glib/input-stream.cpp @@ -285,7 +285,9 @@ garrow_input_stream_read_tensor(GArrowInputStream *input_stream, GError **error) { auto arrow_input_stream = garrow_input_stream_get_raw(input_stream); + ARROW_SUPPRESS_DEPRECATION_WARNING auto arrow_tensor = arrow::ipc::ReadTensor(arrow_input_stream.get()); + ARROW_UNSUPPRESS_DEPRECATION_WARNING if (garrow::check(error, arrow_tensor, "[input-stream][read-tensor]")) { return garrow_tensor_new_raw(&(arrow_tensor.ValueOrDie())); } else { diff --git a/c_glib/arrow-glib/output-stream.cpp b/c_glib/arrow-glib/output-stream.cpp index d9bdf7ad8b78..a6fb7d6b90a2 100644 --- a/c_glib/arrow-glib/output-stream.cpp +++ b/c_glib/arrow-glib/output-stream.cpp @@ -211,10 +211,12 @@ garrow_output_stream_write_tensor(GArrowOutputStream *stream, auto arrow_tensor = garrow_tensor_get_raw(tensor); int32_t metadata_length; int64_t body_length; + ARROW_SUPPRESS_DEPRECATION_WARNING auto status = arrow::ipc::WriteTensor(*arrow_tensor, arrow_stream.get(), &metadata_length, &body_length); + ARROW_UNSUPPRESS_DEPRECATION_WARNING if (garrow::check(error, status, "[output-stream][write-tensor]")) { return metadata_length + body_length; } else { diff --git a/cpp/src/arrow/ipc/generate_tensor_fuzz_corpus.cc b/cpp/src/arrow/ipc/generate_tensor_fuzz_corpus.cc index 870f45867082..312514007e01 100644 --- a/cpp/src/arrow/ipc/generate_tensor_fuzz_corpus.cc +++ b/cpp/src/arrow/ipc/generate_tensor_fuzz_corpus.cc @@ -52,12 +52,14 @@ Result> MakeSerializedBuffer( } Result> SerializeTensor(const std::shared_ptr& tensor) { + ARROW_SUPPRESS_DEPRECATION_WARNING return MakeSerializedBuffer( [&](const std::shared_ptr& sink) -> Status { int32_t metadata_length; int64_t body_length; return ipc::WriteTensor(*tensor, sink.get(), &metadata_length, &body_length); }); + ARROW_UNSUPPRESS_DEPRECATION_WARNING } Result>> Tensors() { diff --git a/cpp/src/arrow/ipc/reader.cc b/cpp/src/arrow/ipc/reader.cc index 47ea70e43fac..4c10686b19b9 100644 --- a/cpp/src/arrow/ipc/reader.cc +++ b/cpp/src/arrow/ipc/reader.cc @@ -2276,7 +2276,9 @@ Result> ReadSchema(const Message& message, Result> ReadTensor(io::InputStream* file) { std::unique_ptr message; RETURN_NOT_OK(ReadContiguousPayload(file, &message)); + ARROW_SUPPRESS_DEPRECATION_WARNING return ReadTensor(*message); + ARROW_UNSUPPRESS_DEPRECATION_WARNING } Result> ReadTensor(const Message& message) { @@ -2969,7 +2971,9 @@ Status FuzzIpcTensorStream(const uint8_t* data, int64_t size) { std::shared_ptr tensor; while (true) { + ARROW_SUPPRESS_DEPRECATION_WARNING ARROW_ASSIGN_OR_RAISE(tensor, ReadTensor(&buffer_reader)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING if (tensor == nullptr) { break; } diff --git a/cpp/src/arrow/ipc/reader.h b/cpp/src/arrow/ipc/reader.h index b5184e967cdd..e43c5f4c0654 100644 --- a/cpp/src/arrow/ipc/reader.h +++ b/cpp/src/arrow/ipc/reader.h @@ -36,8 +36,7 @@ #include "arrow/util/macros.h" #include "arrow/util/visibility.h" -namespace arrow { -namespace ipc { +namespace arrow::ipc { class DictionaryMemo; struct IpcPayload; @@ -589,6 +588,9 @@ Result> ReadRecordBatch( /// /// \param[in] file an InputStream pointed at the start of the message /// \return the read tensor +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Result> ReadTensor(io::InputStream* file); @@ -596,6 +598,9 @@ Result> ReadTensor(io::InputStream* file); /// /// \param[in] message a Message containing the tensor metadata and body /// \return the read tensor +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Result> ReadTensor(const Message& message); @@ -603,6 +608,9 @@ Result> ReadTensor(const Message& message); /// /// \param[in] file an InputStream pointed at the start of the message /// \return the read sparse tensor +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Result> ReadSparseTensor(io::InputStream* file); @@ -610,6 +618,9 @@ Result> ReadSparseTensor(io::InputStream* file); /// /// \param[in] message a Message containing the tensor metadata and body /// \return the read sparse tensor +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Result> ReadSparseTensor(const Message& message); @@ -639,5 +650,4 @@ Status FuzzIpcFile(const uint8_t* data, int64_t size); } // namespace internal -} // namespace ipc -} // namespace arrow +} // namespace arrow::ipc diff --git a/cpp/src/arrow/ipc/tensor_test.cc b/cpp/src/arrow/ipc/tensor_test.cc index a9243e779932..78ab3cb0a135 100644 --- a/cpp/src/arrow/ipc/tensor_test.cc +++ b/cpp/src/arrow/ipc/tensor_test.cc @@ -72,7 +72,9 @@ class TestTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK(WriteTensor(tensor, mmap_.get(), &metadata_length, &body_length)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING const int64_t expected_body_length = elem_size * tensor.size(); ASSERT_EQ(expected_body_length, body_length); @@ -80,7 +82,9 @@ class TestTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); std::shared_ptr result; + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK_AND_ASSIGN(result, ReadTensor(mmap_.get())); + ARROW_UNSUPPRESS_DEPRECATION_WARNING ASSERT_EQ(result->data()->size(), expected_body_length); ASSERT_TRUE(tensor.Equals(*result)); @@ -115,7 +119,9 @@ TEST_F(TestTensorRoundTrip, BasicRoundtrip) { CheckTensorRoundTrip(t_zero_length_dim); int64_t serialized_size; + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK(GetTensorSize(t0, &serialized_size)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING ASSERT_TRUE(serialized_size > static_cast(size * sizeof(int64_t))); // ARROW-2840: Check that padding/alignment minded @@ -151,8 +157,10 @@ class TestSparseTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK( WriteSparseTensor(sparse_tensor, mmap_.get(), &metadata_length, &body_length)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING const auto& sparse_index = checked_cast(*sparse_tensor.sparse_index()); @@ -166,7 +174,9 @@ class TestSparseTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); std::shared_ptr result; + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK_AND_ASSIGN(result, ReadSparseTensor(mmap_.get())); + ARROW_UNSUPPRESS_DEPRECATION_WARNING ASSERT_EQ(SparseTensorFormat::COO, result->format_id()); const auto& resulted_sparse_index = @@ -192,8 +202,10 @@ class TestSparseTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK( WriteSparseTensor(sparse_tensor, mmap_.get(), &metadata_length, &body_length)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING const auto& sparse_index = checked_cast(*sparse_tensor.sparse_index()); @@ -209,7 +221,9 @@ class TestSparseTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); std::shared_ptr result; + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK_AND_ASSIGN(result, ReadSparseTensor(mmap_.get())); + ARROW_UNSUPPRESS_DEPRECATION_WARNING constexpr auto expected_format_id = std::is_same::value ? SparseTensorFormat::CSR @@ -233,8 +247,10 @@ class TestSparseTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK( WriteSparseTensor(sparse_tensor, mmap_.get(), &metadata_length, &body_length)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING const auto& sparse_index = checked_cast(*sparse_tensor.sparse_index()); @@ -259,7 +275,9 @@ class TestSparseTensorRoundTrip : public BaseTensorTest { ASSERT_OK(mmap_->Seek(0)); std::shared_ptr result; + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK_AND_ASSIGN(result, ReadSparseTensor(mmap_.get())); + ARROW_UNSUPPRESS_DEPRECATION_WARNING ASSERT_EQ(SparseTensorFormat::CSF, result->format_id()); const auto& resulted_sparse_index = @@ -565,6 +583,7 @@ IpcPayload MakeSparseTensorPayload(const std::shared_ptr& message, } // namespace TEST(TestSparseCSFIndex, RejectInconsistentBufferCounts) { + ARROW_SUPPRESS_DEPRECATION_WARNING // ndim == 1 is not a valid CSF index (it has no indptr buffers), and used to // reach SparseCSFIndex's constructor with an empty indptr vector. ASSERT_OK_AND_ASSIGN(auto message, @@ -587,9 +606,11 @@ TEST(TestSparseCSFIndex, RejectInconsistentBufferCounts) { /*num_indices_buffers=*/2, /*axis_order_size=*/3)); ASSERT_RAISES(Invalid, ReadSparseTensor(*message)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING } TEST(TestSparseCSFIndex, RejectInconsistentPayloadBufferCounts) { + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK_AND_ASSIGN(auto message, MakeCSFSparseTensorMessage(/*shape=*/{4}, /*num_indptr_buffers=*/0, /*num_indices_buffers=*/1, @@ -603,6 +624,7 @@ TEST(TestSparseCSFIndex, RejectInconsistentPayloadBufferCounts) { /*axis_order_size=*/3)); ASSERT_RAISES(Invalid, internal::ReadSparseTensorPayload(MakeSparseTensorPayload(message, 4))); + ARROW_UNSUPPRESS_DEPRECATION_WARNING } TEST(TestSparseCSXIndex, RejectIndptrLengthOverflow) { @@ -618,6 +640,7 @@ TEST(TestSparseCSXIndex, RejectIndptrLengthOverflow) { TEST(TestSparseTensor, RejectNegativeShapeAndNonZeroLength) { // A negative non_zero_length must be rejected by GetSparseTensorMetadata, // otherwise the negative size product bypasses the index buffer-size guards. + ARROW_SUPPRESS_DEPRECATION_WARNING ASSERT_OK_AND_ASSIGN( auto message, MakeCSFSparseTensorMessage(/*shape=*/{4, 4}, /*num_indptr_buffers=*/1, /*num_indices_buffers=*/2, @@ -631,6 +654,7 @@ TEST(TestSparseTensor, RejectNegativeShapeAndNonZeroLength) { /*num_indices_buffers=*/2, /*axis_order_size=*/2)); ASSERT_RAISES(Invalid, ReadSparseTensor(*message)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING } } // namespace test diff --git a/cpp/src/arrow/ipc/writer.cc b/cpp/src/arrow/ipc/writer.cc index 855d1a2f2116..eefd88e9f6b4 100644 --- a/cpp/src/arrow/ipc/writer.cc +++ b/cpp/src/arrow/ipc/writer.cc @@ -1119,7 +1119,9 @@ Status GetSparseTensorPayload(const SparseTensor& sparse_tensor, MemoryPool* poo Result> GetSparseTensorMessage(const SparseTensor& sparse_tensor, MemoryPool* pool) { IpcPayload payload; + ARROW_SUPPRESS_DEPRECATION_WARNING RETURN_NOT_OK(GetSparseTensorPayload(sparse_tensor, pool, &payload)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING return std::unique_ptr( new Message(std::move(payload.metadata), std::move(payload.body_buffers[0]))); } @@ -1154,7 +1156,9 @@ Status GetTensorSize(const Tensor& tensor, int64_t* size) { int32_t metadata_length = 0; int64_t body_length = 0; io::MockOutputStream dst; + ARROW_SUPPRESS_DEPRECATION_WARNING RETURN_NOT_OK(WriteTensor(tensor, &dst, &metadata_length, &body_length)); + ARROW_UNSUPPRESS_DEPRECATION_WARNING *size = dst.GetExtentBytesWritten(); return Status::OK(); } diff --git a/cpp/src/arrow/ipc/writer.h b/cpp/src/arrow/ipc/writer.h index aefb59f3136e..79ac4ccf8b01 100644 --- a/cpp/src/arrow/ipc/writer.h +++ b/cpp/src/arrow/ipc/writer.h @@ -23,33 +23,16 @@ #include #include +#include "arrow/io/type_fwd.h" #include "arrow/ipc/dictionary.h" // IWYU pragma: export #include "arrow/ipc/message.h" #include "arrow/ipc/options.h" #include "arrow/result.h" +#include "arrow/type_fwd.h" #include "arrow/util/macros.h" #include "arrow/util/visibility.h" -namespace arrow { - -class Array; -class Buffer; -class MemoryManager; -class MemoryPool; -class RecordBatch; -class Schema; -class Status; -class Table; -class Tensor; -class SparseTensor; - -namespace io { - -class OutputStream; - -} // namespace io - -namespace ipc { +namespace arrow::ipc { /// \brief Intermediate data structure with metadata header, and zero /// or more buffers for the message body. @@ -284,6 +267,9 @@ Status GetRecordBatchSize(const RecordBatch& batch, const IpcWriteOptions& optio /// \param[in] tensor the tensor to write /// \param[out] size the size of the complete encapsulated message /// \return Status +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Status GetTensorSize(const Tensor& tensor, int64_t* size); @@ -293,6 +279,9 @@ Status GetTensorSize(const Tensor& tensor, int64_t* size); /// \param[in] tensor the Tensor to write /// \param[in] pool MemoryPool to allocate space for metadata /// \return the resulting Message +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Result> GetTensorMessage(const Tensor& tensor, MemoryPool* pool); @@ -312,6 +301,9 @@ Result> GetTensorMessage(const Tensor& tensor, MemoryPo /// \param[out] metadata_length the actual metadata length, including padding /// \param[out] body_length the actual message body length /// \return Status +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Status WriteTensor(const Tensor& tensor, io::OutputStream* dst, int32_t* metadata_length, int64_t* body_length); @@ -327,6 +319,9 @@ Status WriteTensor(const Tensor& tensor, io::OutputStream* dst, int32_t* metadat /// \param[in] sparse_tensor the SparseTensor to write /// \param[in] pool MemoryPool to allocate space for metadata /// \return the resulting Message +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Result> GetSparseTensorMessage(const SparseTensor& sparse_tensor, MemoryPool* pool); @@ -341,6 +336,9 @@ Result> GetSparseTensorMessage(const SparseTensor& spar /// \param[out] metadata_length the actual metadata length, including padding /// \param[out] body_length the actual message body length /// \return Status +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Status WriteSparseTensor(const SparseTensor& sparse_tensor, io::OutputStream* dst, int32_t* metadata_length, int64_t* body_length); @@ -413,6 +411,9 @@ Status WriteIpcPayload(const IpcPayload& payload, const IpcWriteOptions& options /// \param[in,out] pool for any required temporary memory allocations /// \param[out] out the returned IpcPayload /// \return Status +ARROW_DEPRECATED( + "Tensor-specific IPC messages are deprecated in 26.0.0. " + "Use FixedShapeTensor extension arrays instead.") ARROW_EXPORT Status GetSparseTensorPayload(const SparseTensor& sparse_tensor, MemoryPool* pool, IpcPayload* out); @@ -471,5 +472,4 @@ Result> OpenRecordBatchWriter( const IpcWriteOptions& options = IpcWriteOptions::Defaults()); } // namespace internal -} // namespace ipc -} // namespace arrow +} // namespace arrow::ipc