Skip to content

Commit 1c480a5

Browse files
committed
create dir first
1 parent 369df6e commit 1c480a5

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pyiceberg/io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def delete(self, location: Union[str, InputFile, OutputFile]) -> None:
275275
"s3a": [ARROW_FILE_IO, FSSPEC_FILE_IO],
276276
"s3n": [ARROW_FILE_IO, FSSPEC_FILE_IO],
277277
"gs": [ARROW_FILE_IO],
278-
"file": [ARROW_FILE_IO],
278+
"file": [ARROW_FILE_IO, FSSPEC_FILE_IO],
279279
"hdfs": [ARROW_FILE_IO],
280280
"abfs": [FSSPEC_FILE_IO],
281281
"abfss": [FSSPEC_FILE_IO],

pyiceberg/io/fsspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def s3v4_rest_signer(properties: Properties, request: AWSRequest, **_: Any) -> A
9999

100100

101101
def _file(_: Properties) -> LocalFileSystem:
102-
return LocalFileSystem()
102+
return LocalFileSystem(auto_mkdir=True)
103103

104104

105105
def _s3(properties: Properties) -> AbstractFileSystem:

pyiceberg/io/pyarrow.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@
172172
T = TypeVar("T")
173173

174174

175+
class PyArrowLocalFileSystem(pyarrow.fs.LocalFileSystem):
176+
def open_output_stream(self, path, *args, **kwargs):
177+
# In LocalFileSystem, parent directories must be first created before opening an output stream
178+
self.create_dir(os.path.dirname(path), recursive=True)
179+
return super().open_output_stream(path, *args, **kwargs)
180+
181+
175182
class PyArrowFile(InputFile, OutputFile):
176183
"""A combined InputFile and OutputFile implementation that uses a pyarrow filesystem to generate pyarrow.lib.NativeFile instances.
177184
@@ -378,9 +385,7 @@ def _initialize_fs(self, scheme: str, netloc: Optional[str] = None) -> FileSyste
378385

379386
return GcsFileSystem(**gcs_kwargs)
380387
elif scheme == "file":
381-
from pyarrow.fs import LocalFileSystem
382-
383-
return LocalFileSystem()
388+
return PyArrowLocalFileSystem()
384389
else:
385390
raise ValueError(f"Unrecognized filesystem type in URI: {scheme}")
386391

0 commit comments

Comments
 (0)