1717 * under the License.
1818 */
1919
20- #include " iceberg/arrow/io/local_file_io .h"
20+ #include " iceberg/arrow/io/arrow_fs_file_io .h"
2121
2222#include < filesystem>
2323
2828namespace iceberg ::arrow::io {
2929
3030// / \brief Read the content of the file at the given location.
31- expected<std::string, Error> LocalFileIO ::ReadFile (const std::string& file_location,
32- std::optional<size_t > length) {
31+ expected<std::string, Error> ArrowFileSystemFileIO ::ReadFile (
32+ const std::string& file_location, std::optional<size_t > length) {
3333 // We don't support reading a file with a specific length.
3434 if (length.has_value ()) {
3535 return unexpected (Error (ErrorKind::kInvalidArgument , " Length is not supported" ));
3636 }
3737 std::string content;
38- ICEBERG_INTERNAL_ASSIGN_OR_RETURN (auto file, local_fs_ ->OpenInputFile (file_location));
38+ ICEBERG_INTERNAL_ASSIGN_OR_RETURN (auto file, arrow_fs_ ->OpenInputFile (file_location));
3939 ICEBERG_INTERNAL_ASSIGN_OR_RETURN (auto file_size, file->GetSize ());
4040
4141 content.resize (file_size);
@@ -47,31 +47,28 @@ expected<std::string, Error> LocalFileIO::ReadFile(const std::string& file_locat
4747}
4848
4949// / \brief Write the given content to the file at the given location.
50- expected<void , Error> LocalFileIO::WriteFile (const std::string& file_location,
51- std::string_view content, bool overwrite) {
52- if (!overwrite && FileExists (file_location)) {
53- return unexpected (
54- Error (ErrorKind::kAlreadyExists , std::format (" File {} exists" , file_location)));
55- }
50+ expected<void , Error> ArrowFileSystemFileIO::WriteFile (const std::string& file_location,
51+ std::string_view content,
52+ bool overwrite) {
53+ // auto file_info = arrow_fs_->GetFileInfo(file_location);
54+ // if (file_info.status().ok() && !overwrite) {
55+ // return unexpected(
56+ // Error(ErrorKind::kAlreadyExists, std::format("File {} exists",
57+ // file_location)));
58+ // }
5659 ICEBERG_INTERNAL_ASSIGN_OR_RETURN (auto file,
57- local_fs_ ->OpenOutputStream (file_location));
60+ arrow_fs_ ->OpenOutputStream (file_location));
5861 ICEBERG_INTERNAL_RETURN_NOT_OK (file->Write (content.data (), content.size ()));
62+ ICEBERG_INTERNAL_RETURN_NOT_OK (file->Flush ());
63+ ICEBERG_INTERNAL_RETURN_NOT_OK (file->Close ());
5964 return {};
6065}
6166
6267// / \brief Delete a file at the given location.
63- expected<void , Error> LocalFileIO::DeleteFile (const std::string& file_location) {
64- if (!FileExists (file_location)) {
65- return unexpected (Error (ErrorKind::kNoSuchFile ,
66- std::format (" File {} does not exist" , file_location)));
67- }
68- ICEBERG_INTERNAL_RETURN_NOT_OK (local_fs_->DeleteFile (file_location));
68+ expected<void , Error> ArrowFileSystemFileIO::DeleteFile (
69+ const std::string& file_location) {
70+ ICEBERG_INTERNAL_RETURN_NOT_OK (arrow_fs_->DeleteFile (file_location));
6971 return {};
7072}
7173
72- bool LocalFileIO::FileExists (const std::string& location) {
73- // ::arrow::fs::LocalFileSystem does not have a exists method.
74- return std::filesystem::exists (location);
75- }
76-
7774} // namespace iceberg::arrow::io
0 commit comments