-
Notifications
You must be signed in to change notification settings - Fork 330
Add getting-started for Polaris Spark Client with Delta tables #1488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| # Getting Started with Apache Spark and Apache Polaris With Delta and Iceberg | ||
|
|
||
| This getting started guide provides a `docker-compose` file to set up [Apache Spark](https://spark.apache.org/) with Apache Polaris using | ||
| the new Polaris Spark Client. | ||
|
|
||
| The Polaris Spark Client enables manage of both Delta and Iceberg tables using Apache Polaris. | ||
|
|
||
| A Jupyter notebook is started to run PySpark, and Polaris Python client is also installed to call Polaris APIs | ||
| directly through Python Client. | ||
|
|
||
| ## Build the Spark Client Jar and Polaris image | ||
| If Spark Client Jar is not presented locally under plugins/spark/v3.5/build/<scala_version>/libs, please build the jar | ||
| using | ||
| - `./gradlew assemble` -- build the Polaris project and skip the tests. | ||
|
|
||
| If a Polaris image is not already present locally, build one with the following command: | ||
|
|
||
| ```shell | ||
| ./gradlew \ | ||
| :polaris-quarkus-server:assemble \ | ||
| :polaris-quarkus-server:quarkusAppPartsBuild --rerun \ | ||
| -Dquarkus.container-image.build=true | ||
| ``` | ||
|
|
||
| ## Run the `docker-compose` file | ||
|
|
||
| To start the `docker-compose` file, run this command from the repo's root directory: | ||
| ```shell | ||
| docker-compose -f plugins/spark/v3.5/getting-started/docker-compose.yml up | ||
| ``` | ||
|
|
||
| This will spin up 2 container services | ||
| * The `polaris` service for running Apache Polaris using an in-memory metastore | ||
| * The `jupyter` service for running Jupyter notebook with PySpark | ||
|
|
||
| NOTE: Starting the container first time may take a couple of minutes, because it will need to download the Spark 3.5.5. | ||
| When working with Delta, the Polaris Spark Client requires delta-io >= 3.2.1, and it requires at least Spark 3.5.3, | ||
| but the current jupyter Spark image only support Spark 3.5.0. | ||
|
|
||
| ### Run with AWS access setup | ||
| If you want to interact with S3 bucket, make sure you have the following environment variables setup correctly in | ||
| your local env before running the `docker-compose` file. | ||
| ``` | ||
| AWS_ACCESS_KEY_ID=<your_access_key> | ||
| AWS_SECRET_ACCESS_KEY=<your_secret_key> | ||
| ``` | ||
|
|
||
| ## Access the Jupyter notebook interface | ||
| In the Jupyter notebook container log, look for the URL to access the Jupyter notebook. The url should be in the | ||
| format, `http://127.0.0.1:8888/lab?token=<token>`. | ||
|
|
||
| Open the Jupyter notebook in a browser. | ||
| Navigate to [`notebooks/SparkPolaris.ipynb`](http://127.0.0.1:8888/lab/tree/notebooks/SparkPolaris.ipynb) <!-- markdown-link-check-disable-line --> | ||
|
|
||
| If the above url doesn't work, try to replace `127.0.0.1` with `localhost`, for example: | ||
| `http://localhost:8888/lab?token=<token>`. | ||
|
|
||
| ## Run the Jupyter notebook | ||
| You can now run all cells in the notebook or write your own code! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| services: | ||
| polaris: | ||
| image: apache/polaris:latest | ||
| ports: | ||
| - "8181:8181" | ||
| - "8182" | ||
| environment: | ||
| AWS_REGION: us-west-2 | ||
| AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID | ||
| AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY | ||
| POLARIS_BOOTSTRAP_CREDENTIALS: default-realm,root,s3cr3t | ||
| polaris.realm-context.realms: default-realm | ||
| quarkus.otel.sdk.disabled: "true" | ||
| healthcheck: | ||
| test: ["CMD", "curl", "http://localhost:8182/healthcheck"] | ||
| interval: 10s | ||
| timeout: 10s | ||
| retries: 5 | ||
| jupyter: | ||
| build: | ||
| context: ../../../../ # this is needed to get the ./client | ||
| dockerfile: ./plugins/spark/v3.5/getting-started/notebooks/Dockerfile | ||
| network: host | ||
| ports: | ||
| - "8888:8888" | ||
| depends_on: | ||
| polaris: | ||
| condition: service_healthy | ||
| environment: | ||
| AWS_REGION: us-west-2 | ||
| AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID | ||
| AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY | ||
| POLARIS_HOST: polaris | ||
| volumes: | ||
| - ./notebooks:/home/jovyan/notebooks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| FROM jupyter/all-spark-notebook:spark-3.5.0 | ||
|
|
||
| ENV LANGUAGE='en_US:en' | ||
|
|
||
| USER root | ||
|
|
||
| # Generic table support requires delta 3.2.1 | ||
| # Install Spark 3.5.5 | ||
| RUN wget -q https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz \ | ||
| && tar -xzf spark-3.5.5-bin-hadoop3.tgz \ | ||
| && mv spark-3.5.5-bin-hadoop3 /opt/spark \ | ||
| && rm spark-3.5.5-bin-hadoop3.tgz | ||
|
|
||
| # Set environment variables | ||
| ENV SPARK_HOME=/opt/spark | ||
| ENV PATH=$SPARK_HOME/bin:$PATH | ||
|
|
||
| USER jovyan | ||
|
|
||
| COPY --chown=jovyan client /home/jovyan/client | ||
| COPY --chown=jovyan regtests/requirements.txt /tmp | ||
| COPY --chown=jovyan plugins/spark/v3.5/spark/build/2.12/libs /home/jovyan/polaris_libs | ||
| RUN pip install -r /tmp/requirements.txt | ||
| RUN cd client/python && poetry lock && \ | ||
| python3 -m poetry install && \ | ||
| pip install -e . | ||
|
|
||
| WORKDIR /home/jovyan/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just replace
127.0.0.1withlocalhostthen, at least, we can verify it works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the url printed in the console? or just suggest to replace it in the description from the very beginning. The console print is actually controlled by the Spark Jupyter notebook image, which I don't think i can change it, i can suggest to replace 127.0.0.1 to localhost from the beginning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. NVM.