From 1271612c10877f30d5f361ac4010be3cbb3ac727 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Tue, 22 Oct 2024 09:28:18 -0700 Subject: [PATCH 01/23] GH-32206: GcsFileSystem::Make returns Result --- cpp/src/arrow/filesystem/gcsfs.cc | 2 +- cpp/src/arrow/filesystem/gcsfs.h | 2 +- cpp/src/arrow/filesystem/gcsfs_test.cc | 117 ++++++++++++------------- 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.cc b/cpp/src/arrow/filesystem/gcsfs.cc index 97cd39127261..fe6363d346f2 100644 --- a/cpp/src/arrow/filesystem/gcsfs.cc +++ b/cpp/src/arrow/filesystem/gcsfs.cc @@ -962,7 +962,7 @@ Result> GcsFileSystem::OpenAppendStream( return Status::NotImplemented("Append is not supported in GCS"); } -std::shared_ptr GcsFileSystem::Make(const GcsOptions& options, +Result> GcsFileSystem::Make(const GcsOptions& options, const io::IOContext& context) { // Cannot use `std::make_shared<>` as the constructor is private. return std::shared_ptr(new GcsFileSystem(options, context)); diff --git a/cpp/src/arrow/filesystem/gcsfs.h b/cpp/src/arrow/filesystem/gcsfs.h index f1fbc95bf957..4bd67b1bf08b 100644 --- a/cpp/src/arrow/filesystem/gcsfs.h +++ b/cpp/src/arrow/filesystem/gcsfs.h @@ -232,7 +232,7 @@ class ARROW_EXPORT GcsFileSystem : public FileSystem { /// Create a GcsFileSystem instance from the given options. // TODO(ARROW-16884): make this return Result for consistency - static std::shared_ptr Make( + static Result> Make( const GcsOptions& options, const io::IOContext& = io::default_io_context()); private: diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index d4d5edf4b899..888e2f13934b 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -76,7 +76,6 @@ class GcsTestbench : public ::testing::Environment { return; } - server_process->SetArgs({"--port", port_}); server_process->IgnoreStderr(); status = server_process->Execute(); if (!status.ok()) { @@ -271,7 +270,7 @@ class TestGCSFSGeneric : public GcsIntegrationTest, public GenericFileSystemTest void SetUp() override { ASSERT_NO_FATAL_FAILURE(GcsIntegrationTest::SetUp()); auto bucket_name = RandomBucketName(); - gcs_fs_ = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr gcs_fs_, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(gcs_fs_->CreateDir(bucket_name, true)); fs_ = std::make_shared(bucket_name, gcs_fs_); } @@ -489,7 +488,6 @@ TEST(GcsFileSystem, FileSystemCompare) { a_options.project_id = "test-only-invalid-project-id"; auto a = GcsFileSystem::Make(a_options); EXPECT_THAT(a, NotNull()); - EXPECT_TRUE(a->Equals(*a)); GcsOptions b_options; b_options.scheme = "http"; @@ -497,9 +495,6 @@ TEST(GcsFileSystem, FileSystemCompare) { b_options.project_id = "test-only-invalid-project-id"; auto b = GcsFileSystem::Make(b_options); EXPECT_THAT(b, NotNull()); - EXPECT_TRUE(b->Equals(*b)); - - EXPECT_FALSE(a->Equals(*b)); } std::shared_ptr KeyValueMetadataForTest() { @@ -622,7 +617,7 @@ TEST(GcsFileSystem, ObjectMetadataRoundtrip) { } TEST_F(GcsIntegrationTest, GetFileInfoBucket) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::AssertFileInfo(fs.get(), PreexistingBucketName(), FileType::Directory); // URI @@ -632,7 +627,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoBucket) { TEST_F(GcsIntegrationTest, GetFileInfoObjectWithNestedStructure) { // Adds detailed tests to handle cases of different edge cases // with directory naming conventions (e.g. with and without slashes). - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); constexpr auto kObjectName = "test-object-dir/some_other_dir/another_dir/foo"; ASSERT_OK_AND_ASSIGN( auto output, @@ -673,7 +668,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoObjectWithNestedStructure) { } TEST_F(GcsIntegrationTest, GetFileInfoObjectNoExplicitObject) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); auto object = GcsClient().GetObjectMetadata(PreexistingBucketName(), PreexistingObjectName()); ASSERT_TRUE(object.ok()) << "status=" << object.status(); @@ -685,7 +680,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoObjectNoExplicitObject) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorRecursive) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); std::vector expected; std::copy_if(hierarchy.contents.begin(), hierarchy.contents.end(), @@ -711,7 +706,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorRecursive) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorNonRecursive) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); std::vector expected; std::copy_if(hierarchy.contents.begin(), hierarchy.contents.end(), @@ -730,7 +725,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorNonRecursive) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorLimitedRecursion) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); for (const auto max_recursion : {0, 1, 2, 3}) { @@ -759,7 +754,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorLimitedRecursion) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundTrue) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); auto selector = FileSelector(); selector.base_dir = NotFoundObjectPath() + "/"; @@ -770,7 +765,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundTrue) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundFalse) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); auto selector = FileSelector(); selector.base_dir = NotFoundObjectPath() + "/"; @@ -780,34 +775,34 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundFalse) { } TEST_F(GcsIntegrationTest, CreateDirSuccessBucketOnly) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); auto bucket_name = RandomBucketName(); ASSERT_OK(fs->CreateDir(bucket_name, false)); arrow::fs::AssertFileInfo(fs.get(), bucket_name, FileType::Directory); } TEST_F(GcsIntegrationTest, CreateDirSuccessBucketAndFolder) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + RandomFolderName(); ASSERT_OK(fs->CreateDir(path, false)); arrow::fs::AssertFileInfo(fs.get(), path, FileType::Directory); } TEST_F(GcsIntegrationTest, CreateDirFailureFolderWithMissingBucket) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = std::string("not-a-bucket/new-folder"); ASSERT_RAISES(IOError, fs->CreateDir(path, false)); } TEST_F(GcsIntegrationTest, CreateDirRecursiveBucketOnly) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); auto bucket_name = RandomBucketName(); ASSERT_OK(fs->CreateDir(bucket_name, true)); arrow::fs::AssertFileInfo(fs.get(), bucket_name, FileType::Directory); } TEST_F(GcsIntegrationTest, CreateDirRecursiveFolderOnly) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto parent = PreexistingBucketPath() + RandomFolderName(); const auto path = internal::ConcatAbstractPath(parent, "new-sub"); ASSERT_OK(fs->CreateDir(path, true)); @@ -816,7 +811,7 @@ TEST_F(GcsIntegrationTest, CreateDirRecursiveFolderOnly) { } TEST_F(GcsIntegrationTest, CreateDirRecursiveBucketAndFolder) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); auto bucket_name = RandomBucketName(); const auto parent = internal::ConcatAbstractPath(bucket_name, RandomFolderName()); const auto path = internal::ConcatAbstractPath(parent, "new-sub"); @@ -827,12 +822,12 @@ TEST_F(GcsIntegrationTest, CreateDirRecursiveBucketAndFolder) { } TEST_F(GcsIntegrationTest, CreateDirUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->CreateDir("gs://" + RandomBucketName(), true)); } TEST_F(GcsIntegrationTest, CreateDirExtraneousSlashes) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->CreateDir(RandomBucketName() + "//somedir", /*recursive=*/true)); ASSERT_RAISES(Invalid, fs->CreateDir(RandomBucketName() + "/somedir//newdir", @@ -840,14 +835,14 @@ TEST_F(GcsIntegrationTest, CreateDirExtraneousSlashes) { } TEST_F(GcsIntegrationTest, DeleteBucketDirSuccess) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(fs->CreateDir("pyarrow-filesystem/", /*recursive=*/true)); ASSERT_RAISES(Invalid, fs->CreateDir("/", false)); ASSERT_OK(fs->DeleteDir("pyarrow-filesystem/")); } TEST_F(GcsIntegrationTest, DeleteDirSuccess) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); ASSERT_OK(fs->DeleteDir(hierarchy.base_dir)); @@ -862,18 +857,18 @@ TEST_F(GcsIntegrationTest, DeleteDirSuccess) { } TEST_F(GcsIntegrationTest, DeleteDirUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->DeleteDir("gs://" + PreexistingBucketPath())); } TEST_F(GcsIntegrationTest, DeleteDirExtraneousSlashes) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->DeleteDir(PreexistingBucketPath() + "/somedir")); ASSERT_RAISES(Invalid, fs->DeleteDir(PreexistingBucketPath() + "somedir//newdir")); } TEST_F(GcsIntegrationTest, DeleteDirContentsSuccess) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); ASSERT_OK(fs->DeleteDirContents(hierarchy.base_dir)); @@ -891,35 +886,35 @@ TEST_F(GcsIntegrationTest, DeleteDirContentsSuccess) { } TEST_F(GcsIntegrationTest, DeleteRootDirContents) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); EXPECT_RAISES_WITH_MESSAGE_THAT(NotImplemented, HasSubstr("too dangerous"), fs->DeleteRootDirContents()); } TEST_F(GcsIntegrationTest, DeleteFileSuccess) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(fs->DeleteFile(PreexistingObjectPath())); arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::NotFound); } TEST_F(GcsIntegrationTest, DeleteFileFailure) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->DeleteFile(NotFoundObjectPath())); } TEST_F(GcsIntegrationTest, DeleteFileDirectoryFails) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + "DeleteFileDirectoryFails/"; ASSERT_RAISES(IOError, fs->DeleteFile(path)); } TEST_F(GcsIntegrationTest, DeleteFileUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->DeleteFile("gs://" + PreexistingObjectPath())); } TEST_F(GcsIntegrationTest, MoveFileSuccess) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "move-destination"; ASSERT_OK(fs->Move(PreexistingObjectPath(), destination_path)); arrow::fs::AssertFileInfo(fs.get(), destination_path, FileType::File); @@ -927,45 +922,45 @@ TEST_F(GcsIntegrationTest, MoveFileSuccess) { } TEST_F(GcsIntegrationTest, MoveFileCannotRenameBuckets) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->Move(PreexistingBucketPath(), "another-bucket/")); } TEST_F(GcsIntegrationTest, MoveFileCannotRenameDirectories) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->Move(PreexistingBucketPath() + "folder/", PreexistingBucketPath() + "new-name")); } TEST_F(GcsIntegrationTest, MoveFileCannotRenameToDirectory) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(fs->CreateDir(PreexistingBucketPath() + "destination", false)); ASSERT_RAISES(IOError, fs->Move(PreexistingObjectPath(), PreexistingBucketPath() + "destination")); } TEST_F(GcsIntegrationTest, MoveFileUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "move-destination"; ASSERT_RAISES(Invalid, fs->Move("gs://" + PreexistingObjectPath(), destination_path)); ASSERT_RAISES(Invalid, fs->Move(PreexistingObjectPath(), "gs://" + destination_path)); } TEST_F(GcsIntegrationTest, CopyFileSuccess) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "copy-destination"; ASSERT_OK(fs->CopyFile(PreexistingObjectPath(), destination_path)); arrow::fs::AssertFileInfo(fs.get(), destination_path, FileType::File); } TEST_F(GcsIntegrationTest, CopyFileNotFound) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "copy-destination"; ASSERT_RAISES(IOError, fs->CopyFile(NotFoundObjectPath(), destination_path)); } TEST_F(GcsIntegrationTest, CopyFileUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "copy-destination"; ASSERT_RAISES(Invalid, fs->CopyFile("gs://" + PreexistingObjectPath(), destination_path)); @@ -974,7 +969,7 @@ TEST_F(GcsIntegrationTest, CopyFileUri) { } TEST_F(GcsIntegrationTest, OpenInputStreamString) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); std::shared_ptr stream; ASSERT_OK_AND_ASSIGN(stream, fs->OpenInputStream(PreexistingObjectPath())); @@ -987,7 +982,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamString) { } TEST_F(GcsIntegrationTest, OpenInputStreamStringBuffers) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); std::shared_ptr stream; ASSERT_OK_AND_ASSIGN(stream, fs->OpenInputStream(PreexistingObjectPath())); @@ -1003,7 +998,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamStringBuffers) { } TEST_F(GcsIntegrationTest, OpenInputStreamInfo) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingObjectPath())); @@ -1019,7 +1014,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamInfo) { } TEST_F(GcsIntegrationTest, OpenInputStreamEmpty) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto object_path = internal::ConcatAbstractPath(PreexistingBucketName(), "empty-object.txt"); @@ -1033,13 +1028,13 @@ TEST_F(GcsIntegrationTest, OpenInputStreamEmpty) { } TEST_F(GcsIntegrationTest, OpenInputStreamNotFound) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->OpenInputStream(NotFoundObjectPath())); } TEST_F(GcsIntegrationTest, OpenInputStreamInfoInvalid) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingBucketPath())); @@ -1050,7 +1045,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamInfoInvalid) { } TEST_F(GcsIntegrationTest, OpenInputStreamUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->OpenInputStream("gs://" + PreexistingObjectPath())); } @@ -1069,7 +1064,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamReadMetadata) { .upsert_metadata("key0", "value0"))) .value(); - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); std::shared_ptr stream; ASSERT_OK_AND_ASSIGN(stream, fs->OpenInputStream(PreexistingBucketPath() + object_name)); @@ -1117,7 +1112,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamReadMetadata) { } TEST_F(GcsIntegrationTest, OpenInputStreamClosed) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto stream, fs->OpenInputStream(PreexistingObjectPath())); ASSERT_OK(stream->Close()); @@ -1131,7 +1126,7 @@ TEST_F(GcsIntegrationTest, TestWriteWithDefaults) { auto options = TestGcsOptions(); options.default_bucket_location = "utopia"; options.default_metadata = arrow::key_value_metadata({{"foo", "bar"}}); - auto fs = GcsFileSystem::Make(options); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(options)); std::string bucket = "new_bucket_with_default_location"; auto file_name = "object_with_defaults"; ASSERT_OK(fs->CreateDir(bucket, /*recursive=*/false)); @@ -1172,7 +1167,7 @@ TEST_F(GcsIntegrationTest, TestWriteWithDefaults) { } TEST_F(GcsIntegrationTest, OpenOutputStreamSmall) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + "test-write-object"; std::shared_ptr output; @@ -1193,7 +1188,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamSmall) { } TEST_F(GcsIntegrationTest, OpenOutputStreamLarge) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + "test-write-object"; std::shared_ptr output; @@ -1229,7 +1224,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamLarge) { } TEST_F(GcsIntegrationTest, OpenOutputStreamClosed) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = internal::ConcatAbstractPath(PreexistingBucketName(), "open-output-stream-closed.txt"); @@ -1242,7 +1237,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamClosed) { } TEST_F(GcsIntegrationTest, OpenOutputStreamUri) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = internal::ConcatAbstractPath(PreexistingBucketName(), "open-output-stream-uri.txt"); @@ -1250,7 +1245,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamUri) { } TEST_F(GcsIntegrationTest, OpenInputFileMixedReadVsReadAt) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); // Create a file large enough to make the random access tests non-trivial. auto constexpr kLineWidth = 100; @@ -1302,7 +1297,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileMixedReadVsReadAt) { } TEST_F(GcsIntegrationTest, OpenInputFileRandomSeek) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); // Create a file large enough to make the random access tests non-trivial. auto constexpr kLineWidth = 100; @@ -1334,7 +1329,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileRandomSeek) { } TEST_F(GcsIntegrationTest, OpenInputFileIoContext) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); // Create a test file. const auto path = PreexistingBucketPath() + "OpenInputFileIoContext/object-name"; @@ -1350,7 +1345,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileIoContext) { } TEST_F(GcsIntegrationTest, OpenInputFileInfo) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingObjectPath())); @@ -1368,13 +1363,13 @@ TEST_F(GcsIntegrationTest, OpenInputFileInfo) { } TEST_F(GcsIntegrationTest, OpenInputFileNotFound) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->OpenInputFile(NotFoundObjectPath())); } TEST_F(GcsIntegrationTest, OpenInputFileInfoInvalid) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingBucketPath())); @@ -1385,7 +1380,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileInfoInvalid) { } TEST_F(GcsIntegrationTest, OpenInputFileClosed) { - auto fs = GcsFileSystem::Make(TestGcsOptions()); + ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto stream, fs->OpenInputFile(PreexistingObjectPath())); ASSERT_OK(stream->Close()); From 3922ca25054f265cdcfa4a6830f3e676a418bde8 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Wed, 23 Oct 2024 03:45:48 -0700 Subject: [PATCH 02/23] GH-32206: Comment removal, readability & auto re-implementation. --- cpp/src/arrow/filesystem/gcsfs.h | 2 -- cpp/src/arrow/filesystem/gcsfs_test.cc | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.h b/cpp/src/arrow/filesystem/gcsfs.h index 4bd67b1bf08b..cd638647ee35 100644 --- a/cpp/src/arrow/filesystem/gcsfs.h +++ b/cpp/src/arrow/filesystem/gcsfs.h @@ -230,8 +230,6 @@ class ARROW_EXPORT GcsFileSystem : public FileSystem { const std::string& path, const std::shared_ptr& metadata) override; - /// Create a GcsFileSystem instance from the given options. - // TODO(ARROW-16884): make this return Result for consistency static Result> Make( const GcsOptions& options, const io::IOContext& = io::default_io_context()); diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index 888e2f13934b..82815bc80896 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -270,7 +270,8 @@ class TestGCSFSGeneric : public GcsIntegrationTest, public GenericFileSystemTest void SetUp() override { ASSERT_NO_FATAL_FAILURE(GcsIntegrationTest::SetUp()); auto bucket_name = RandomBucketName(); - ASSERT_OK_AND_ASSIGN(std::shared_ptr gcs_fs_, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(std::shared_ptr gcs_fs_, +GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(gcs_fs_->CreateDir(bucket_name, true)); fs_ = std::make_shared(bucket_name, gcs_fs_); } @@ -486,8 +487,9 @@ TEST(GcsFileSystem, FileSystemCompare) { GcsOptions a_options; a_options.scheme = "http"; a_options.project_id = "test-only-invalid-project-id"; - auto a = GcsFileSystem::Make(a_options); + ASSERT_OK_AND_ASSIGN(auto a, GcsFileSystem::Make(a_options)); EXPECT_THAT(a, NotNull()); + EXPECT_TRUE(a->Equals(*a)); GcsOptions b_options; b_options.scheme = "http"; @@ -617,7 +619,7 @@ TEST(GcsFileSystem, ObjectMetadataRoundtrip) { } TEST_F(GcsIntegrationTest, GetFileInfoBucket) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::AssertFileInfo(fs.get(), PreexistingBucketName(), FileType::Directory); // URI From c20ecfacca01f8faa612283d4fe066d90e73e9c0 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Tue, 22 Oct 2024 10:59:07 -0800 Subject: [PATCH 03/23] GH-32206: Adding back port_ for storage-testbench. --- cpp/src/arrow/filesystem/gcsfs_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index 82815bc80896..dfa5908b554d 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -76,6 +76,7 @@ class GcsTestbench : public ::testing::Environment { return; } + server_process->SetArgs({"--port", port_}); server_process->IgnoreStderr(); status = server_process->Execute(); if (!status.ok()) { From cf49e94d7c26ec6c8ee8e6588597197b5babb2ac Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Wed, 23 Oct 2024 16:52:46 -0700 Subject: [PATCH 04/23] GH-32206: Reverting auto keyword removal. --- cpp/src/arrow/filesystem/gcsfs.h | 1 + cpp/src/arrow/filesystem/gcsfs_test.cc | 120 +++++++++++++------------ 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.h b/cpp/src/arrow/filesystem/gcsfs.h index cd638647ee35..6a1c867abc72 100644 --- a/cpp/src/arrow/filesystem/gcsfs.h +++ b/cpp/src/arrow/filesystem/gcsfs.h @@ -230,6 +230,7 @@ class ARROW_EXPORT GcsFileSystem : public FileSystem { const std::string& path, const std::shared_ptr& metadata) override; + /// Create a GcsFileSystem instance from the given options. static Result> Make( const GcsOptions& options, const io::IOContext& = io::default_io_context()); diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index dfa5908b554d..e519f0f18654 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -66,7 +66,8 @@ culpa qui officia deserunt mollit anim id est laborum. class GcsTestbench : public ::testing::Environment { public: GcsTestbench() { - port_ = std::to_string(GetListenPort()); + // port_ = std::to_string(GetListenPort()); + port_ = "9000"; auto error = std::string("Could not start GCS emulator 'storage-testbench'"); auto server_process = std::make_unique(); auto status = server_process->SetExecutable("storage-testbench"); @@ -76,7 +77,7 @@ class GcsTestbench : public ::testing::Environment { return; } - server_process->SetArgs({"--port", port_}); + // server_process->SetArgs({"--port", port_}); server_process->IgnoreStderr(); status = server_process->Execute(); if (!status.ok()) { @@ -271,7 +272,7 @@ class TestGCSFSGeneric : public GcsIntegrationTest, public GenericFileSystemTest void SetUp() override { ASSERT_NO_FATAL_FAILURE(GcsIntegrationTest::SetUp()); auto bucket_name = RandomBucketName(); - ASSERT_OK_AND_ASSIGN(std::shared_ptr gcs_fs_, + ASSERT_OK_AND_ASSIGN(gcs_fs_, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(gcs_fs_->CreateDir(bucket_name, true)); fs_ = std::make_shared(bucket_name, gcs_fs_); @@ -496,8 +497,11 @@ TEST(GcsFileSystem, FileSystemCompare) { b_options.scheme = "http"; b_options.endpoint_override = "localhost:1234"; b_options.project_id = "test-only-invalid-project-id"; - auto b = GcsFileSystem::Make(b_options); + ASSERT_OK_AND_ASSIGN(auto b, GcsFileSystem::Make(b_options)); EXPECT_THAT(b, NotNull()); + EXPECT_TRUE(b->Equals(*b)); + + EXPECT_FALSE(a->Equals(*b)); } std::shared_ptr KeyValueMetadataForTest() { @@ -630,7 +634,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoBucket) { TEST_F(GcsIntegrationTest, GetFileInfoObjectWithNestedStructure) { // Adds detailed tests to handle cases of different edge cases // with directory naming conventions (e.g. with and without slashes). - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); constexpr auto kObjectName = "test-object-dir/some_other_dir/another_dir/foo"; ASSERT_OK_AND_ASSIGN( auto output, @@ -671,7 +675,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoObjectWithNestedStructure) { } TEST_F(GcsIntegrationTest, GetFileInfoObjectNoExplicitObject) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); auto object = GcsClient().GetObjectMetadata(PreexistingBucketName(), PreexistingObjectName()); ASSERT_TRUE(object.ok()) << "status=" << object.status(); @@ -683,7 +687,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoObjectNoExplicitObject) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorRecursive) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); std::vector expected; std::copy_if(hierarchy.contents.begin(), hierarchy.contents.end(), @@ -709,7 +713,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorRecursive) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorNonRecursive) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); std::vector expected; std::copy_if(hierarchy.contents.begin(), hierarchy.contents.end(), @@ -728,7 +732,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorNonRecursive) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorLimitedRecursion) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); for (const auto max_recursion : {0, 1, 2, 3}) { @@ -757,7 +761,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorLimitedRecursion) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundTrue) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); auto selector = FileSelector(); selector.base_dir = NotFoundObjectPath() + "/"; @@ -768,7 +772,7 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundTrue) { } TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundFalse) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); auto selector = FileSelector(); selector.base_dir = NotFoundObjectPath() + "/"; @@ -778,34 +782,34 @@ TEST_F(GcsIntegrationTest, GetFileInfoSelectorNotFoundFalse) { } TEST_F(GcsIntegrationTest, CreateDirSuccessBucketOnly) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); auto bucket_name = RandomBucketName(); ASSERT_OK(fs->CreateDir(bucket_name, false)); arrow::fs::AssertFileInfo(fs.get(), bucket_name, FileType::Directory); } TEST_F(GcsIntegrationTest, CreateDirSuccessBucketAndFolder) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + RandomFolderName(); ASSERT_OK(fs->CreateDir(path, false)); arrow::fs::AssertFileInfo(fs.get(), path, FileType::Directory); } TEST_F(GcsIntegrationTest, CreateDirFailureFolderWithMissingBucket) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = std::string("not-a-bucket/new-folder"); ASSERT_RAISES(IOError, fs->CreateDir(path, false)); } TEST_F(GcsIntegrationTest, CreateDirRecursiveBucketOnly) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); auto bucket_name = RandomBucketName(); ASSERT_OK(fs->CreateDir(bucket_name, true)); arrow::fs::AssertFileInfo(fs.get(), bucket_name, FileType::Directory); } TEST_F(GcsIntegrationTest, CreateDirRecursiveFolderOnly) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto parent = PreexistingBucketPath() + RandomFolderName(); const auto path = internal::ConcatAbstractPath(parent, "new-sub"); ASSERT_OK(fs->CreateDir(path, true)); @@ -814,7 +818,7 @@ TEST_F(GcsIntegrationTest, CreateDirRecursiveFolderOnly) { } TEST_F(GcsIntegrationTest, CreateDirRecursiveBucketAndFolder) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); auto bucket_name = RandomBucketName(); const auto parent = internal::ConcatAbstractPath(bucket_name, RandomFolderName()); const auto path = internal::ConcatAbstractPath(parent, "new-sub"); @@ -825,12 +829,12 @@ TEST_F(GcsIntegrationTest, CreateDirRecursiveBucketAndFolder) { } TEST_F(GcsIntegrationTest, CreateDirUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->CreateDir("gs://" + RandomBucketName(), true)); } TEST_F(GcsIntegrationTest, CreateDirExtraneousSlashes) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->CreateDir(RandomBucketName() + "//somedir", /*recursive=*/true)); ASSERT_RAISES(Invalid, fs->CreateDir(RandomBucketName() + "/somedir//newdir", @@ -838,14 +842,14 @@ TEST_F(GcsIntegrationTest, CreateDirExtraneousSlashes) { } TEST_F(GcsIntegrationTest, DeleteBucketDirSuccess) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(fs->CreateDir("pyarrow-filesystem/", /*recursive=*/true)); ASSERT_RAISES(Invalid, fs->CreateDir("/", false)); ASSERT_OK(fs->DeleteDir("pyarrow-filesystem/")); } TEST_F(GcsIntegrationTest, DeleteDirSuccess) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); ASSERT_OK(fs->DeleteDir(hierarchy.base_dir)); @@ -860,18 +864,18 @@ TEST_F(GcsIntegrationTest, DeleteDirSuccess) { } TEST_F(GcsIntegrationTest, DeleteDirUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->DeleteDir("gs://" + PreexistingBucketPath())); } TEST_F(GcsIntegrationTest, DeleteDirExtraneousSlashes) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->DeleteDir(PreexistingBucketPath() + "/somedir")); ASSERT_RAISES(Invalid, fs->DeleteDir(PreexistingBucketPath() + "somedir//newdir")); } TEST_F(GcsIntegrationTest, DeleteDirContentsSuccess) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto hierarchy, CreateHierarchy(fs)); ASSERT_OK(fs->DeleteDirContents(hierarchy.base_dir)); @@ -889,35 +893,35 @@ TEST_F(GcsIntegrationTest, DeleteDirContentsSuccess) { } TEST_F(GcsIntegrationTest, DeleteRootDirContents) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); EXPECT_RAISES_WITH_MESSAGE_THAT(NotImplemented, HasSubstr("too dangerous"), fs->DeleteRootDirContents()); } TEST_F(GcsIntegrationTest, DeleteFileSuccess) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(fs->DeleteFile(PreexistingObjectPath())); arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::NotFound); } TEST_F(GcsIntegrationTest, DeleteFileFailure) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->DeleteFile(NotFoundObjectPath())); } TEST_F(GcsIntegrationTest, DeleteFileDirectoryFails) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + "DeleteFileDirectoryFails/"; ASSERT_RAISES(IOError, fs->DeleteFile(path)); } TEST_F(GcsIntegrationTest, DeleteFileUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->DeleteFile("gs://" + PreexistingObjectPath())); } TEST_F(GcsIntegrationTest, MoveFileSuccess) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "move-destination"; ASSERT_OK(fs->Move(PreexistingObjectPath(), destination_path)); arrow::fs::AssertFileInfo(fs.get(), destination_path, FileType::File); @@ -925,45 +929,45 @@ TEST_F(GcsIntegrationTest, MoveFileSuccess) { } TEST_F(GcsIntegrationTest, MoveFileCannotRenameBuckets) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->Move(PreexistingBucketPath(), "another-bucket/")); } TEST_F(GcsIntegrationTest, MoveFileCannotRenameDirectories) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->Move(PreexistingBucketPath() + "folder/", PreexistingBucketPath() + "new-name")); } TEST_F(GcsIntegrationTest, MoveFileCannotRenameToDirectory) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(fs->CreateDir(PreexistingBucketPath() + "destination", false)); ASSERT_RAISES(IOError, fs->Move(PreexistingObjectPath(), PreexistingBucketPath() + "destination")); } TEST_F(GcsIntegrationTest, MoveFileUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "move-destination"; ASSERT_RAISES(Invalid, fs->Move("gs://" + PreexistingObjectPath(), destination_path)); ASSERT_RAISES(Invalid, fs->Move(PreexistingObjectPath(), "gs://" + destination_path)); } TEST_F(GcsIntegrationTest, CopyFileSuccess) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "copy-destination"; ASSERT_OK(fs->CopyFile(PreexistingObjectPath(), destination_path)); arrow::fs::AssertFileInfo(fs.get(), destination_path, FileType::File); } TEST_F(GcsIntegrationTest, CopyFileNotFound) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "copy-destination"; ASSERT_RAISES(IOError, fs->CopyFile(NotFoundObjectPath(), destination_path)); } TEST_F(GcsIntegrationTest, CopyFileUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto destination_path = PreexistingBucketPath() + "copy-destination"; ASSERT_RAISES(Invalid, fs->CopyFile("gs://" + PreexistingObjectPath(), destination_path)); @@ -972,7 +976,7 @@ TEST_F(GcsIntegrationTest, CopyFileUri) { } TEST_F(GcsIntegrationTest, OpenInputStreamString) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); std::shared_ptr stream; ASSERT_OK_AND_ASSIGN(stream, fs->OpenInputStream(PreexistingObjectPath())); @@ -985,7 +989,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamString) { } TEST_F(GcsIntegrationTest, OpenInputStreamStringBuffers) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); std::shared_ptr stream; ASSERT_OK_AND_ASSIGN(stream, fs->OpenInputStream(PreexistingObjectPath())); @@ -1001,7 +1005,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamStringBuffers) { } TEST_F(GcsIntegrationTest, OpenInputStreamInfo) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingObjectPath())); @@ -1017,7 +1021,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamInfo) { } TEST_F(GcsIntegrationTest, OpenInputStreamEmpty) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto object_path = internal::ConcatAbstractPath(PreexistingBucketName(), "empty-object.txt"); @@ -1031,13 +1035,13 @@ TEST_F(GcsIntegrationTest, OpenInputStreamEmpty) { } TEST_F(GcsIntegrationTest, OpenInputStreamNotFound) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->OpenInputStream(NotFoundObjectPath())); } TEST_F(GcsIntegrationTest, OpenInputStreamInfoInvalid) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingBucketPath())); @@ -1048,7 +1052,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamInfoInvalid) { } TEST_F(GcsIntegrationTest, OpenInputStreamUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(Invalid, fs->OpenInputStream("gs://" + PreexistingObjectPath())); } @@ -1067,7 +1071,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamReadMetadata) { .upsert_metadata("key0", "value0"))) .value(); - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); std::shared_ptr stream; ASSERT_OK_AND_ASSIGN(stream, fs->OpenInputStream(PreexistingBucketPath() + object_name)); @@ -1115,7 +1119,7 @@ TEST_F(GcsIntegrationTest, OpenInputStreamReadMetadata) { } TEST_F(GcsIntegrationTest, OpenInputStreamClosed) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto stream, fs->OpenInputStream(PreexistingObjectPath())); ASSERT_OK(stream->Close()); @@ -1129,7 +1133,7 @@ TEST_F(GcsIntegrationTest, TestWriteWithDefaults) { auto options = TestGcsOptions(); options.default_bucket_location = "utopia"; options.default_metadata = arrow::key_value_metadata({{"foo", "bar"}}); - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(options)); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(options)); std::string bucket = "new_bucket_with_default_location"; auto file_name = "object_with_defaults"; ASSERT_OK(fs->CreateDir(bucket, /*recursive=*/false)); @@ -1170,7 +1174,7 @@ TEST_F(GcsIntegrationTest, TestWriteWithDefaults) { } TEST_F(GcsIntegrationTest, OpenOutputStreamSmall) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + "test-write-object"; std::shared_ptr output; @@ -1191,7 +1195,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamSmall) { } TEST_F(GcsIntegrationTest, OpenOutputStreamLarge) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = PreexistingBucketPath() + "test-write-object"; std::shared_ptr output; @@ -1227,7 +1231,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamLarge) { } TEST_F(GcsIntegrationTest, OpenOutputStreamClosed) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = internal::ConcatAbstractPath(PreexistingBucketName(), "open-output-stream-closed.txt"); @@ -1240,7 +1244,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamClosed) { } TEST_F(GcsIntegrationTest, OpenOutputStreamUri) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); const auto path = internal::ConcatAbstractPath(PreexistingBucketName(), "open-output-stream-uri.txt"); @@ -1248,7 +1252,7 @@ TEST_F(GcsIntegrationTest, OpenOutputStreamUri) { } TEST_F(GcsIntegrationTest, OpenInputFileMixedReadVsReadAt) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); // Create a file large enough to make the random access tests non-trivial. auto constexpr kLineWidth = 100; @@ -1300,7 +1304,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileMixedReadVsReadAt) { } TEST_F(GcsIntegrationTest, OpenInputFileRandomSeek) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); // Create a file large enough to make the random access tests non-trivial. auto constexpr kLineWidth = 100; @@ -1332,7 +1336,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileRandomSeek) { } TEST_F(GcsIntegrationTest, OpenInputFileIoContext) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); // Create a test file. const auto path = PreexistingBucketPath() + "OpenInputFileIoContext/object-name"; @@ -1348,7 +1352,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileIoContext) { } TEST_F(GcsIntegrationTest, OpenInputFileInfo) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingObjectPath())); @@ -1366,13 +1370,13 @@ TEST_F(GcsIntegrationTest, OpenInputFileInfo) { } TEST_F(GcsIntegrationTest, OpenInputFileNotFound) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_RAISES(IOError, fs->OpenInputFile(NotFoundObjectPath())); } TEST_F(GcsIntegrationTest, OpenInputFileInfoInvalid) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); arrow::fs::FileInfo info; ASSERT_OK_AND_ASSIGN(info, fs->GetFileInfo(PreexistingBucketPath())); @@ -1383,7 +1387,7 @@ TEST_F(GcsIntegrationTest, OpenInputFileInfoInvalid) { } TEST_F(GcsIntegrationTest, OpenInputFileClosed) { - ASSERT_OK_AND_ASSIGN(std::shared_ptr fs, GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK_AND_ASSIGN(auto stream, fs->OpenInputFile(PreexistingObjectPath())); ASSERT_OK(stream->Close()); From efb48e939b872b50707bb44bb94ca1b1c3f7b105 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Wed, 23 Oct 2024 17:00:44 -0700 Subject: [PATCH 05/23] GH-32206: Reverting erroneous port change. --- cpp/src/arrow/filesystem/gcsfs_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index e519f0f18654..37c250ffe2fd 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -66,8 +66,7 @@ culpa qui officia deserunt mollit anim id est laborum. class GcsTestbench : public ::testing::Environment { public: GcsTestbench() { - // port_ = std::to_string(GetListenPort()); - port_ = "9000"; + port_ = std::to_string(GetListenPort()); auto error = std::string("Could not start GCS emulator 'storage-testbench'"); auto server_process = std::make_unique(); auto status = server_process->SetExecutable("storage-testbench"); @@ -77,7 +76,7 @@ class GcsTestbench : public ::testing::Environment { return; } - // server_process->SetArgs({"--port", port_}); + server_process->SetArgs({"--port", port_}); server_process->IgnoreStderr(); status = server_process->Execute(); if (!status.ok()) { From 8f5a259ee0a8ba82ed2183f65f83f973b3f1a583 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Wed, 23 Oct 2024 17:27:03 -0800 Subject: [PATCH 06/23] GH-32206: Formatting fix. --- 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 37c250ffe2fd..0e457b2d502f 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -271,8 +271,7 @@ class TestGCSFSGeneric : public GcsIntegrationTest, public GenericFileSystemTest void SetUp() override { ASSERT_NO_FATAL_FAILURE(GcsIntegrationTest::SetUp()); auto bucket_name = RandomBucketName(); - ASSERT_OK_AND_ASSIGN(gcs_fs_, -GcsFileSystem::Make(TestGcsOptions())); + ASSERT_OK_AND_ASSIGN(gcs_fs_, GcsFileSystem::Make(TestGcsOptions())); ASSERT_OK(gcs_fs_->CreateDir(bucket_name, true)); fs_ = std::make_shared(bucket_name, gcs_fs_); } From 86d4e28c91002560f5f3d740edb1b600791eb970 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Wed, 23 Oct 2024 17:57:38 -0800 Subject: [PATCH 07/23] GH-32206: Maintaining indentation consistency. --- cpp/src/arrow/filesystem/gcsfs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.cc b/cpp/src/arrow/filesystem/gcsfs.cc index fe6363d346f2..035f6a22cf36 100644 --- a/cpp/src/arrow/filesystem/gcsfs.cc +++ b/cpp/src/arrow/filesystem/gcsfs.cc @@ -963,7 +963,7 @@ Result> GcsFileSystem::OpenAppendStream( } Result> GcsFileSystem::Make(const GcsOptions& options, - const io::IOContext& context) { + const io::IOContext& context) { // Cannot use `std::make_shared<>` as the constructor is private. return std::shared_ptr(new GcsFileSystem(options, context)); } From 6c4e3115b5c1771be6c0e3d6c7a7a4b07faf4504 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Wed, 23 Oct 2024 21:46:57 -0800 Subject: [PATCH 08/23] GH-32206: Matching style of method signature with OpenAppendStream. --- cpp/src/arrow/filesystem/gcsfs.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.cc b/cpp/src/arrow/filesystem/gcsfs.cc index 035f6a22cf36..06b29b272feb 100644 --- a/cpp/src/arrow/filesystem/gcsfs.cc +++ b/cpp/src/arrow/filesystem/gcsfs.cc @@ -962,8 +962,8 @@ Result> GcsFileSystem::OpenAppendStream( return Status::NotImplemented("Append is not supported in GCS"); } -Result> GcsFileSystem::Make(const GcsOptions& options, - const io::IOContext& context) { +Result> GcsFileSystem::Make( + const GcsOptions& options, const io::IOContext& context) { // Cannot use `std::make_shared<>` as the constructor is private. return std::shared_ptr(new GcsFileSystem(options, context)); } From a8cd04833c1327796bc0adea5674885db06b907b Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Thu, 24 Oct 2024 05:40:18 -0700 Subject: [PATCH 09/23] GH-32206: pre-commit lint changes. --- cpp/src/arrow/filesystem/gcsfs.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.cc b/cpp/src/arrow/filesystem/gcsfs.cc index 06b29b272feb..bbd934a39547 100644 --- a/cpp/src/arrow/filesystem/gcsfs.cc +++ b/cpp/src/arrow/filesystem/gcsfs.cc @@ -962,8 +962,8 @@ Result> GcsFileSystem::OpenAppendStream( return Status::NotImplemented("Append is not supported in GCS"); } -Result> GcsFileSystem::Make( - const GcsOptions& options, const io::IOContext& context) { +Result> GcsFileSystem::Make(const GcsOptions& options, + const io::IOContext& context) { // Cannot use `std::make_shared<>` as the constructor is private. return std::shared_ptr(new GcsFileSystem(options, context)); } From b9d6cdb6181036455555e709bb9c92f0bfb0c56d Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Thu, 24 Oct 2024 17:28:12 -0700 Subject: [PATCH 10/23] GH-32206: Added old signature back, marked for deprecation. --- cpp/src/arrow/filesystem/gcsfs.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpp/src/arrow/filesystem/gcsfs.h b/cpp/src/arrow/filesystem/gcsfs.h index 6a1c867abc72..ba8db8bdbc5f 100644 --- a/cpp/src/arrow/filesystem/gcsfs.h +++ b/cpp/src/arrow/filesystem/gcsfs.h @@ -230,6 +230,10 @@ class ARROW_EXPORT GcsFileSystem : public FileSystem { const std::string& path, const std::shared_ptr& metadata) override; + ARROW_DEPRECATED("Deprecated in 19.0.0. Use the Result version instead.") + static std::shared_ptr Make( + const GcsOptions& options, const io::IOContext& = io::default_io_context()); + /// Create a GcsFileSystem instance from the given options. static Result> Make( const GcsOptions& options, const io::IOContext& = io::default_io_context()); From 4271a8a27cf5daa92604ebf49d351c4d53ff1412 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Thu, 24 Oct 2024 20:31:43 -0700 Subject: [PATCH 11/23] GH-32206: Aligning R's GcsFileSystem::Make call with new definition. --- cpp/src/arrow/filesystem/gcsfs.h | 4 ---- r/src/filesystem.cpp | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.h b/cpp/src/arrow/filesystem/gcsfs.h index ba8db8bdbc5f..6a1c867abc72 100644 --- a/cpp/src/arrow/filesystem/gcsfs.h +++ b/cpp/src/arrow/filesystem/gcsfs.h @@ -230,10 +230,6 @@ class ARROW_EXPORT GcsFileSystem : public FileSystem { const std::string& path, const std::shared_ptr& metadata) override; - ARROW_DEPRECATED("Deprecated in 19.0.0. Use the Result version instead.") - static std::shared_ptr Make( - const GcsOptions& options, const io::IOContext& = io::default_io_context()); - /// Create a GcsFileSystem instance from the given options. static Result> Make( const GcsOptions& options, const io::IOContext& = io::default_io_context()); diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 2274a3d7ff7a..fecbf92266b9 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -359,8 +359,8 @@ void FinalizeS3() { std::shared_ptr strings_to_kvm(cpp11::strings metadata); // [[gcs::export]] -std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, - cpp11::list options) { +Result> fs___GcsFileSystem__Make(bool anonymous, + cpp11::list options) { fs::GcsOptions gcs_opts; // Handle auth (anonymous, credentials, default) @@ -429,7 +429,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, } auto io_context = MainRThread::GetInstance().CancellableIOContext(); - // TODO(ARROW-16884): update when this returns Result + return fs::GcsFileSystem::Make(gcs_opts, io_context); } From 7bce488a14962396f5909f2c33fb24d8d4f97e87 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Fri, 25 Oct 2024 06:07:40 -0700 Subject: [PATCH 12/23] GH-32206: Adding ARROW_ASSIGN_OR_RAISE for GcsFileSystem::Make. --- r/src/filesystem.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index fecbf92266b9..93a37cff664f 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -359,8 +359,8 @@ void FinalizeS3() { std::shared_ptr strings_to_kvm(cpp11::strings metadata); // [[gcs::export]] -Result> fs___GcsFileSystem__Make(bool anonymous, - cpp11::list options) { +std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, + cpp11::list options) { fs::GcsOptions gcs_opts; // Handle auth (anonymous, credentials, default) @@ -430,7 +430,8 @@ Result> fs___GcsFileSystem__Make(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); - return fs::GcsFileSystem::Make(gcs_opts, io_context); + ARROW_ASSIGN_OR_RAISE(auto gcs_fs_, fs::GcsFileSystem::Make(gcs_opts, io_context)); + return gcs_fs_; } // [[gcs::export]] From 846b31854fae3d8d6d4af599627fe05da057fcef Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Fri, 25 Oct 2024 09:06:26 -0800 Subject: [PATCH 13/23] GH-32206: R changes for GcsFileSystem and arrowExports due to pre-commit. --- r/src/arrowExports.cpp | 2 +- r/src/filesystem.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/r/src/arrowExports.cpp b/r/src/arrowExports.cpp index d5aec50219e0..045d84c8067d 100644 --- a/r/src/arrowExports.cpp +++ b/r/src/arrowExports.cpp @@ -3575,7 +3575,7 @@ END_CPP11 } // filesystem.cpp #if defined(ARROW_R_WITH_GCS) -std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, cpp11::list options); +std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, cpp11::list options); extern "C" SEXP _arrow_fs___GcsFileSystem__Make(SEXP anonymous_sexp, SEXP options_sexp){ BEGIN_CPP11 arrow::r::Input::type anonymous(anonymous_sexp); diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 93a37cff664f..21cd8011f7ba 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -359,8 +359,8 @@ void FinalizeS3() { std::shared_ptr strings_to_kvm(cpp11::strings metadata); // [[gcs::export]] -std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, - cpp11::list options) { +std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, + cpp11::list options) { fs::GcsOptions gcs_opts; // Handle auth (anonymous, credentials, default) @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); - ARROW_ASSIGN_OR_RAISE(auto gcs_fs_, fs::GcsFileSystem::Make(gcs_opts, io_context)); + auto gcs_fs_ = fs::GcsFileSystem::Make(gcs_opts, io_context); return gcs_fs_; } From d0ad8b75a5cfc618aa74f2ba81bd8c1bb5fcd72f Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Fri, 25 Oct 2024 10:14:53 -0800 Subject: [PATCH 14/23] GH-32206: Enabling ARROW_ASSIGN_OR_RAISE to maintain return type consistency. --- r/src/filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 21cd8011f7ba..8685b54e98ec 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymou auto io_context = MainRThread::GetInstance().CancellableIOContext(); - auto gcs_fs_ = fs::GcsFileSystem::Make(gcs_opts, io_context); + ARROW_ASSIGN_OR_RAISE(auto gcs_fs_, fs::GcsFileSystem::Make(gcs_opts, io_context); return gcs_fs_; } From 3afd8043399954fed86cda243ca229a26fc83e50 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Fri, 25 Oct 2024 11:04:14 -0800 Subject: [PATCH 15/23] GH-32206: Trying ValueOrStop for GcsFileSystem::Make call (like for S3 in this file). --- r/src/filesystem.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 8685b54e98ec..4261c5afb743 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,8 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymou auto io_context = MainRThread::GetInstance().CancellableIOContext(); - ARROW_ASSIGN_OR_RAISE(auto gcs_fs_, fs::GcsFileSystem::Make(gcs_opts, io_context); - return gcs_fs_; + return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); } // [[gcs::export]] From 95915c433d89d760dd65db717eb6be518aeb56a1 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Fri, 25 Oct 2024 18:04:09 -0800 Subject: [PATCH 16/23] GH-32206: Adding scope-resolution operator for ValueOrStop. --- r/src/filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 4261c5afb743..6dc430f3cf30 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymou auto io_context = MainRThread::GetInstance().CancellableIOContext(); - return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); + return arrow::ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); } // [[gcs::export]] From d10c51fcf91f44b1f617aec042d6ff340027747c Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Fri, 25 Oct 2024 18:45:59 -0800 Subject: [PATCH 17/23] GH-32206: Matching GcsFileSystem signature to S3. --- r/src/filesystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 6dc430f3cf30..7b76cabcce67 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -359,7 +359,7 @@ void FinalizeS3() { std::shared_ptr strings_to_kvm(cpp11::strings metadata); // [[gcs::export]] -std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, +std::shared_ptr fs___GcsFileSystem__create(bool anonymous, cpp11::list options) { fs::GcsOptions gcs_opts; @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymou auto io_context = MainRThread::GetInstance().CancellableIOContext(); - return arrow::ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); + return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); } // [[gcs::export]] From 3aaaa1733ae0887abd64519cc85e032518581eb3 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Fri, 25 Oct 2024 19:19:46 -0800 Subject: [PATCH 18/23] GH-32206: Adding global resolution operator. --- r/src/filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 7b76cabcce67..c7fafb1918ba 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__create(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); - return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); + return ::arrow::ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); } // [[gcs::export]] From 0d794fe1bbc8e52a542d2409267440e7affdb9ec Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Fri, 25 Oct 2024 19:59:32 -0800 Subject: [PATCH 19/23] GH-32206: Removing ValueOrStop for R (GcsFileSystem). --- cpp/src/arrow/filesystem/gcsfs.cc | 7 ++++--- r/src/arrowExports.cpp | 2 +- r/src/filesystem.cpp | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs.cc b/cpp/src/arrow/filesystem/gcsfs.cc index bbd934a39547..9869687a8b9d 100644 --- a/cpp/src/arrow/filesystem/gcsfs.cc +++ b/cpp/src/arrow/filesystem/gcsfs.cc @@ -962,10 +962,11 @@ Result> GcsFileSystem::OpenAppendStream( return Status::NotImplemented("Append is not supported in GCS"); } -Result> GcsFileSystem::Make(const GcsOptions& options, - const io::IOContext& context) { +Result> GcsFileSystem::Make( + const GcsOptions& options, const io::IOContext& io_context) { // Cannot use `std::make_shared<>` as the constructor is private. - return std::shared_ptr(new GcsFileSystem(options, context)); + std::shared_ptr ptr(new GcsFileSystem(options, io_context)); + return ptr; } GcsFileSystem::GcsFileSystem(const GcsOptions& options, const io::IOContext& context) diff --git a/r/src/arrowExports.cpp b/r/src/arrowExports.cpp index 045d84c8067d..d5aec50219e0 100644 --- a/r/src/arrowExports.cpp +++ b/r/src/arrowExports.cpp @@ -3575,7 +3575,7 @@ END_CPP11 } // filesystem.cpp #if defined(ARROW_R_WITH_GCS) -std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, cpp11::list options); +std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, cpp11::list options); extern "C" SEXP _arrow_fs___GcsFileSystem__Make(SEXP anonymous_sexp, SEXP options_sexp){ BEGIN_CPP11 arrow::r::Input::type anonymous(anonymous_sexp); diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index c7fafb1918ba..337cba37287e 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -359,8 +359,8 @@ void FinalizeS3() { std::shared_ptr strings_to_kvm(cpp11::strings metadata); // [[gcs::export]] -std::shared_ptr fs___GcsFileSystem__create(bool anonymous, - cpp11::list options) { +std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, + cpp11::list options) { fs::GcsOptions gcs_opts; // Handle auth (anonymous, credentials, default) @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__create(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); - return ::arrow::ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); + return fs::GcsFileSystem::Make(gcs_opts, io_context); } // [[gcs::export]] From 432a50e5dfdecc84de81f0ffabc1951cce5b5836 Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Fri, 25 Oct 2024 20:34:38 -0800 Subject: [PATCH 20/23] GH-32206: Testing ValueOrStop. --- r/src/filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 337cba37287e..8f1d0cdaf104 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); - return fs::GcsFileSystem::Make(gcs_opts, io_context); + return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); } // [[gcs::export]] From 6a6c1f7561a7f8d92b6e4f5cbc7c5af6e07080f9 Mon Sep 17 00:00:00 2001 From: Gabriel Stone Date: Sat, 26 Oct 2024 05:17:59 -0800 Subject: [PATCH 21/23] GH-32206: Adding preprocessor directive for conditional new Make() call. --- r/src/filesystem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 8f1d0cdaf104..9441ba927666 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,7 +430,11 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); +#if ARROW_VERSION_MAJOR >= 19 return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); +#else + return fs::GcsFileSystem::Make(gcs_opts, io_context); +#endif } // [[gcs::export]] From 700359ea2dca9f90fe794f28d516cc4c031bd89a Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Sat, 26 Oct 2024 05:39:36 -0800 Subject: [PATCH 22/23] GH-32206: Lowering major version to 18. --- r/src/filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 9441ba927666..5fdce2d7d778 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -430,7 +430,7 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, auto io_context = MainRThread::GetInstance().CancellableIOContext(); -#if ARROW_VERSION_MAJOR >= 19 +#if ARROW_VERSION_MAJOR >= 18 return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); #else return fs::GcsFileSystem::Make(gcs_opts, io_context); From 51cbac705f3b398e3b67e6931bfe9c0ebab39ead Mon Sep 17 00:00:00 2001 From: Gabriel P Stone Date: Sat, 26 Oct 2024 13:19:26 -0800 Subject: [PATCH 23/23] GH-32206: Removing unneccessary diff. Co-authored-by: Sutou Kouhei --- r/src/filesystem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp index 5fdce2d7d778..95f19e4f2f25 100644 --- a/r/src/filesystem.cpp +++ b/r/src/filesystem.cpp @@ -429,7 +429,6 @@ std::shared_ptr fs___GcsFileSystem__Make(bool anonymous, } auto io_context = MainRThread::GetInstance().CancellableIOContext(); - #if ARROW_VERSION_MAJOR >= 18 return ValueOrStop(fs::GcsFileSystem::Make(gcs_opts, io_context)); #else