From a5f09c1bf5ed5ea032b115dfd30ea833bfff8aef Mon Sep 17 00:00:00 2001 From: Mohammad Naqvi Date: Sat, 12 Sep 2026 17:42:32 -0400 Subject: [PATCH 1/2] GH-32438: [C++] Create target file when HadoopFileSystem::OpenAppendStream targets a nonexistent path --- cpp/src/arrow/filesystem/hdfs_test.cc | 1 - cpp/src/arrow/io/hdfs.cc | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/hdfs_test.cc b/cpp/src/arrow/filesystem/hdfs_test.cc index db5cefef3748..eab536c77c96 100644 --- a/cpp/src/arrow/filesystem/hdfs_test.cc +++ b/cpp/src/arrow/filesystem/hdfs_test.cc @@ -346,7 +346,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, diff --git a/cpp/src/arrow/io/hdfs.cc b/cpp/src/arrow/io/hdfs.cc index 73d8e1575721..0c32e4c4175c 100644 --- a/cpp/src/arrow/io/hdfs.cc +++ b/cpp/src/arrow/io/hdfs.cc @@ -529,7 +529,10 @@ class HadoopFileSystem::HadoopFileSystemImpl { int16_t replication, int64_t default_block_size, std::shared_ptr* file) { int flags = O_WRONLY; - if (append) flags |= O_APPEND; + // 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 = From 5986fccc1f9edf05773ce260181f65100e7c008e Mon Sep 17 00:00:00 2001 From: Mohammad Naqvi Date: Sat, 12 Sep 2026 18:25:35 -0400 Subject: [PATCH 2/2] chore: clarify Hadoop FileSystem::append --- cpp/src/arrow/io/hdfs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/io/hdfs.cc b/cpp/src/arrow/io/hdfs.cc index 0c32e4c4175c..dc1878d368ef 100644 --- a/cpp/src/arrow/io/hdfs.cc +++ b/cpp/src/arrow/io/hdfs.cc @@ -529,7 +529,7 @@ class HadoopFileSystem::HadoopFileSystemImpl { int16_t replication, int64_t default_block_size, std::shared_ptr* file) { int flags = O_WRONLY; - // FileSystem::append (unlike a POSIX O_CREAT|O_APPEND open) requires + // 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;