Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbdemos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.6.28"
__version__ = "0.6.32"

from .dbdemos import list_demos, install, create_cluster, help, install_all, check_status_all, check_status, get_html_list_demos

38 changes: 28 additions & 10 deletions dbdemos/notebook_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ def md_to_html(text):
"};"
"});", 1)

@staticmethod
def _replace_with_optional_escaped_quotes(content: str, old: str, new: str) -> str:
"""
Helper to replace text handling both escaped and unescaped quotes.
In JSON content, quotes are escaped as \", but in parsed content they're not.
We handle both by trying replacements with escaped quotes first, then unescaped.
This is much faster than using regex.
"""
# Try with escaped quotes first (JSON format: \")
old_escaped = old.replace('"', '\\"')
new_escaped = new.replace('"', '\\"')
content = content.replace(old_escaped, new_escaped)

# Then try with unescaped quotes (plain text format: ")
content = content.replace(old, new)

return content

@staticmethod
def replace_schema_in_content(content: str, demo_conf: DemoConf) -> str:
"""
Expand All @@ -100,8 +118,8 @@ def replace_schema_in_content(content: str, demo_conf: DemoConf) -> str:
"""
#main__build is used during the build process to avoid collision with default main.
# #main_build is used because agent don't support __ in their catalog name - TODO should improve this and move everything to main_build
content = content.replace('catalog = "main__build"', 'catalog = "main"')
content = content.replace('catalog = "main_build"', 'catalog = "main"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, 'catalog = "main__build"', 'catalog = "main"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, 'catalog = "main_build"', 'catalog = "main"')
content = content.replace(f'main__build.{demo_conf.default_schema}', f'main.{demo_conf.default_schema}')
content = content.replace(f'main_build.{demo_conf.default_schema}', f'main.{demo_conf.default_schema}')
content = content.replace('Volumes/main__build', 'Volumes/main')
Expand All @@ -112,16 +130,16 @@ def replace_schema_in_content(content: str, demo_conf: DemoConf) -> str:
content = re.sub(r"\$catalog=[0-9a-z_]*\s{1,3}\$schema=[0-9a-z_]*", f"$catalog={demo_conf.catalog} $schema={demo_conf.schema}", content)
content = re.sub(r"\$catalog=[0-9a-z_]*\s{1,3}\$db=[0-9a-z_]*", f"$catalog={demo_conf.catalog} $db={demo_conf.schema}", content)
content = content.replace(f"{demo_conf.default_catalog}.{demo_conf.default_schema}", f"{demo_conf.catalog}.{demo_conf.schema}")
content = content.replace(f'dbutils.widgets.text("catalog", "{demo_conf.default_catalog}"', f'dbutils.widgets.text("catalog", "{demo_conf.catalog}"')
content = content.replace(f'dbutils.widgets.text("schema", "{demo_conf.default_schema}"', f'dbutils.widgets.text("schema", "{demo_conf.schema}"')
content = content.replace(f'dbutils.widgets.text("db", "{demo_conf.default_schema}"', f'dbutils.widgets.text("db", "{demo_conf.schema}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'dbutils.widgets.text("catalog", "{demo_conf.default_catalog}"', f'dbutils.widgets.text("catalog", "{demo_conf.catalog}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'dbutils.widgets.text("schema", "{demo_conf.default_schema}"', f'dbutils.widgets.text("schema", "{demo_conf.schema}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'dbutils.widgets.text("db", "{demo_conf.default_schema}"', f'dbutils.widgets.text("db", "{demo_conf.schema}"')
content = content.replace(f'Volumes/{demo_conf.default_catalog}/{demo_conf.default_schema}', f'Volumes/{demo_conf.catalog}/{demo_conf.schema}')

content = content.replace(f'catalog = "{demo_conf.default_catalog}"', f'catalog = "{demo_conf.catalog}"')
content = content.replace(f'dbName = db = "{demo_conf.default_schema}"', f'dbName = db = "{demo_conf.schema}"')
content = content.replace(f'schema = dbName = db = "{demo_conf.default_schema}"', f'schema = dbName = db = "{demo_conf.schema}"')
content = content.replace(f'db = "{demo_conf.default_schema}"', f'db = "{demo_conf.schema}"')
content = content.replace(f'schema = "{demo_conf.default_schema}"', f'schema = "{demo_conf.schema}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'catalog = "{demo_conf.default_catalog}"', f'catalog = "{demo_conf.catalog}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'dbName = db = "{demo_conf.default_schema}"', f'dbName = db = "{demo_conf.schema}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'schema = dbName = db = "{demo_conf.default_schema}"', f'schema = dbName = db = "{demo_conf.schema}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'db = "{demo_conf.default_schema}"', f'db = "{demo_conf.schema}"')
content = NotebookParser._replace_with_optional_escaped_quotes(content, f'schema = "{demo_conf.default_schema}"', f'schema = "{demo_conf.schema}"')
content = content.replace(f'USE SCHEMA {demo_conf.default_schema}', f'USE SCHEMA {demo_conf.schema}')
content = content.replace(f'USE CATALOG {demo_conf.default_catalog}', f'USE CATALOG {demo_conf.catalog}')
content = content.replace(f'CREATE CATALOG IF NOT EXISTS {demo_conf.default_catalog}', f'CREATE CATALOG IF NOT EXISTS {demo_conf.catalog}')
Expand Down
20 changes: 10 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def bundle():


# Run the jobs (only if there is a new commit since the last time, or failure, or force execution)
bundler.start_and_wait_bundle_jobs(force_execution = False, skip_execution=False, recreate_jobs=False)
bundler.start_and_wait_bundle_jobs(force_execution = False, skip_execution=True, recreate_jobs=False)

packager = Packager(conf, bundler)
packager.package_all()
Expand Down Expand Up @@ -74,8 +74,6 @@ def bundle():
"""
"""

#dbdemos.install("pipeline-bike", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False)



#dbdemos.install_all("/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="AWS", start_cluster = False, skip_dashboards = True)
Expand All @@ -93,19 +91,21 @@ def bundle():
#dbdemos.install("lakehouse-monitoring", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test_lhm', cloud="AWS", start_cluster = False, skip_dashboards=False, use_current_cluster=True, debug = True)
#dbdemos.install("uc-04-system-tables", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test_sys', cloud="AWS", start_cluster = False, debug = True, serverless=True)

dbdemos.install("lakehouse-retail-c360", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main_test_quentin2', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False, create_schema=True)
dbdemos.install("lakehouse-fsi-smart-claims", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)
dbdemos.install("lakehouse-fsi-credit", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)
dbdemos.install("lakehouse-fsi-fraud", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)
dbdemos.install("lakehouse-iot-platform", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="AWS")
#dbdemos.install("declarative-pipeline-cdc", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)
#dbdemos.install("lakehouse-retail-c360", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main_test_quentin2', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False, create_schema=True, debug=True)
#dbdemos.install("lakehouse-fsi-smart-claims", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)
#dbdemos.install("lakehouse-fsi-credit", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)
#dbdemos.install("lakehouse-fsi-fraud", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test2', cloud="AWS", start_cluster = False, skip_dashboards=False)

dbdemos.install("lakehouse-iot-platform", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test3', cloud="AWS", start_cluster = False)
dbdemos.install("pipeline-bike", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test3', cloud="AWS", start_cluster = False)

#dbdemos.install("feature-store", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="AWS", use_current_cluster=False, current_cluster_id=c["current_cluster_id"])
#dbdemos.install("delta-lake", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="GCP")
#dbdemos.install("delta-lake", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="Azure", use_current_cluster=True, current_cluster_id=c["current_cluster_id"])
#dbdemos.install("mlops-end2end", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="AWS", skip_dashboards=True, schema='test_quentin_rag', catalog='dbdemos')
#dbdemos.install("pandas-on-spark", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], cloud="AWS")
#dbdemos.install("delta-sharing-airlines", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'])
#dbdemos.install("dlt-cdc", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'])
#dbdemos.install("dlt-loans", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'])
#dbdemos.install("dlt-unit-test", "/Users/quentin.ambard@databricks.com/test_install", True, c['username'], c['pat_token'], c['url'])
#dbdemos.create_cluster("uc-05-upgrade", c['username'], c['pat_token'], c['url'], "GCP")
Expand All @@ -120,4 +120,4 @@ def bundle():



#dbdemos.install("dbt-on-databricks", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test_sys', cloud="AWS", start_cluster = False, debug = True, serverless=True)
#dbdemos.install("dbt-on-databricks", "/Users/quentin.ambard@databricks.com/test_install_quentin", True, c['username'], c['pat_token'], c['url'], catalog='main', schema='quentin_test_sys', cloud="AWS", start_cluster = False, debug = True, serverless=True)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#this will be the package name you will see, e.g. the output of 'conda list' in anaconda prompt
name = 'dbdemos',
#some version number you may wish to add - increment this after every update
version='0.6.28',
version='0.6.32',
author="Databricks",
author_email=["quentin.ambard@databricks.com", "cal.reynolds@databricks.com"],
description="Install databricks demos: notebooks, Delta Live Table Pipeline, DBSQL Dashboards, ML Models etc.",
Expand Down