From ada8750917cd2ec2ae8a605d2673d78ef04c82e4 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Mon, 6 Jan 2025 14:39:35 +0900 Subject: [PATCH] GH-44563: [C++] `FunctionOptions::{Serialize,Deserialize}()` return an error without `ARROW_IPC` (#45171) ### Rationale for this change They use IPC format internally. So we can't do them without `ARROW_IPC`. ### What changes are included in this PR? Returns `arrow::Status::NotImplemented` without `ARROW_IPC`. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #44563 Authored-by: Sutou Kouhei Signed-off-by: Sutou Kouhei --- cpp/src/arrow/compute/function_internal.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/compute/function_internal.cc b/cpp/src/arrow/compute/function_internal.cc index 2ef1d265ea09c..8d85254209d7d 100644 --- a/cpp/src/arrow/compute/function_internal.cc +++ b/cpp/src/arrow/compute/function_internal.cc @@ -15,14 +15,18 @@ // specific language governing permissions and limitations // under the License. +#include "arrow/util/config.h" + #include "arrow/compute/function_internal.h" #include "arrow/array/util.h" #include "arrow/compute/function.h" #include "arrow/compute/registry.h" #include "arrow/io/memory.h" -#include "arrow/ipc/reader.h" -#include "arrow/ipc/writer.h" +#ifdef ARROW_IPC +# include "arrow/ipc/reader.h" +# include "arrow/ipc/writer.h" +#endif #include "arrow/record_batch.h" #include "arrow/scalar.h" #include "arrow/util/checked_cast.h" @@ -65,6 +69,7 @@ Result> FunctionOptionsFromStructScalar( Result> GenericOptionsType::Serialize( const FunctionOptions& options) const { +#ifdef ARROW_IPC ARROW_ASSIGN_OR_RAISE(auto scalar, FunctionOptionsToStructScalar(options)); ARROW_ASSIGN_OR_RAISE(auto array, MakeArrayFromScalar(*scalar, 1)); auto batch = @@ -74,6 +79,9 @@ Result> GenericOptionsType::Serialize( RETURN_NOT_OK(writer->WriteRecordBatch(*batch)); RETURN_NOT_OK(writer->Close()); return stream->Finish(); +#else + return Status::NotImplemented("IPC feature isn't enabled"); +#endif } Result> GenericOptionsType::Deserialize( @@ -83,6 +91,7 @@ Result> GenericOptionsType::Deserialize( Result> DeserializeFunctionOptions( const Buffer& buffer) { +#ifdef ARROW_IPC // Copying the buffer here is not ideal, but we need to do it to avoid // use-after-free issues with the zero-copy buffer read. auto stream = io::BufferReader::FromString(buffer.ToString()); @@ -108,6 +117,9 @@ Result> DeserializeFunctionOptions( checked_cast(*column).GetScalar(0)); auto scalar = checked_cast(*raw_scalar); return FunctionOptionsFromStructScalar(scalar); +#else + return Status::NotImplemented("IPC feature isn't enabled"); +#endif } Status CheckAllArrayOrScalar(const std::vector& values) {