Skip to content

Commit ca35bba

Browse files
authored
Doc: Add getting started with JDBC source (#1470)
1 parent 72f0418 commit ca35bba

File tree

9 files changed

+232
-4
lines changed

9 files changed

+232
-4
lines changed

extension/persistence/relational-jdbc/src/main/resources/postgres/schema-v1.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ COMMENT ON COLUMN grant_records.grantee_catalog_id IS 'catalog id of the grantee
7979
COMMENT ON COLUMN grant_records.grantee_id IS 'id of the grantee';
8080
COMMENT ON COLUMN grant_records.privilege_code IS 'privilege code';
8181

82-
8382
CREATE TABLE IF NOT EXISTS principal_authentication_data (
8483
realm_id TEXT NOT NULL,
8584
principal_id BIGINT NOT NULL,

getting-started/eclipselink/docker-compose-postgres.yml renamed to getting-started/assets/postgres/docker-compose-postgres.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
volumes:
3333
# Bind local conf file to a convenient location in the container
3434
- type: bind
35-
source: ./postgresql.conf
35+
source: ../assets/postgres/postgresql.conf
3636
target: /etc/postgresql/postgresql.conf
3737
command:
3838
- "postgres"

getting-started/eclipselink/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This example requires `jq` to be installed on your machine.
3737
2. Start the docker compose group by running the following command from the root of the repository:
3838

3939
```shell
40-
docker compose -f getting-started/eclipselink/docker-compose-postgres.yml -f getting-started/eclipselink/docker-compose-bootstrap-db.yml -f getting-started/eclipselink/docker-compose.yml up
40+
docker compose -f getting-started/eclipselink/docker-compose-bootstrap-db.yml -f getting-started/assets/postgres/docker-compose-postgres.yml -f getting-started/eclipselink/docker-compose.yml up
4141
```
4242

4343
3. Using spark-sql: attach to the running spark-sql container:

getting-started/eclipselink/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ services:
9696
ports:
9797
- "8080:8080"
9898
volumes:
99-
- ./trino-config/catalog:/etc/trino/catalog
99+
- ../assets/trino-config/catalog:/etc/trino/catalog

getting-started/jdbc/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Getting Started with Apache Polaris, Relational JDBC, Postgres and Spark SQL
21+
22+
This example requires `jq` to be installed on your machine.
23+
24+
1. If such an image is not already present, build the Polaris image with support for JDBC persistence and
25+
the Postgres JDBC driver:
26+
27+
```shell
28+
./gradlew \
29+
:polaris-quarkus-server:assemble \
30+
:polaris-quarkus-server:quarkusAppPartsBuild --rerun \
31+
:polaris-quarkus-admin:assemble \
32+
:polaris-quarkus-admin:quarkusAppPartsBuild --rerun \
33+
-Dquarkus.container-image.tag=postgres-latest \
34+
-Dquarkus.container-image.build=true
35+
```
36+
37+
2. Start the docker compose group by running the following command from the root of the repository:
38+
39+
```shell
40+
docker compose -f getting-started/jdbc/docker-compose-bootstrap-db.yml -f getting-started/assets/postgres/docker-compose-postgres.yml -f getting-started/jdbc/docker-compose.yml up
41+
```
42+
43+
3. Using spark-sql: attach to the running spark-sql container:
44+
45+
```shell
46+
docker attach $(docker ps -q --filter name=spark-sql)
47+
```
48+
49+
You may not see Spark's prompt immediately, type ENTER to see it. A few commands that you can try:
50+
51+
```sql
52+
CREATE NAMESPACE polaris.ns1;
53+
USE polaris.ns1;
54+
CREATE TABLE table1 (id int, name string);
55+
INSERT INTO table1 VALUES (1, 'a');
56+
SELECT * FROM table1;
57+
```
58+
59+
4. To access Polaris from the host machine, first request an access token:
60+
61+
```shell
62+
export POLARIS_TOKEN=$(curl -s http://polaris:8181/api/catalog/v1/oauth/tokens \
63+
--resolve polaris:8181:127.0.0.1 \
64+
--user root:s3cr3t \
65+
-d 'grant_type=client_credentials' \
66+
-d 'scope=PRINCIPAL_ROLE:ALL' | jq -r .access_token)
67+
```
68+
69+
5. Then, use the access token in the Authorization header when accessing Polaris:
70+
71+
```shell
72+
curl -v http://127.0.0.1:8181/api/management/v1/principal-roles -H "Authorization: Bearer $POLARIS_TOKEN"
73+
curl -v http://127.0.0.1:8181/api/management/v1/catalogs/quickstart_catalog -H "Authorization: Bearer $POLARIS_TOKEN"
74+
```
75+
76+
6. Using Trino CLI: To access the Trino CLI, run this command:
77+
```shell
78+
docker exec -it jdbc-trino-1 trino
79+
```
80+
Note, `jdbc-trino-1` is the name of the Docker container.
81+
82+
Example Trino queries:
83+
```
84+
SHOW CATALOGS;
85+
SHOW SCHEMAS FROM iceberg;
86+
SHOW TABLES FROM iceberg.information_schema;
87+
DESCRIBE iceberg.information_schema.tables;
88+
89+
CREATE SCHEMA iceberg.tpch;
90+
CREATE TABLE iceberg.tpch.test_polaris AS SELECT 1 x;
91+
SELECT * FROM iceberg.tpch.test_polaris;
92+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
services:
21+
polaris-bootstrap:
22+
# IMPORTANT: the image MUST contain the Postgres JDBC driver and EclipseLink dependencies, see README for instructions
23+
image: apache/polaris-admin-tool:postgres-latest
24+
environment:
25+
polaris.persistence.type: relational-jdbc
26+
quarkus.datasource.db-kind: pgsql
27+
quarkus.datasource.jdbc.url: jdbc:postgresql://postgres:5432/POLARIS
28+
quarkus.datasource.username: postgres
29+
quarkus.datasource.password: postgres
30+
command:
31+
- "bootstrap"
32+
- "--realm=POLARIS"
33+
- "--credential=POLARIS,root,s3cr3t"
34+
35+
polaris:
36+
depends_on:
37+
polaris-bootstrap:
38+
condition: service_completed_successfully
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
services:
21+
22+
polaris:
23+
image: apache/polaris:postgres-latest
24+
ports:
25+
# API port
26+
- "8181:8181"
27+
# Management port (metrics and health checks)
28+
- "8182:8182"
29+
# Optional, allows attaching a debugger to the Polaris JVM
30+
- "5005:5005"
31+
environment:
32+
JAVA_DEBUG: "true"
33+
JAVA_DEBUG_PORT: "*:5005"
34+
polaris.persistence.type: relational-jdbc
35+
quarkus.datasource.db-kind: pgsql
36+
quarkus.datasource.jdbc.url: jdbc:postgresql://postgres:5432/POLARIS
37+
quarkus.datasource.username: postgres
38+
quarkus.datasource.password: postgres
39+
polaris.realm-context.realms: POLARIS
40+
quarkus.otel.sdk.disabled: "true"
41+
healthcheck:
42+
test: ["CMD", "curl", "http://localhost:8182/q/health"]
43+
interval: 2s
44+
timeout: 10s
45+
retries: 10
46+
start_period: 10s
47+
48+
polaris-setup:
49+
image: alpine/curl
50+
depends_on:
51+
polaris:
52+
condition: service_healthy
53+
environment:
54+
- STORAGE_LOCATION=${STORAGE_LOCATION}
55+
- AWS_ROLE_ARN=${AWS_ROLE_ARN}
56+
- AZURE_TENANT_ID=${AZURE_TENANT_ID}
57+
volumes:
58+
- ../assets/polaris/:/polaris
59+
entrypoint: '/bin/sh -c "chmod +x /polaris/create-catalog.sh && /polaris/create-catalog.sh"'
60+
61+
spark-sql:
62+
image: apache/spark:3.5.5-java17-python3
63+
depends_on:
64+
polaris-setup:
65+
condition: service_completed_successfully
66+
stdin_open: true
67+
tty: true
68+
ports:
69+
- "4040-4045:4040-4045"
70+
healthcheck:
71+
test: "curl localhost:4040"
72+
interval: 5s
73+
retries: 15
74+
command: [
75+
/opt/spark/bin/spark-sql,
76+
--packages, "org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.7.0,software.amazon.awssdk:bundle:2.28.17,software.amazon.awssdk:url-connection-client:2.28.17,org.apache.iceberg:iceberg-gcp-bundle:1.7.0,org.apache.iceberg:iceberg-azure-bundle:1.7.0",
77+
--conf, "spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions",
78+
--conf, "spark.sql.catalog.polaris=org.apache.iceberg.spark.SparkCatalog",
79+
--conf, "spark.sql.catalog.polaris.type=rest",
80+
--conf, "spark.sql.catalog.polaris.warehouse=quickstart_catalog",
81+
--conf, "spark.sql.catalog.polaris.uri=http://polaris:8181/api/catalog",
82+
--conf, "spark.sql.catalog.polaris.credential=root:s3cr3t",
83+
--conf, "spark.sql.catalog.polaris.scope=PRINCIPAL_ROLE:ALL",
84+
--conf, "spark.sql.defaultCatalog=polaris",
85+
--conf, "spark.sql.catalogImplementation=in-memory",
86+
--conf, "spark.driver.extraJavaOptions=-Divy.cache.dir=/tmp -Divy.home=/tmp"
87+
]
88+
89+
trino:
90+
image: trinodb/trino:latest
91+
depends_on:
92+
polaris-setup:
93+
condition: service_completed_successfully
94+
stdin_open: true
95+
tty: true
96+
ports:
97+
- "8080:8080"
98+
volumes:
99+
- ../assets/trino-config/catalog:/etc/trino/catalog

0 commit comments

Comments
 (0)