rdblue commented on a change in pull request #3691: URL: https://github.com/apache/iceberg/pull/3691#discussion_r765253507
########## File path: python/src/iceberg/io/file.py ########## @@ -0,0 +1,80 @@ +# 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. + +import logging +from abc import ABC, abstractmethod + +log = logging.getLogger(__name__) + + +class FileIO(ABC): + """A base class for FileIO implementations + + All of the input and output functionality of the library relies on some implementation + of this base class. Implementing this class requires overriding the `__enter__` and + `__exit__` methods. The implementation will be used as a context manager. To maintain the + convention of the path argument being named `path`, it's recommended to just use the base + class's init method. + + Example: + >>> from iceberg.io.file import FileIO + >>> class FooFileIO(FileIO): + def __init__(self, path): + super().__init__(path=path) + + def __enter__(self): + super().__enter__() + + data = bytes("bar", encoding="utf-8") + self.byte_stream = io.BytesIO(data) + + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + del self.byte_stream + super().__exit__(exc_type, exc_value, exc_traceback) + return + """ + + def __init__(self, path): + self._path = path + super().__init__() + + @property + def path(self): + return self._path + + @abstractmethod + def __enter__(self): Review comment: I think that we should pattern this class more after the FileIO in Java. `FileIO` is responsible for 3 methods: `new_input_file(str)`, `new_output_file(str)`, and `delete_file(str)`. These `__enter__` and `__exit__` methods would make sense for input and output files, but not the FileIO implementation itself, which is responsible for creating the files that you actually use to interact with S3 or another store. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
