apache / apache/iceberg-python

REST catalog, S3tables with botocore session

Abierto
#2,657 1 comentario 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
1.1k
Forks
581
Merge medio
1 d 17 h
PR fusionados (30 d)
78

Descripción

### Apache Iceberg version

0.10.0

### Please describe the bug 🐞

Since 0.10.0, it is now possible to use a [botocore session](https://github.com/apache/iceberg-python/pull/2071) for a rest catalog, so:

```
import io
import os

import pandas as pd
import pyarrow as pa

from boto3 import Session
from pyiceberg.catalog import load_catalog

boto3_session = Session(profile_name='a_profile', region_name='us-east-1')

catalog = load_catalog(
"catalog",
type="rest",
botocore_session=boto3_session._session,
warehouse="arn:aws:s3tables:us-east-1:XXXXXXXXXXX:bucket/a_bucket",
uri=f"https://s3tables.us-east-1.amazonaws.com/iceberg",
**{
"rest.sigv4-enabled": "true",
"rest.signing-name": "s3tables",
"rest.signing-region": "us-east-1"
})

table = catalog.load_table("namespace.a_table")

json_string = "[{\"data\":\"000000000000\", ...}]"
df = pd.read_json(io.StringIO(json_string), orient='records')

arrow_table = pa.Table.from_pandas(df=df, schema=table.schema().as_arrow())

table.overwrite(arrow_table)
```

It works until we ".overwrite()":
> OSError: When reading information for key 'metadata/snap-6778585584222594295-0-3ae9518f-fd1c-488f-b3d2-4ca1724317a1.avro' in bucket '2c8e7acb-67a1-4dc9-8ym9eg38966b8bazzfjn487w5o9wruse1b--table-s3': AWS Error UNKNOWN (HTTP status 400) during HeadObject operation: No response body.

To "fix" it, we can do:

```
boto3_session = Session(profile_name='a_profile', region_name='us-east-1')

catalog = load_catalog(
"catalog",
type="rest",
botocore_session=boto3_session._session,
warehouse="arn:aws:s3tables:us-east-1:XXXXXXXXXXX:bucket/a_bucket",
uri=f"https://s3tables.us-east-1.amazonaws.com/iceberg",
**{
"rest.sigv4-enabled": "true",
"rest.signing-name": "s3tables",
"rest.signing-region": "us-east-1"
})

table = catalog.load_table("namespace.a_table")

json_string = "[{\"data\":\"000000000000\", ...}]"
df = pd.read_json(io.StringIO(json_string), orient='records')

arrow_table = pa.Table.from_pandas(df=df, schema=table.schema().as_arrow())

credentials = boto3_session.get_credentials().get_frozen_credentials()
os.environ["AWS_ACCESS_KEY_ID"] = credentials.access_key
os.environ["AWS_SECRET_ACCESS_KEY"] = credentials.secret_key
if credentials.token:
os.environ["AWS_SESSION_TOKEN"] = credentials.token
table.overwrite(arrow_table)
```

which works but defeats the purpose.

We can access .schema() and such. So it seems the overwrite method is not using the proper SigV4Adapter (pyiceberg/catalog/rest/__init__.py).

### Willingness to contribute

- [ ] I can contribute a fix for this bug independently
- [x] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza en pyiceberg/catalog/rest/__init__.py y sigue cómo se utilizan la sesión de botocore y SigV4Adapter para acceder al catálogo frente a table.overwrite(). Reproduce el ejemplo de S3 Tables y sigue la llamada HeadObject que falla; el trabajo estará terminado cuando overwrite funcione con botocore_session sin exportar las credenciales de AWS.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
aws, python
Área
cloud, databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.