felipecrv commented on code in PR #39692:
URL: https://github.com/apache/arrow/pull/39692#discussion_r1458165956
##########
cpp/src/arrow/filesystem/azurefs.cc:
##########
@@ -1728,6 +1728,37 @@ class AzureFileSystem::Impl {
}
return Status::OK();
}
+
+ Status DeleteFile(const AzureLocation& location) {
+ if (location.path.empty()) {
+ return Status::Invalid("Cannot delete an empty path");
+ }
+
+ auto last_sep = location.path.find_last_of(internal::kSep);
+ auto directory = location.path.substr(0, last_sep);
+ auto file = location.path.substr(last_sep + 1);
+
+ auto file_client =
+ datalake_service_client_->GetFileSystemClient(location.container)
+ .GetDirectoryClient(directory).GetFileClient(file);
+
+ try {
+ auto response = file_client.DeleteIfExists();
+ if (response.Value.Deleted) {
+ return Status::OK();
+ } else {
+ return StatusFromErrorResponse(
+ container_client.GetUrl(), response.RawResponse.get(),
+ "Failed to delete a container: " + location.container);
+ }
+ } catch (const Azure::Storage::StorageException& exception) {
+ return internal::ExceptionToStatus(
+ "Failed to delete a file: " + location.all + ": " +
+ file_client.GetUrl(),
+ exception);
Review Comment:
It's been a while since you rebased. This function expects exception to be
the first parameter now and all the other components can be passed as separate
arguments, so you don't have to `+` the strings yourself.
##########
cpp/src/arrow/filesystem/azurefs.cc:
##########
@@ -1728,6 +1728,37 @@ class AzureFileSystem::Impl {
}
return Status::OK();
}
+
+ Status DeleteFile(const AzureLocation& location) {
+ if (location.path.empty()) {
+ return Status::Invalid("Cannot delete an empty path");
+ }
+
+ auto last_sep = location.path.find_last_of(internal::kSep);
+ auto directory = location.path.substr(0, last_sep);
+ auto file = location.path.substr(last_sep + 1);
+
+ auto file_client =
+ datalake_service_client_->GetFileSystemClient(location.container)
+ .GetDirectoryClient(directory).GetFileClient(file);
+
+ try {
+ auto response = file_client.DeleteIfExists();
Review Comment:
If you use `Delete()` you get an exception when the file doesn't exist and
then you can return `PathNotFound(location)`.
##########
cpp/src/arrow/filesystem/azurefs.cc:
##########
@@ -1728,6 +1728,37 @@ class AzureFileSystem::Impl {
}
return Status::OK();
}
+
+ Status DeleteFile(const AzureLocation& location) {
+ if (location.path.empty()) {
+ return Status::Invalid("Cannot delete an empty path");
+ }
+
+ auto last_sep = location.path.find_last_of(internal::kSep);
+ auto directory = location.path.substr(0, last_sep);
+ auto file = location.path.substr(last_sep + 1);
+
+ auto file_client =
+ datalake_service_client_->GetFileSystemClient(location.container)
+ .GetDirectoryClient(directory).GetFileClient(file);
Review Comment:
You can `GetFileClient(location.path)` from filesystem client -- you don't
have to create a directory client.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]