-
Notifications
You must be signed in to change notification settings - Fork 106
feat(io): add bulk delete API to FileIO. #659
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
Changes from all commits
2b4017c
fc6fbe8
16cde97
1e963a0
70bff3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||
| /* | ||||
| * Licensed to the Apache Software Foundation (ASF) under one | ||||
| * or more contributor license agreements. See the NOTICE file | ||||
| * distributed with this work for additional information | ||||
| * regarding copyright ownership. The ASF licenses this file | ||||
| * to you under the Apache License, Version 2.0 (the | ||||
| * "License"); you may not use this file except in compliance | ||||
| * with the License. You may obtain a copy of the License at | ||||
| * | ||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | ||||
| * Unless required by applicable law or agreed to in writing, | ||||
| * software distributed under the License is distributed on an | ||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||
| * KIND, either express or implied. See the License for the | ||||
| * specific language governing permissions and limitations | ||||
| * under the License. | ||||
| */ | ||||
|
|
||||
| #include "iceberg/file_io.h" | ||||
|
|
||||
| #include <string> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
|
|
||||
| #include <gtest/gtest.h> | ||||
|
|
||||
| #include "iceberg/test/matchers.h" | ||||
|
|
||||
| namespace iceberg { | ||||
| namespace { | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this or its counterpart. If you want to wrap
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I’ll shrink the anonymous namespace scope to cover only the helper
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not putting all cases in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. I moved the test cases into the iceberg namespace and kept RecordingFileIO in an anonymous namespace, so the iceberg:: prefixes are no longer needed. |
||||
|
|
||||
| class RecordingFileIO : public FileIO { | ||||
| public: | ||||
| explicit RecordingFileIO(std::string failure_path = "") | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name |
||||
| : failure_path_(std::move(failure_path)) {} | ||||
|
|
||||
| Status DeleteFile(const std::string& file_location) override { | ||||
| deleted_paths.push_back(file_location); | ||||
| if (file_location == failure_path_) { | ||||
| return IOError("failed to delete {}", file_location); | ||||
| } | ||||
| return {}; | ||||
| } | ||||
|
|
||||
| std::vector<std::string> deleted_paths; | ||||
|
|
||||
| private: | ||||
| std::string failure_path_; | ||||
| }; | ||||
|
|
||||
| } // namespace | ||||
|
|
||||
| TEST(FileIOTest, DeleteFilesFallsBackToDeleteFileForEachPath) { | ||||
| RecordingFileIO file_io; | ||||
| std::vector<std::string> paths = {"file-a.avro", "file-b.avro"}; | ||||
|
|
||||
| EXPECT_THAT(file_io.DeleteFiles(paths), IsOk()); | ||||
| EXPECT_THAT(file_io.deleted_paths, | ||||
| ::testing::ElementsAre("file-a.avro", "file-b.avro")); | ||||
| } | ||||
|
|
||||
| TEST(FileIOTest, DeleteFilesReturnsFirstDeleteFileError) { | ||||
| RecordingFileIO file_io("file-b.avro"); | ||||
| std::vector<std::string> paths = {"file-a.avro", "file-b.avro", "file-c.avro"}; | ||||
|
|
||||
| auto status = file_io.DeleteFiles(paths); | ||||
|
|
||||
| EXPECT_THAT(status, IsError(ErrorKind::kIOError)); | ||||
| EXPECT_THAT(status, HasErrorMessage("failed to delete file-b.avro")); | ||||
| EXPECT_THAT(file_io.deleted_paths, | ||||
| ::testing::ElementsAre("file-a.avro", "file-b.avro")); | ||||
| } | ||||
|
|
||||
| } // namespace iceberg | ||||
Uh oh!
There was an error while loading. Please reload this page.