From 69473603a98bcc34d074b968061cc19544c88c8a Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Mon, 29 Jan 2024 16:34:40 -0500 Subject: [PATCH 01/16] [C++][FS][Azure] Implement DeleteFile() #38703 Modifications to support the deletion of a file. --- cpp/src/arrow/filesystem/azurefs.cc | 29 +++++++++++++++++++++++- cpp/src/arrow/filesystem/azurefs_test.cc | 28 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index a5179c22190e1..163a41d7ace92 100644 --- a/cpp/src/arrow/filesystem/azurefs.cc +++ b/cpp/src/arrow/filesystem/azurefs.cc @@ -1690,6 +1690,32 @@ class AzureFileSystem::Impl { } } + Status DeleteFile(const AzureLocation& location) { + if (location.path.empty()) { + return Status::Invalid("Cannot delete an empty path"); + } + + auto file_client = + datalake_service_client_->GetFileSystemClient(location.container) + .GetFileClient(location.path); + + try { + auto response = file_client.Delete(); + // Only the "*IfExists" functions ever set Deleted to false. + // All the others either succeed or throw an exception. + DCHECK(response.Value.Deleted); + } catch (const Storage::StorageException& exception) { + if (exception.ErrorCode == "FilesystemNotFound" || + exception.ErrorCode == "PathNotFound") { + return PathNotFound(location); + } + return ExceptionToStatus(exception, + "Failed to delete a file: ", location.path, ": ", + file_client.GetUrl()); + } + return Status::OK(); + } + Status CopyFile(const AzureLocation& src, const AzureLocation& dest) { RETURN_NOT_OK(ValidateFileLocation(src)); RETURN_NOT_OK(ValidateFileLocation(dest)); @@ -1875,7 +1901,8 @@ Status AzureFileSystem::DeleteRootDirContents() { } Status AzureFileSystem::DeleteFile(const std::string& path) { - return Status::NotImplemented("The Azure FileSystem is not fully implemented"); + ARROW_ASSIGN_OR_RAISE(auto location, AzureLocation::FromString(path)); + return impl_->DeleteFile(location); } Status AzureFileSystem::Move(const std::string& src, const std::string& dest) { diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 6104b04411b32..e51077600434e 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -376,6 +376,10 @@ culpa qui officia deserunt mollit anim id est laborum. return s; } + std::string RandomFileName(RNG &rng) { return RandomChars(10, rng); } + + std::string RandomFileNameExtension(RNG &rng) { return RandomChars(3, rng); } + static int RandomIndex(int end, RNG& rng) { return std::uniform_int_distribution(0, end - 1)(rng); } @@ -1382,6 +1386,30 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) { this->TestDeleteDirContentsFailureNonexistent(); } +TEST_F(AzuriteFileSystemTest, DeleteFileSuccessHaveFile) { +void CreateFile(FileSystem* fs, const std::string& path, const std::string& data) { + const auto file_name = PreexistingData::RandomFileName() + PreexistingData::RandomFileNameExtension(); + ASSERT_OK(CreateFile(fs_.get(), file_name, "abc")); + arrow::fs::AssertFileInfo(fs_.get(), file_name, FileType::File); + ASSERT_OK(fs_->DeleteFile(file_name)); + arrow::fs::AssertFileInfo(fs_.get(), file_name, FileType::NotFound); +} + +TEST_F(AzuriteFileSystemTest, DeleteFileSuccessNonexistent) { + const auto file_name = PreexistingData::RandomFileName() + PreexistingData::RandomFileNameExtension(); + ASSERT_OK(fs_->DeleteFile(file_name)); + arrow::fs::AssertFileInfo(fs_.get(), file_name, FileType::NotFound); +} + +TEST_F(AzuriteFileSystemTest, DeleteFileSuccessNotAFile) { + const auto container_name = RandomContainerName(); + ASSERT_OK(fs_->CreateDir(container_name)); + arrow::fs::AssertFileInfo(fs_.get(), container_name, FileType::Directory); + ASSERT_RAISES(IOError, fs_->DeleteFile(container_name)); + ASSERT_OK(fs_->DeleteDir(container_name)); + arrow::fs::AssertFileInfo(fs_.get(), container_name, FileType::NotFound); +} + TEST_F(TestAzuriteFileSystem, CopyFileSuccessDestinationNonexistent) { auto data = SetUpPreexistingData(); const auto destination_path = data.ContainerPath("copy-destionation"); From 7df1f8db1d8c994c14b2e245e05d927f999aed3f Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Mon, 29 Jan 2024 16:34:40 -0500 Subject: [PATCH 02/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() #39840 Modifications to support the deletion of a file. Updated azurefs.cc and azurefs_test.cc to address Lint issues. --- cpp/src/arrow/filesystem/azurefs.cc | 29 +++++++++++++++++++- cpp/src/arrow/filesystem/azurefs_test.cc | 35 ++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index a5179c22190e1..c187ce63e780f 100644 --- a/cpp/src/arrow/filesystem/azurefs.cc +++ b/cpp/src/arrow/filesystem/azurefs.cc @@ -1690,6 +1690,32 @@ class AzureFileSystem::Impl { } } + Status DeleteFile(const AzureLocation& location) { + if (location.path.empty()) { + return Status::Invalid("Cannot delete an empty path"); + } + + auto file_client = + datalake_service_client_->GetFileSystemClient(location.container) + .GetFileClient(location.path); + + try { + auto response = file_client.Delete(); + // Only the "*IfExists" functions ever set Deleted to false. + // All the others either succeed or throw an exception. + DCHECK(response.Value.Deleted); + } catch (const Storage::StorageException& exception) { + if (exception.ErrorCode == "FilesystemNotFound" || + exception.ErrorCode == "PathNotFound") { + return PathNotFound(location); + } + return ExceptionToStatus(exception, + "Failed to delete a file: ", location.path, ": ", + file_client.GetUrl()); + } + return Status::OK(); + } + Status CopyFile(const AzureLocation& src, const AzureLocation& dest) { RETURN_NOT_OK(ValidateFileLocation(src)); RETURN_NOT_OK(ValidateFileLocation(dest)); @@ -1875,7 +1901,8 @@ Status AzureFileSystem::DeleteRootDirContents() { } Status AzureFileSystem::DeleteFile(const std::string& path) { - return Status::NotImplemented("The Azure FileSystem is not fully implemented"); + ARROW_ASSIGN_OR_RAISE(auto location, AzureLocation::FromString(path)); + return impl_->DeleteFile(location); } Status AzureFileSystem::Move(const std::string& src, const std::string& dest) { diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 6104b04411b32..53e7cd09b3b95 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -376,6 +376,10 @@ culpa qui officia deserunt mollit anim id est laborum. return s; } + std::string RandomFileName(RNG &rng) { return RandomChars(10, rng); } + + std::string RandomFileNameExtension(RNG &rng) { return RandomChars(3, rng); } + static int RandomIndex(int end, RNG& rng) { return std::uniform_int_distribution(0, end - 1)(rng); } @@ -1382,6 +1386,32 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) { this->TestDeleteDirContentsFailureNonexistent(); } +TEST_F(AzuriteFileSystemTest, DeleteFileSuccessHaveFile) { +void CreateFile(FileSystem* fs, const std::string& path, const std::string& data) { + const auto file_name = PreexistingData::RandomFileName() + + PreexistingData::RandomFileNameExtension(); + ASSERT_OK(CreateFile(fs_.get(), file_name, "abc")); + arrow::fs::AssertFileInfo(fs_.get(), file_name, FileType::File); + ASSERT_OK(fs_->DeleteFile(file_name)); + arrow::fs::AssertFileInfo(fs_.get(), file_name, FileType::NotFound); +} + +TEST_F(AzuriteFileSystemTest, DeleteFileSuccessNonexistent) { + const auto file_name = PreexistingData::RandomFileName() + + PreexistingData::RandomFileNameExtension(); + ASSERT_OK(fs_->DeleteFile(file_name)); + arrow::fs::AssertFileInfo(fs_.get(), file_name, FileType::NotFound); +} + +TEST_F(AzuriteFileSystemTest, DeleteFileSuccessNotAFile) { + const auto container_name = RandomContainerName(); + ASSERT_OK(fs_->CreateDir(container_name)); + arrow::fs::AssertFileInfo(fs_.get(), container_name, FileType::Directory); + ASSERT_RAISES(IOError, fs_->DeleteFile(container_name)); + ASSERT_OK(fs_->DeleteDir(container_name)); + arrow::fs::AssertFileInfo(fs_.get(), container_name, FileType::NotFound); +} + TEST_F(TestAzuriteFileSystem, CopyFileSuccessDestinationNonexistent) { auto data = SetUpPreexistingData(); const auto destination_path = data.ContainerPath("copy-destionation"); @@ -1868,6 +1898,5 @@ TEST_F(TestAzuriteFileSystem, OpenInputFileClosed) { ASSERT_RAISES(Invalid, stream->ReadAt(1, 1)); ASSERT_RAISES(Invalid, stream->Seek(2)); } - -} // namespace fs -} // namespace arrow +} // namespace fs +} // namespace arrow From fdde91a1210a04606290782408a556747d4f61e1 Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Wed, 31 Jan 2024 12:54:32 -0500 Subject: [PATCH 03/16] Updated the RandomBlobName() function. --- cpp/src/arrow/filesystem/azurefs_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index ab49b55b0b254..e7aeebfcfcd5d 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -377,7 +377,7 @@ culpa qui officia deserunt mollit anim id est laborum. } static std::string RandomBlobName(RNG &rng) { - return RandomChars(10, rng) + RandomChars(3, rng); + return RandomChars(10, rng) + "." + RandomChars(3, rng); } static int RandomIndex(int end, RNG& rng) { From 333028403e2f350554941287f2d7a2e80e34ddfe Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Thu, 1 Feb 2024 03:19:42 -0500 Subject: [PATCH 04/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Cleaned issues with azurefs_test.cc that were found in the logs. --- cpp/src/arrow/filesystem/azurefs_test.cc | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index e7aeebfcfcd5d..fbf0a4ede23e4 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -376,7 +376,7 @@ culpa qui officia deserunt mollit anim id est laborum. return s; } - static std::string RandomBlobName(RNG &rng) { + static std::string RandomBlobName(RNG& rng) { return RandomChars(10, rng) + "." + RandomChars(3, rng); } @@ -1386,27 +1386,27 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) { this->TestDeleteDirContentsFailureNonexistent(); } -TEST_F(AzuriteFileSystemTest, DeleteFileSuccessHaveFile) { - const auto blob_name = PreexistingData::RandomBlobName(); - ASSERT_OK(CreateFile(fs_.get(), blob_name, "abc")); - arrow::fs::AssertFileInfo(fs_.get(), blob_name, FileType::File); - ASSERT_OK(fs_->DeleteFile(blob_name)); - arrow::fs::AssertFileInfo(fs_.get(), blob_name, FileType::NotFound); +TEST_F(TestAzuriteFileSystem, DeleteFileSuccessHaveFile) { + const auto blob_name = PreexistingData::RandomBlobName(rng_); + ASSERT_OK(CreateFile(fs(), blob_name, "abc")); + arrow::fs::AssertFileInfo(fs(), blob_name, FileType::File); + ASSERT_OK(fs()->DeleteFile(blob_name)); + arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound); } -TEST_F(AzuriteFileSystemTest, DeleteFileSuccessNonexistent) { - const auto blob_name = PreexistingData::RandomBlobName(); - arrow::fs::AssertFileInfo(fs_.get(), blob_name, FileType::NotFound); - ASSERT_RAISES(IOError, fs_->DeleteFile(blob_name)); +TEST_F(TestAzuriteFileSystem, DeleteFileSuccessNonexistent) { + const auto blob_name = PreexistingData::RandomBlobName(rng_); + arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound); + ASSERT_RAISES(IOError, fs()->DeleteFile(blob_name)); } -TEST_F(AzuriteFileSystemTest, DeleteFileSuccessNotAFile) { - const auto container_name = RandomContainerName(); - ASSERT_OK(fs_->CreateDir(container_name)); - arrow::fs::AssertFileInfo(fs_.get(), container_name, FileType::Directory); - ASSERT_RAISES(IOError, fs_->DeleteFile(container_name)); - ASSERT_OK(fs_->DeleteDir(container_name)); - arrow::fs::AssertFileInfo(fs_.get(), container_name, FileType::NotFound); +TEST_F(TestAzuriteFileSystem, DeleteFileSuccessNotAFile) { + const auto container_name = PreexistingData::RandomContainerName(rng_); + ASSERT_OK(fs()->CreateDir(container_name)); + arrow::fs::AssertFileInfo(fs(), container_name, FileType::Directory); + ASSERT_RAISES(IOError, fs()->DeleteFile(container_name)); + ASSERT_OK(fs()->DeleteDir(container_name)); + arrow::fs::AssertFileInfo(fs(), container_name, FileType::NotFound); } TEST_F(TestAzuriteFileSystem, CopyFileSuccessDestinationNonexistent) { From 4b1c63511af44684273b9a4f310c9567be132b8d Mon Sep 17 00:00:00 2001 From: av8or1 Date: Thu, 1 Feb 2024 02:52:11 -0600 Subject: [PATCH 05/16] Update cpp/src/arrow/filesystem/azurefs_test.cc Co-authored-by: Sutou Kouhei --- cpp/src/arrow/filesystem/azurefs_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index fbf0a4ede23e4..103a91eaa9da0 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1386,7 +1386,7 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) { this->TestDeleteDirContentsFailureNonexistent(); } -TEST_F(TestAzuriteFileSystem, DeleteFileSuccessHaveFile) { +TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { const auto blob_name = PreexistingData::RandomBlobName(rng_); ASSERT_OK(CreateFile(fs(), blob_name, "abc")); arrow::fs::AssertFileInfo(fs(), blob_name, FileType::File); From 516be740f8f56d95bec9cf3216d5080fb1fe106d Mon Sep 17 00:00:00 2001 From: av8or1 Date: Thu, 1 Feb 2024 02:53:04 -0600 Subject: [PATCH 06/16] Update cpp/src/arrow/filesystem/azurefs_test.cc Co-authored-by: Sutou Kouhei --- cpp/src/arrow/filesystem/azurefs_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 103a91eaa9da0..752336776a658 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1394,7 +1394,7 @@ TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound); } -TEST_F(TestAzuriteFileSystem, DeleteFileSuccessNonexistent) { +TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { const auto blob_name = PreexistingData::RandomBlobName(rng_); arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound); ASSERT_RAISES(IOError, fs()->DeleteFile(blob_name)); From 6c0fa18d71c481a7858e0851a0eb654136909fb0 Mon Sep 17 00:00:00 2001 From: av8or1 Date: Thu, 1 Feb 2024 02:53:24 -0600 Subject: [PATCH 07/16] Update cpp/src/arrow/filesystem/azurefs_test.cc Co-authored-by: Sutou Kouhei --- cpp/src/arrow/filesystem/azurefs_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 752336776a658..f59c21a984d2f 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1400,7 +1400,7 @@ TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { ASSERT_RAISES(IOError, fs()->DeleteFile(blob_name)); } -TEST_F(TestAzuriteFileSystem, DeleteFileSuccessNotAFile) { +TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { const auto container_name = PreexistingData::RandomContainerName(rng_); ASSERT_OK(fs()->CreateDir(container_name)); arrow::fs::AssertFileInfo(fs(), container_name, FileType::Directory); From 110932b132e0a235d1b4b22c96a9313a49b4c57f Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Thu, 1 Feb 2024 04:11:13 -0500 Subject: [PATCH 08/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Updated cpp/src/arrow/filesystem/azurefs_test.cc to remove two lines that are conducted during TearDown(). --- cpp/src/arrow/filesystem/azurefs_test.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index f59c21a984d2f..9fd943bb8dd7d 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1405,8 +1405,6 @@ TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { ASSERT_OK(fs()->CreateDir(container_name)); arrow::fs::AssertFileInfo(fs(), container_name, FileType::Directory); ASSERT_RAISES(IOError, fs()->DeleteFile(container_name)); - ASSERT_OK(fs()->DeleteDir(container_name)); - arrow::fs::AssertFileInfo(fs(), container_name, FileType::NotFound); } TEST_F(TestAzuriteFileSystem, CopyFileSuccessDestinationNonexistent) { From 953da8e8032bc1cd3c1e6546a26bb41b9646bc40 Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Thu, 1 Feb 2024 11:43:23 -0500 Subject: [PATCH 09/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Modified DeleteFile() regression tests based on Felipe's feedback. --- cpp/src/arrow/filesystem/azurefs_test.cc | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 9fd943bb8dd7d..a18546f0bc910 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -376,10 +376,6 @@ culpa qui officia deserunt mollit anim id est laborum. return s; } - static std::string RandomBlobName(RNG& rng) { - return RandomChars(10, rng) + "." + RandomChars(3, rng); - } - static int RandomIndex(int end, RNG& rng) { return std::uniform_int_distribution(0, end - 1)(rng); } @@ -1387,17 +1383,15 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) { } TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { - const auto blob_name = PreexistingData::RandomBlobName(rng_); - ASSERT_OK(CreateFile(fs(), blob_name, "abc")); - arrow::fs::AssertFileInfo(fs(), blob_name, FileType::File); - ASSERT_OK(fs()->DeleteFile(blob_name)); - arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound); + CreateFile(fs(), "abc", "data"); + arrow::fs::AssertFileInfo(fs(), "abc", FileType::File); + ASSERT_OK(fs()->DeleteFile("abc")); + arrow::fs::AssertFileInfo(fs(), "abc, FileType::NotFound); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { - const auto blob_name = PreexistingData::RandomBlobName(rng_); - arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound); - ASSERT_RAISES(IOError, fs()->DeleteFile(blob_name)); + arrow::fs::AssertFileInfo(fs(), "abc", FileType::NotFound); + ASSERT_RAISES(IOError, fs()->DeleteFile("abc")); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { From d2e6f9b2b6d187340075cd0f40bec64d577c704c Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Thu, 1 Feb 2024 11:46:32 -0500 Subject: [PATCH 10/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Corrected typo. --- cpp/src/arrow/filesystem/azurefs_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index a18546f0bc910..b1ef8370e8531 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1386,7 +1386,7 @@ TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { CreateFile(fs(), "abc", "data"); arrow::fs::AssertFileInfo(fs(), "abc", FileType::File); ASSERT_OK(fs()->DeleteFile("abc")); - arrow::fs::AssertFileInfo(fs(), "abc, FileType::NotFound); + arrow::fs::AssertFileInfo(fs(), "abc", FileType::NotFound); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { From b96af56cd5667385e523984b5d781e428af80f6c Mon Sep 17 00:00:00 2001 From: av8or1 Date: Fri, 2 Feb 2024 08:05:22 -0600 Subject: [PATCH 11/16] Update cpp/src/arrow/filesystem/azurefs_test.cc Co-authored-by: Sutou Kouhei --- cpp/src/arrow/filesystem/azurefs_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index b1ef8370e8531..e1b34a3d0f29f 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1390,8 +1390,7 @@ TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { } TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { - arrow::fs::AssertFileInfo(fs(), "abc", FileType::NotFound); - ASSERT_RAISES(IOError, fs()->DeleteFile("abc")); + ASSERT_RAISES(IOError, fs()->DeleteFile("nonexistent")); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { From 022bd5733eb45799d79f9d07175deaea173bb00c Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Fri, 2 Feb 2024 09:25:19 -0500 Subject: [PATCH 12/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Updated ~cpp/src/arrow/filesystem/azurefs_test.cc to include an additional test for deleting files and cleaned the spacing on the last two lines in the file. --- cpp/src/arrow/filesystem/azurefs_test.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index e1b34a3d0f29f..47b08031e5d4c 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1400,6 +1400,14 @@ TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { ASSERT_RAISES(IOError, fs()->DeleteFile(container_name)); } +TEST_F(TestAzuriteFileSystem, DeleteFileFailureDirectory) { + const auto directory_name = ConcatAbstractPath( + PreexistingData::RandomContainerName(rng_), "directory"); + ASSERT_OK(fs()->CreateDir(directory_name)); + arrow::fs::AssertFileInfo(fs(), directory_name, FileType::Directory); + ASSERT_RAISES(IOError, fs()->DeleteFile(directory_name)); +} + TEST_F(TestAzuriteFileSystem, CopyFileSuccessDestinationNonexistent) { auto data = SetUpPreexistingData(); const auto destination_path = data.ContainerPath("copy-destionation"); @@ -1886,5 +1894,5 @@ TEST_F(TestAzuriteFileSystem, OpenInputFileClosed) { ASSERT_RAISES(Invalid, stream->ReadAt(1, 1)); ASSERT_RAISES(Invalid, stream->Seek(2)); } -} // namespace fs -} // namespace arrow +} // namespace fs +} // namespace arrow From 3cce85c62e7d6c987e73fb6fa6b2480ba1a76656 Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Fri, 2 Feb 2024 15:51:58 -0500 Subject: [PATCH 13/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Updated the new regression test. --- cpp/src/arrow/filesystem/azurefs_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 47b08031e5d4c..5fe696a73eedf 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1401,8 +1401,8 @@ TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { } TEST_F(TestAzuriteFileSystem, DeleteFileFailureDirectory) { - const auto directory_name = ConcatAbstractPath( - PreexistingData::RandomContainerName(rng_), "directory"); + const auto directory_name = + ConcatAbstractPath(PreexistingData::RandomContainerName(rng_), "directory"); ASSERT_OK(fs()->CreateDir(directory_name)); arrow::fs::AssertFileInfo(fs(), directory_name, FileType::Directory); ASSERT_RAISES(IOError, fs()->DeleteFile(directory_name)); From dd6070431554de0e31822d1ddb1017dd6bde0e8a Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Wed, 7 Feb 2024 01:19:32 -0500 Subject: [PATCH 14/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Modified regression test per suggestion --- cpp/src/arrow/filesystem/azurefs_test.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 5fe696a73eedf..305699370370d 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1383,10 +1383,13 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) { } TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { - CreateFile(fs(), "abc", "data"); - arrow::fs::AssertFileInfo(fs(), "abc", FileType::File); - ASSERT_OK(fs()->DeleteFile("abc")); - arrow::fs::AssertFileInfo(fs(), "abc", FileType::NotFound); + const auto container_name = PreexistingData::RandomContainerName(rng_); + ASSERT_OK(fs()->CreateDir(container_name)); + const auto file_name = ConcatAbstractPath(container_name, "abc"); + CreateFile(fs(), file_name, "data"); + arrow::fs::AssertFileInfo(fs(), file_name, FileType::File); + ASSERT_OK(fs()->DeleteFile(file_name)); + arrow::fs::AssertFileInfo(fs(), file_name, FileType::NotFound); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { From 39eb5ae393859ed10cb775a0bc4f6f91d5b1aec8 Mon Sep 17 00:00:00 2001 From: "jerry.adair" Date: Wed, 7 Feb 2024 01:48:49 -0500 Subject: [PATCH 15/16] GH-38703: [C++][FS][Azure] Implement DeleteFile() Modified the deletion of a non-existent file regression test. --- cpp/src/arrow/filesystem/azurefs_test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 305699370370d..b133762463fea 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1393,7 +1393,10 @@ TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { } TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { - ASSERT_RAISES(IOError, fs()->DeleteFile("nonexistent")); + const auto container_name = PreexistingData::RandomContainerName(rng_); + auto container_client = CreateContainer(container_name); + const auto blob_path = ConcatAbstractPath(container_name, "someblob"); + ASSERT_RAISES(IOError, fs()->DeleteFile(blob_path)); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) { From fc7ada2db593e9dbb5e773837e931bea799ca85d Mon Sep 17 00:00:00 2001 From: av8or1 Date: Wed, 7 Feb 2024 23:11:37 -0600 Subject: [PATCH 16/16] Update cpp/src/arrow/filesystem/azurefs_test.cc Co-authored-by: Sutou Kouhei --- cpp/src/arrow/filesystem/azurefs_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index b133762463fea..4d123028ea86e 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -1394,9 +1394,9 @@ TEST_F(TestAzuriteFileSystem, DeleteFileSuccess) { TEST_F(TestAzuriteFileSystem, DeleteFileFailureNonexistent) { const auto container_name = PreexistingData::RandomContainerName(rng_); - auto container_client = CreateContainer(container_name); - const auto blob_path = ConcatAbstractPath(container_name, "someblob"); - ASSERT_RAISES(IOError, fs()->DeleteFile(blob_path)); + ASSERT_OK(fs()->CreateDir(container_name)); + const auto nonexistent_file_name = ConcatAbstractPath(container_name, "nonexistent"); + ASSERT_RAISES(IOError, fs()->DeleteFile(nonexistent_file_name)); } TEST_F(TestAzuriteFileSystem, DeleteFileFailureContainer) {