Skip to content

Commit 707d18f

Browse files
committed
doc: full iceberg-rest example
1 parent 85068b0 commit 707d18f

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export CATALOG_CATALOG__IMPL=org.apache.iceberg.aws.glue.GlueCatalog
1212
java -jar ./build/libs/iceberg-rest-image-all.jar
1313
```
1414

15+
## Example
16+
17+
how run a iceberg-rest service using a centralized external database -> [example](./example/README.md)
18+
1519
## Browse
1620

1721
To browse the catalog, you can use `pyiceberg`:

example/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# iceberg-rest example
2+
3+
how start the example stack
4+
5+
```shell
6+
docker compose up -d
7+
```
8+
9+
then
10+
11+
```shell
12+
pip install "pyiceberg[s3fs,pyarrow]
13+
curl https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2023-01.parquet -o /tmp/yellow_tripdata_2023-01.parquet
14+
python3 iceberg_s3_example.py
15+
```

example/docker-compose.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
services:
2+
minio:
3+
image: minio/minio:RELEASE.2024-05-27T19-17-46Z
4+
command: server /data --console-address ":9001"
5+
ports:
6+
- "9020:9000"
7+
- "9021:9001"
8+
environment:
9+
MINIO_ROOT_USER: admin
10+
MINIO_ROOT_PASSWORD: adminadmin
11+
MINIO_SITE_REGION: eu-west-3
12+
13+
createbuckets:
14+
image: minio/mc
15+
depends_on:
16+
- minio
17+
entrypoint: >
18+
/bin/sh -c "
19+
echo sleep 10;
20+
sleep 10;
21+
/usr/bin/mc config host add myminio http://minio:9000 admin adminadmin;
22+
/usr/bin/mc mb myminio/test-bucket;
23+
exit 0;
24+
"
25+
26+
iceberg_rest:
27+
image: tabulario/iceberg-rest
28+
depends_on:
29+
iceberg_rest-db:
30+
condition: service_healthy
31+
ports:
32+
- 8181:8181
33+
environment:
34+
- AWS_ACCESS_KEY_ID=admin
35+
- AWS_SECRET_ACCESS_KEY=adminadmin
36+
- AWS_REGION=eu-west-3
37+
- CATALOG_WAREHOUSE=s3://test-bucket/
38+
- CATALOG_IO__IMPL=org.apache.iceberg.aws.s3.S3FileIO
39+
- CATALOG_S3_ENDPOINT=http://minio:9000
40+
- CATALOG_S3_PATH__STYLE__ACCESS=true
41+
- iceberg_rest-db=org.apache.iceberg.jdbc.JdbcCatalog
42+
- CATALOG_URI=jdbc:postgresql://iceberg_rest-db:5432/iceberg_restdb
43+
- CATALOG_JDBC_USER=iceberg_rest
44+
- CATALOG_JDBC_PASSWORD=password
45+
46+
iceberg_rest-db:
47+
image: postgres:15.2
48+
init: true
49+
environment:
50+
POSTGRES_DB: iceberg_restdb
51+
POSTGRES_USER: iceberg_rest
52+
POSTGRES_PASSWORD: password
53+
ports:
54+
- "5436:5432"
55+
healthcheck:
56+
test: [ "CMD", "pg_isready", "-U", "iceberg_rest", "-d", "iceberg_restdb" ]
57+
interval: 5s
58+
retries: 5

example/iceberg_s3_example.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# pip install "pyiceberg[s3fs,pyarrow]
2+
# curl https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2023-01.parquet -o /tmp/yellow_tripdata_2023-01.parquet
3+
4+
import os
5+
6+
os.environ["AWS_DEFAULT_REGION"] = "eu-west-3"
7+
os.environ["AWS_REGION"] = "eu-west-3"
8+
os.environ["AWS_ACCESS_KEY_ID"] = "admin"
9+
os.environ["AWS_SECRET_ACCESS_KEY"] = "adminadmin"
10+
11+
12+
def run_iceberg():
13+
from pyiceberg.catalog.rest import RestCatalog
14+
15+
catalog = RestCatalog(
16+
"default",
17+
**{
18+
"uri": "http://localhost:8181",
19+
"warehouse": "s3://test-bucket/",
20+
"s3.endpoint": "http://localhost:9020",
21+
},
22+
)
23+
import pyarrow.parquet as pq
24+
25+
df = pq.read_table("/tmp/yellow_tripdata_2023-01.parquet")
26+
27+
catalog.create_namespace("default")
28+
table = catalog.create_table(
29+
"default.taxi_dataset",
30+
schema=df.schema,
31+
)
32+
33+
table.append(df)
34+
35+
36+
table = catalog.load_table("default.taxi_dataset")
37+
df = table.scan().to_arrow()
38+
print(len(df))
39+
40+
41+
if __name__ == '__main__':
42+
run_iceberg()

0 commit comments

Comments
 (0)