emkornfield commented on a change in pull request #3691:
URL: https://github.com/apache/iceberg/pull/3691#discussion_r791010587



##########
File path: python/src/iceberg/io/base.py
##########
@@ -0,0 +1,99 @@
+# 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.
+"""Base FileIO classes for implementing reading and writing table files
+
+The FileIO abstraction includes a subset of full filesystem implementations. 
Specifically,
+Iceberg needs to read or write a file at a given location (as a seekable 
stream), as well
+as check if a file exists. An implementation of the FileIO abstract base class 
is responsible
+for returning an InputFile instance, an OutputFile instance, and deleting a 
file given
+its location.
+"""
+
+from abc import ABC, abstractmethod
+
+
+class InputFile(ABC):
+    """A base class for InputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the input file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def open(self):

Review comment:
       This seems to require https://pypi.org/project/typing-extensions/ for 
python <= 3.7

##########
File path: python/src/iceberg/io/base.py
##########
@@ -0,0 +1,100 @@
+# 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.
+"""Base FileIO classes for implementing reading and writing table files
+
+The FileIO abstraction includes a subset of full filesystem implementations. 
Specifically,
+Iceberg needs to read or write a file at a given location (as a seekable 
stream), as well
+as check if a file exists. An implementation of the FileIO abstract base class 
is responsible
+for returning an InputFile instance, an OutputFile instance, and deleting a 
file given
+its location.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Union
+
+
+class InputFile(ABC):
+    """A base class for InputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the input file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def open(self):
+        """This method should return an instance of an seekable input 
stream."""
+
+
+class OutputFile(ABC):
+    """A base class for OutputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the output file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def to_input_file(self) -> InputFile:
+        """Returns an InputFile for the location of this output file"""
+
+    @abstractmethod
+    def create(self, overwrite: bool = False):
+        """This method should return a file-like object.
+
+        Args:
+            overwrite(bool): If the file already exists at `self.location`
+            and `overwrite` is False a FileExistsError should be raised.
+        """
+
+
+class FileIO(ABC):
+    @abstractmethod
+    def new_input(self, location: str) -> InputFile:
+        """Get an InputFile instance to read bytes from the file at the given 
location"""
+
+    @abstractmethod
+    def new_output(self, location: str) -> OutputFile:

Review comment:
       I guess this might be more a philosophical question.   There are two 
ways to achieve the flexibility:
   1.  Provide a single class and have users only implement the methods they 
want (you can document a set of methods that should always be implemented 
together).  Giving users run-time errors when not implemented.
   2. Separate the functionality into two different interfaces and require all 
methods be implemented.
   
   My sense is that #2 is more of a java design pattern.  I think (but I'm no 
expert) option #1 is more pythonic/dynamically typed language pattern.
   

##########
File path: python/src/iceberg/io/base.py
##########
@@ -0,0 +1,100 @@
+# 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.
+"""Base FileIO classes for implementing reading and writing table files
+
+The FileIO abstraction includes a subset of full filesystem implementations. 
Specifically,
+Iceberg needs to read or write a file at a given location (as a seekable 
stream), as well
+as check if a file exists. An implementation of the FileIO abstract base class 
is responsible
+for returning an InputFile instance, an OutputFile instance, and deleting a 
file given
+its location.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Union
+
+
+class InputFile(ABC):
+    """A base class for InputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the input file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def open(self):
+        """This method should return an instance of an seekable input 
stream."""

Review comment:
       Also specify what should happen if the file doesn't exist.

##########
File path: python/src/iceberg/io/base.py
##########
@@ -0,0 +1,100 @@
+# 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.
+"""Base FileIO classes for implementing reading and writing table files
+
+The FileIO abstraction includes a subset of full filesystem implementations. 
Specifically,
+Iceberg needs to read or write a file at a given location (as a seekable 
stream), as well
+as check if a file exists. An implementation of the FileIO abstract base class 
is responsible
+for returning an InputFile instance, an OutputFile instance, and deleting a 
file given
+its location.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Union
+
+
+class InputFile(ABC):
+    """A base class for InputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the input file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def open(self):
+        """This method should return an instance of an seekable input 
stream."""

Review comment:
       nit, be consistent ending doc-strings with periods or not.

##########
File path: python/src/iceberg/io/base.py
##########
@@ -0,0 +1,100 @@
+# 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.
+"""Base FileIO classes for implementing reading and writing table files
+
+The FileIO abstraction includes a subset of full filesystem implementations. 
Specifically,
+Iceberg needs to read or write a file at a given location (as a seekable 
stream), as well
+as check if a file exists. An implementation of the FileIO abstract base class 
is responsible
+for returning an InputFile instance, an OutputFile instance, and deleting a 
file given
+its location.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Union
+
+
+class InputFile(ABC):
+    """A base class for InputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the input file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def open(self):
+        """This method should return an instance of an seekable input 
stream."""
+
+
+class OutputFile(ABC):
+    """A base class for OutputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the output file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def to_input_file(self) -> InputFile:
+        """Returns an InputFile for the location of this output file"""
+
+    @abstractmethod
+    def create(self, overwrite: bool = False):
+        """This method should return a file-like object.
+
+        Args:
+            overwrite(bool): If the file already exists at `self.location`
+            and `overwrite` is False a FileExistsError should be raised.
+        """
+
+
+class FileIO(ABC):

Review comment:
       doc string

##########
File path: python/src/iceberg/io/base.py
##########
@@ -0,0 +1,100 @@
+# 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.
+"""Base FileIO classes for implementing reading and writing table files
+
+The FileIO abstraction includes a subset of full filesystem implementations. 
Specifically,
+Iceberg needs to read or write a file at a given location (as a seekable 
stream), as well
+as check if a file exists. An implementation of the FileIO abstract base class 
is responsible
+for returning an InputFile instance, an OutputFile instance, and deleting a 
file given
+its location.
+"""
+
+from abc import ABC, abstractmethod
+from typing import Union
+
+
+class InputFile(ABC):
+    """A base class for InputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the input file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def open(self):
+        """This method should return an instance of an seekable input 
stream."""
+
+
+class OutputFile(ABC):
+    """A base class for OutputFile implementations"""
+
+    def __init__(self, location: str):
+        self._location = location
+
+    @abstractmethod
+    def __len__(self) -> int:
+        """Returns the total length of the file, in bytes"""
+
+    @property
+    def location(self) -> str:
+        """The fully-qualified location of the output file"""
+        return self._location
+
+    @property
+    @abstractmethod
+    def exists(self) -> bool:
+        """Checks whether the file exists"""
+
+    @abstractmethod
+    def to_input_file(self) -> InputFile:
+        """Returns an InputFile for the location of this output file"""
+
+    @abstractmethod
+    def create(self, overwrite: bool = False):
+        """This method should return a file-like object.

Review comment:
       I should add that I understand it because I am familiar with the python 
idiom of "file-like" and maybe most users of these class will be since, because 
after all this is python.




-- 
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]

Reply via email to