You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/08/20 21:42:19 UTC

[GitHub] [iceberg] rdblue commented on a diff in pull request #5332: [Python] S3fsFileIO, a FileIO that wraps s3fs

rdblue commented on code in PR #5332:
URL: https://github.com/apache/iceberg/pull/5332#discussion_r950746235


##########
python/pyiceberg/io/s3fs.py:
##########
@@ -0,0 +1,235 @@
+# 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.
+"""FileIO implementation for reading and writing table files that uses s3fs"""
+
+from typing import Optional, Union
+
+from s3fs import S3FileSystem
+
+from pyiceberg.io.base import (
+    FileIO,
+    InputFile,
+    InputStream,
+    OutputFile,
+    OutputStream,
+)
+
+
+class S3fsInputStream(InputStream):
+    """A seekable wrapper for reading an S3 Object that abides by the InputStream protocol
+
+    Args:
+        s3_object(s3fs.core.S3File): An s3 object
+    """
+
+    def __init__(self, s3_object):
+        self._s3_object = s3_object
+
+    def read(self, size: int = -1) -> bytes:
+        """Read the byte content of the s3 object
+
+        Args:
+            size (int, optional): The number of bytes to read. Defaults to -1 which reads the entire file.
+
+        Returns:
+            bytes: The byte content of the file
+        """
+        return self._s3_object.read(length=size)
+
+    def seek(self, offset: int, whence: int = 0) -> int:
+        return self._s3_object.seek(loc=offset, whence=whence)
+
+    def tell(self) -> int:
+        return self._s3_object.tell()
+
+    def closed(self) -> bool:

Review Comment:
   Even if it isn't in the protocol, doesn't it make sense to have a method that exposes this since the underlying implementation does?
   
   We may want to make this a `@property`, though. That's what is normal in Python and why we couldn't include it in the Protocol.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org