Skip to content

Commit fd62433

Browse files
committed
(fix): generate test notebook as part of setup
1 parent 81a7554 commit fd62433

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
work
1+
work
2+
notebooks/*.ipynb

notebooks/.gitkeep

Whitespace-only changes.

setup.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import re
55
from datetime import datetime
6+
from pathlib import Path
67

78
import docker
89
import requests
@@ -358,7 +359,29 @@ def grants_to_catalog_role_on_catalog(
358359
print(f"An error occurred: {e}")
359360

360361

361-
def run_steps():
362+
def generate_setup_notebook_cells(
363+
principal_client_id,
364+
principal_client_secret,
365+
catalog_name=os.getenv("POLARIS_CATALOG_NAME", "my_catalog"),
366+
):
367+
from jinja2 import Environment, FileSystemLoader
368+
369+
env = Environment(loader=FileSystemLoader("templates"))
370+
template_context = {
371+
"polaris_catalog_name": catalog_name,
372+
"principal_client_id": principal_client_id,
373+
"principal_client_secret": principal_client_secret,
374+
}
375+
notebook_template = env.get_template("setup_verify_notebook.ipynb.j2")
376+
content = notebook_template.render(template_context)
377+
378+
template_out_dir = Path("notebooks")
379+
template_out_dir.mkdir(exist_ok=True)
380+
with open(template_out_dir.joinpath("polaris_setup_verify.ipynb"), "w") as f:
381+
f.write(content)
382+
383+
384+
def run_steps() -> tuple[str, str]:
362385
# Get the root principal credentials from the Polaris Container logs
363386
client_id, client_secret = extract_root_principal_credentials()
364387
LOGGER.info(f"Client ID: {client_id},Client Secret: {client_secret}")
@@ -418,4 +441,9 @@ def run_steps():
418441

419442
if __name__ == "__main__":
420443
LOGGER.info("Running Polaris Demo Setup")
421-
run_steps()
444+
principal_client_id, principal_client_secret = run_steps()
445+
LOGGER.info("Generating Setup Verification Notebook Cells")
446+
generate_setup_notebook_cells(
447+
principal_client_id,
448+
principal_client_secret,
449+
)

notebooks/polaris_setup.ipynb renamed to templates/setup_verify_notebook.ipynb.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
"\n",
1212
"## DEFINE SENSITIVE VARIABLES\n",
1313
"POLARIS_URI = 'http://polaris:8181/api/catalog'\n",
14-
"POLARIS_CATALOG_NAME = 'polardb'\n",
15-
"POLARIS_CREDENTIALS = '6d3fd58497b70df7:c6f1c4c5e914cc66534ebdef2a790e55'\n",
14+
"POLARIS_CATALOG_NAME = '{{polaris_catalog_name}}'\n",
15+
"POLARIS_CREDENTIALS = '{{principal_client_id}}:{{principal_client_secret}}'\n",
1616
"POLARIS_SCOPE = 'PRINCIPAL_ROLE:ALL'\n",
1717
"\n",
1818
"conf = (\n",
1919
" pyspark.SparkConf()\n",
2020
" .setAppName('polaris_demo')\n",
21+
{% if use_maven_mirror == '3.0' %}
2122
" .set('spark.jars.ivySettings','/conf/ivy_settings.xml')\n",
23+
{% endif %}
2224
" \t\t#packages\n",
2325
" .set('spark.jars.packages', 'org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.7.1,org.apache.hadoop:hadoop-aws:3.4.0')\n",
2426
" \t\t#SQL Extensions\n",
@@ -29,8 +31,6 @@
2931
" .set('spark.sql.catalog.polardb', 'org.apache.iceberg.spark.SparkCatalog')\n",
3032
" .set('spark.sql.catalog.polardb.catalog-impl', 'org.apache.iceberg.rest.RESTCatalog')\n",
3133
" .set('spark.sql.catalog.polardb.uri', POLARIS_URI)\n",
32-
" # this causes error, TODO need to investigate\n",
33-
" #.set('spark.sql.catalog.my_catalog.oauth2-server-uri', POLARIS_URI)\n",
3434
" .set('spark.sql.catalog.polardb.credential', POLARIS_CREDENTIALS)\n",
3535
" .set('spark.sql.catalog.polardb.scope', POLARIS_SCOPE)\n",
3636
" .set('spark.sql.catalog.polardb.token-refresh-enabled', 'true')\n",

0 commit comments

Comments
 (0)