Skip to content

Commit

Permalink
GH-45512: [C++] Clean up undefined symbols in libarrow without IPC (#…
Browse files Browse the repository at this point in the history
…45513)

### Rationale for this change

When building the Arrow library without IPC, the library ends up with undefined symbols to functions that are only available with ARROW_IPC=ON

### What changes are included in this PR?

Use the ARROW_IPC macro to detect if IPC is being used, and when not, return a NotImplementedError

### Are these changes tested?

Compiles cleanly and no longer shows undefined IPC symbols

### Are there any user-facing changes?

No
* GitHub Issue: #45512

Authored-by: Will Ayd <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
WillAyd authored Feb 13, 2025
1 parent cc861b5 commit 7906e3c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cpp/src/arrow/compute/expression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/util/config.h"

#include "arrow/compute/expression.h"

#include <algorithm>
Expand All @@ -30,8 +32,10 @@
#include "arrow/compute/function_internal.h"
#include "arrow/compute/util.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/util/hash_util.h"
#include "arrow/util/key_value_metadata.h"
#include "arrow/util/logging.h"
Expand Down Expand Up @@ -1492,6 +1496,7 @@ Result<Expression> RemoveNamedRefs(Expression src) {
// this in the schema of a RecordBatch. Embedded arrays and scalars are stored in its
// columns. Finally, the RecordBatch is written to an IPC file.
Result<std::shared_ptr<Buffer>> Serialize(const Expression& expr) {
#ifdef ARROW_IPC
struct {
std::shared_ptr<KeyValueMetadata> metadata_ = std::make_shared<KeyValueMetadata>();
ArrayVector columns_;
Expand Down Expand Up @@ -1567,9 +1572,13 @@ Result<std::shared_ptr<Buffer>> Serialize(const Expression& expr) {
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<Expression> Deserialize(std::shared_ptr<Buffer> buffer) {
#ifdef ARROW_IPC
io::BufferReader stream(std::move(buffer));
ARROW_ASSIGN_OR_RAISE(auto reader, ipc::RecordBatchFileReader::Open(&stream));
ARROW_ASSIGN_OR_RAISE(auto batch, reader->ReadRecordBatch(0));
Expand Down Expand Up @@ -1670,6 +1679,9 @@ Result<Expression> Deserialize(std::shared_ptr<Buffer> buffer) {
};

return FromRecordBatch{*batch, 0}.GetOne();
#else
return Status::NotImplemented("IPC feature isn't enabled");
#endif
}

Expression project(std::vector<Expression> values, std::vector<std::string> names) {
Expand Down

0 comments on commit 7906e3c

Please sign in to comment.