From 84458615e2d1abbe5a7ac71159f2f282cdf31805 Mon Sep 17 00:00:00 2001 From: Mohammad Naqvi Date: Sat, 12 Sep 2026 17:42:32 -0400 Subject: [PATCH] GH-32438: [C++] Create target file when HadoopFileSystem::OpenAppendStream targets a nonexistent path --- cpp/src/arrow/filesystem/hdfs.cc | 5 ++++- cpp/src/arrow/filesystem/hdfs_test.cc | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/hdfs.cc b/cpp/src/arrow/filesystem/hdfs.cc index da0fbd5ec04a..87dab14f3ea2 100644 --- a/cpp/src/arrow/filesystem/hdfs.cc +++ b/cpp/src/arrow/filesystem/hdfs.cc @@ -489,7 +489,10 @@ class HadoopFileSystem::Impl { int16_t replication, int64_t default_block_size, std::shared_ptr* file) { int flags = O_WRONLY; - if (append) flags |= O_APPEND; + // Hadoop's FileSystem::append (unlike a POSIX O_CREAT|O_APPEND open) requires + // the target file to already exist, so only request append semantics if the + // file is actually there. + if (append && Exists(path)) flags |= O_APPEND; errno = 0; hdfsFile handle = diff --git a/cpp/src/arrow/filesystem/hdfs_test.cc b/cpp/src/arrow/filesystem/hdfs_test.cc index e3f0fa966c30..7eb04709038e 100644 --- a/cpp/src/arrow/filesystem/hdfs_test.cc +++ b/cpp/src/arrow/filesystem/hdfs_test.cc @@ -442,7 +442,6 @@ class TestHadoopFileSystemGeneric : public ::testing::Test, bool allow_write_file_over_dir() const override { return true; } bool allow_move_dir_over_non_empty_dir() const override { return true; } bool have_implicit_directories() const override { return true; } - bool allow_append_to_new_file() const override { return false; } std::shared_ptr GetEmptyFileSystem() override { // Since the HDFS contents are kept persistently between test runs,