kbendick commented on code in PR #5332:
URL: https://github.com/apache/iceberg/pull/5332#discussion_r929594025
##########
python/Makefile:
##########
@@ -17,13 +17,22 @@
install:
pip install poetry
- poetry install -E pyarrow
+ poetry install -E pyarrow -E s3fs
lint:
poetry run pre-commit run --all-files
-
test:
+ poetry run coverage run --source=pyiceberg/ -m pytest tests/ -m "not
s3" ${PYTEST_ARGS}
+ poetry run coverage report -m --fail-under=90
+ poetry run coverage html
+ poetry run coverage xml
+test-all:
Review Comment:
Nit: empty lies between cases have been removed. is that necessary?
##########
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:
+ return self._s3_object.closed
+
+ def close(self) -> None:
+ self._s3_object.close()
+
+
+class S3fsOutputStream(OutputStream):
+ """A wrapper for writing an S3 Object that abides by the OutputStream
protocol
+
+ Args:
+ s3_object(s3fs.core.S3FileSystem): An s3 object
+ """
+
+ def __init__(self, s3_object):
+ self._s3_object = s3_object
+
+ def write(self, b: bytes) -> int:
+ """Write to the S3 Object
+
+ Args:
+ b(bytes): The bytes to write to the S3 Object
+
+ Returns:
+ int: The number of bytes written
+
+ Raises:
+ ValueError: When the file is closed
+ """
+ return self._s3_object.write(b)
+
+ def closed(self) -> bool:
+ """Returns whether the stream is closed or not"""
+ return self._s3_object.closed
+
+ def close(self) -> None:
+ """Closes the stream and uploads the bytes to S3"""
+ self._s3_object.close()
+
+
+class S3fsInputFile(InputFile):
+ """An input file implementation for the S3fsFileIO
+
+ Args:
+ location(str): An S3 URI
+
+ Attributes:
+ location(str): An S3 URI
+ """
+
+ def __init__(self, location: str, s3):
+ self._s3 = s3
+ super().__init__(location=location)
+
+ def __len__(self) -> int:
+ """Returns the total length of the file, in bytes"""
+ object_info = self._s3.info(self.location)
+ if object_info.get("Size"): # s3fs versions seem inconsistent on the
case used for size
Review Comment:
I guess this is a hot path bit maybe some kind of variant of `return
object_info[size] for size in ["Size", "size"] if object.(size)`?
I'm good with this but maybe it's cheaper just to try to lower case it and
avoid the if else in the length method? Just a thought.
##########
python/docker-compose.yml:
##########
@@ -0,0 +1,46 @@
+# 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.
+version: "3"
+
+services:
+ minio:
+ image: minio/minio
+ container_name: minio
+ environment:
+ - MINIO_ROOT_USER=admin
+ - MINIO_ROOT_PASSWORD=password
+ ports:
+ - 9001:9001
+ - 9000:9000
+ command: ["server", "/data", "--console-address", ":9001"]
+ mc:
+ depends_on:
+ - minio
+ image: minio/mc
+ container_name: mc
+ environment:
+ - AWS_ACCESS_KEY_ID=admin
+ - AWS_SECRET_ACCESS_KEY=password
+ - AWS_REGION=us-east-1
+ entrypoint: >
+ /bin/sh -c "
+ until (/usr/bin/mc config host add minio http://minio:9000 admin
password) do echo '...waiting...' && sleep 1; done;
+ /usr/bin/mc rm -r --force minio/testbucket;
+ /usr/bin/mc mb minio/testbucket;
+ /usr/bin/mc policy set public minio/testbucket;
+ exit 0;
Review Comment:
Question: would it be better to add the intégration tests in their own PR?
##########
python/Makefile:
##########
@@ -17,13 +17,22 @@
install:
pip install poetry
- poetry install -E pyarrow
+ poetry install -E pyarrow -E s3fs
lint:
poetry run pre-commit run --all-files
-
test:
+ poetry run coverage run --source=pyiceberg/ -m pytest tests/ -m "not
s3" ${PYTEST_ARGS}
+ poetry run coverage report -m --fail-under=90
+ poetry run coverage html
+ poetry run coverage xml
+test-all:
poetry run coverage run --source=pyiceberg/ -m pytest tests/
${PYTEST_ARGS}
poetry run coverage report -m --fail-under=90
poetry run coverage html
poetry run coverage xml
+test-s3:
Review Comment:
Eventually I think we can maybe use some kind of arguments to generify but
this is fine imo for now. And maybe later too depending.
--
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]