From 2b9407c70ca71b60366988d45cfcbeba3a516930 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Tue, 30 Nov 2021 00:49:07 +0000 Subject: [PATCH 1/2] ARROW-14912: [C++] implement GcsFileSystem::CopyFile --- cpp/src/arrow/filesystem/gcsfs.cc | 10 +++++++++- cpp/src/arrow/filesystem/gcsfs_test.cc | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.cc b/cpp/src/arrow/filesystem/gcsfs.cc index aa69890d336..fb77be56e7b 100644 --- a/cpp/src/arrow/filesystem/gcsfs.cc +++ b/cpp/src/arrow/filesystem/gcsfs.cc @@ -182,6 +182,12 @@ class GcsFileSystem::Impl { return GetFileInfoImpl(path, std::move(meta).status(), FileType::Directory); } + Status CopyFile(const GcsPath& src, const GcsPath& dest) { + auto metadata = + client_.RewriteObjectBlocking(src.bucket, src.object, dest.bucket, dest.object); + return internal::ToArrowStatus(metadata.status()); + } + Result> OpenInputStream(const GcsPath& path) { auto stream = client_.ReadObject(path.bucket, path.object); ARROW_GCS_RETURN_NOT_OK(stream.status()); @@ -274,7 +280,9 @@ Status GcsFileSystem::Move(const std::string& src, const std::string& dest) { } Status GcsFileSystem::CopyFile(const std::string& src, const std::string& dest) { - return Status::NotImplemented("The GCS FileSystem is not fully implemented"); + ARROW_ASSIGN_OR_RAISE(auto s, GcsPath::FromString(src)); + ARROW_ASSIGN_OR_RAISE(auto d, GcsPath::FromString(dest)); + return impl_->CopyFile(s, d); } Result> GcsFileSystem::OpenInputStream( diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index 3304d4bcc73..e728de1a58d 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -286,6 +286,20 @@ TEST_F(GcsIntegrationTest, GetFileInfoObject) { arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::File); } +TEST_F(GcsIntegrationTest, CopyFileSuccess) { + auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions()); + const auto destination_path = kPreexistingBucket + std::string("/copy-destination"); + ASSERT_OK(fs->CopyFile(PreexistingObjectPath(), destination_path)); + arrow::fs::AssertFileInfo(fs.get(), destination_path, FileType::File); +} + +TEST_F(GcsIntegrationTest, CopyFileNotFound) { + auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions()); + const auto destination_path = kPreexistingBucket + std::string("/copy-destination"); + const auto status = fs->CopyFile(NotFoundObjectPath(), destination_path); + EXPECT_EQ(status.code(), StatusCode::IOError); +} + TEST_F(GcsIntegrationTest, ReadObjectString) { auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions()); From f05082a85af99d614a2cd526bc366fdf7408e475 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Tue, 30 Nov 2021 13:12:31 +0000 Subject: [PATCH 2/2] Address review comments --- cpp/src/arrow/filesystem/gcsfs_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index e728de1a58d..f3e12cb5974 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -296,8 +296,7 @@ TEST_F(GcsIntegrationTest, CopyFileSuccess) { TEST_F(GcsIntegrationTest, CopyFileNotFound) { auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions()); const auto destination_path = kPreexistingBucket + std::string("/copy-destination"); - const auto status = fs->CopyFile(NotFoundObjectPath(), destination_path); - EXPECT_EQ(status.code(), StatusCode::IOError); + ASSERT_RAISES(IOError, fs->CopyFile(NotFoundObjectPath(), destination_path)); } TEST_F(GcsIntegrationTest, ReadObjectString) {