Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-38703: [C++][FS][Azure] Implement DeleteFile() #39840

Merged
merged 29 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6947360
[C++][FS][Azure] Implement DeleteFile() #38703
av8or1 Jan 29, 2024
7df1f8d
GH-38703: [C++][FS][Azure] Implement DeleteFile() #39840
av8or1 Jan 29, 2024
a08d5a1
Merge branch 'delete-file-branch' of github.com:av8or1/arrow into del…
av8or1 Jan 30, 2024
79e6206
Merge branch 'apache:main' into delete-file-branch
av8or1 Jan 30, 2024
8559881
Merge branch 'delete-file-branch' of github.com:av8or1/arrow into del…
av8or1 Jan 30, 2024
6e082dd
Merge branch 'delete-file-branch' of github.com:av8or1/arrow into del…
av8or1 Jan 31, 2024
4863b20
Merge branch 'apache:main' into delete-file-branch
av8or1 Jan 31, 2024
fdde91a
Updated the RandomBlobName() function.
av8or1 Jan 31, 2024
b812aaa
Merge branch 'delete-file-branch' of github.com:av8or1/arrow into del…
av8or1 Jan 31, 2024
3330284
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 1, 2024
b89a07a
Merge branch 'apache:main' into delete-file-branch
av8or1 Feb 1, 2024
4b1c635
Update cpp/src/arrow/filesystem/azurefs_test.cc
av8or1 Feb 1, 2024
516be74
Update cpp/src/arrow/filesystem/azurefs_test.cc
av8or1 Feb 1, 2024
6c0fa18
Update cpp/src/arrow/filesystem/azurefs_test.cc
av8or1 Feb 1, 2024
110932b
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 1, 2024
953da8e
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 1, 2024
6512c12
Merge branch 'apache:main' into delete-file-branch
av8or1 Feb 1, 2024
d2e6f9b
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 1, 2024
58888b4
Merge branch 'delete-file-branch' of github.com:av8or1/arrow into del…
av8or1 Feb 1, 2024
5af7159
Merge branch 'apache:main' into delete-file-branch
av8or1 Feb 1, 2024
b96af56
Update cpp/src/arrow/filesystem/azurefs_test.cc
av8or1 Feb 2, 2024
79e80b7
Merge branch 'apache:main' into delete-file-branch
av8or1 Feb 2, 2024
022bd57
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 2, 2024
58c4ccd
Merge branch 'apache:main' into delete-file-branch
av8or1 Feb 2, 2024
3cce85c
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 2, 2024
168356e
Merge branch 'apache:main' into delete-file-branch
av8or1 Feb 7, 2024
dd60704
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 7, 2024
39eb5ae
GH-38703: [C++][FS][Azure] Implement DeleteFile()
av8or1 Feb 7, 2024
fc7ada2
Update cpp/src/arrow/filesystem/azurefs_test.cc
av8or1 Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion cpp/src/arrow/filesystem/azurefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,26 @@ class AzureFileSystem::Impl {
}
}

Status DeleteFile(const AzureLocation& location) {
RETURN_NOT_OK(ValidateFileLocation(location));
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));
Expand Down Expand Up @@ -1875,7 +1895,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) {
Expand Down
32 changes: 29 additions & 3 deletions cpp/src/arrow/filesystem/azurefs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ 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<int>(0, end - 1)(rng);
}
Expand Down Expand Up @@ -1382,6 +1386,29 @@ TEST_F(TestAzuriteFileSystem, DeleteDirContentsFailureNonexistent) {
this->TestDeleteDirContentsFailureNonexistent();
}

TEST_F(TestAzuriteFileSystem, DeleteFileSuccessHaveFile) {
av8or1 marked this conversation as resolved.
Show resolved Hide resolved
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(TestAzuriteFileSystem, DeleteFileSuccessNonexistent) {
av8or1 marked this conversation as resolved.
Show resolved Hide resolved
const auto blob_name = PreexistingData::RandomBlobName(rng_);
arrow::fs::AssertFileInfo(fs(), blob_name, FileType::NotFound);
ASSERT_RAISES(IOError, fs()->DeleteFile(blob_name));
}

TEST_F(TestAzuriteFileSystem, DeleteFileSuccessNotAFile) {
av8or1 marked this conversation as resolved.
Show resolved Hide resolved
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);
av8or1 marked this conversation as resolved.
Show resolved Hide resolved
}

av8or1 marked this conversation as resolved.
Show resolved Hide resolved
TEST_F(TestAzuriteFileSystem, CopyFileSuccessDestinationNonexistent) {
auto data = SetUpPreexistingData();
const auto destination_path = data.ContainerPath("copy-destionation");
Expand Down Expand Up @@ -1868,6 +1895,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
Loading