iceberg-python: Unable to load an iceberg table from aws glue catalog
Question
PyIceberg version: 0.6.0 Python version: 3.11.1
Comments:
- Iceberg tables are saved in a AWS Glue catalog
- catalog, list of namespaces and list of tables are retrievable through the catalog api
Hi,
I am facing issues loading iceberg tables from AWS Glue. The code I am using is as follow:
from opensea.resources.resources import *
import pyiceberg.catalog
profile_name = "saml2aws_profile_name"
catalog_name = "catalog name"
table_name = "table name"
aws_region = "aws region"
catalog = pyiceberg.catalog.load_catalog(
catalog_name, **{"type": "glue", "profile_name": profile_name}
)
print(catalog.list_namespaces())
table = catalog.load_table((catalog_name, table_name))
The code allow me to:
- list namespaces
- list tables
But load_table throw the following error:
Traceback (most recent call last):
File "/path/to/the/project/testing.py", line 15, in <module>
table = catalog.load_table((catalog_name, table_name))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/the/project/venv/lib/python3.11/site-packages/pyiceberg/catalog/glue.py", line 473, in load_table
return self._convert_glue_to_iceberg(self._get_glue_table(database_name=database_name, table_name=table_name))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/the/project/venv/lib/python3.11/site-packages/pyiceberg/catalog/glue.py", line 296, in _convert_glue_to_iceberg
metadata = FromInputFile.table_metadata(file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/the/project/venv/lib/python3.11/site-packages/pyiceberg/serializers.py", line 112, in table_metadata
with input_file.open() as input_stream:
^^^^^^^^^^^^^^^^^
File "/path/to/the/project/venv/lib/python3.11/site-packages/pyiceberg/io/pyarrow.py", line 263, in open
input_file = self._filesystem.open_input_file(self._path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pyarrow/_fs.pyx", line 780, in pyarrow._fs.FileSystem.open_input_file
File "pyarrow/error.pxi", line 154, in pyarrow.lib.pyarrow_internal_check_status
File "pyarrow/error.pxi", line 91, in pyarrow.lib.check_status
OSError: When reading information for key 'path/to/s3/table/location/metadata/100000-458c8ffc-de06-4eb5-bc4a-b94c3034a548.metadata.json' in bucket 's3_bucket_name': AWS Error UNKNOWN (HTTP status 400) during HeadObject operation: No response body.
I have checked I have the proper accesses, but it wasn’t the issue. I have tried a few other things but they were all unsuccessful.
- using load_glue, instead of load_catalog
- providing access_key and secret_key directly in the load_catalog call
The table definition is as follow and was created via Trino:
create table catalog_name.table_name (
"timestamp" timestamp,
"type" varchar(20),
distribution int,
service int,
code varchar(20),
base_id bigint,
counter_id bigint,
"category" varchar(50),
volume double)
with (
format = 'PARQUET',
partitioning = ARRAY['day(timestamp)'],
location = 's3://s3_bucket/path/to/table/folder/'
)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (12 by maintainers)
Your glue calls look, fine but your S3 calls are the problem. I was able to reproduce the issue by having the incorrect region for my AWS profile at
./aws/configand passing in the region config upon initializing the catalog.aws_config
catalog init
Which leads to this exception
It looks like when we infer the correct FileIO the PyarrowFs doesn’t utilize the aws profile config. Which might be delegating the calls to the default profile instead.
https://github.com/apache/iceberg-python/blob/7fcdb8d25dfa2498ba98a2b8e8d2b327d85fa7c9/pyiceberg/io/pyarrow.py#L339-L357
We might need to feed the credentials into the session properties before inferring the FileIO in the GlueCatalog, so that we actually use the correct profile when reading from S3. For now you should be able to work around this by ensuring the profiles region is in sync with the config passed into the catalog. Or pass in the
s3.regionproperty into the catalogedit: just saw the message above the fix is also there
@impproductions Thanks for the detailed explanation. Great catch!
Looking through the code, there’s indeed an expectation for both AWS credential formats.
s3.access-key-idvsaws_access_key_ids3.secret-access-keyvsaws_secret_access_keyThis issue exists for both
glueanddynamodbcatalogs https://github.com/search?q=repo%3Aapache%2Ficeberg-python+aws_secret_access_key+path%3A.py+-path%3Atests&type=codeWe had the same problem within our Airflow deployment. The easy fix for us would have been to set the default aws credentials through environment variables:
This, however, wasn’t feasible because of deployment issues. Long story short, we ended up with this solution:
If you come from a google search, please take everything that follows with a grain of salt, because we have no previous experience with either pyiceberg or airflow. Anyway.
We came to this conclusion (that we needed to pass both formats) because it seems that the the boto client initialization expects one format (the second set in the above snippet):
And the same set of properties is passed to the
load_file_iopyiceberg function, which, to the extent of our very limited understanding, expects the other format (s3.stuff):We might be completely off base here, of course, and what ultimately convinced us to adopt the above solution is just that it works, while passing either set of credentials without the other wouldn’t work for us.
We’re using:
We’re still unclear on whether it’s indeed a bug or we’re just using the APIs improperly, any help would be appreciated.
Have a nice day!
This seems to be an issue with reading the metadata file. Specifically, this line https://github.com/apache/iceberg-python/blob/781096eb0c71fa540357e0e6e3b51104ad6469ee/pyiceberg/catalog/glue.py#L320
What is the
metadata_locationof the table in the Glue catalog?