-
Notifications
You must be signed in to change notification settings - Fork 126
Update examples using scripts/update_from_templates.sh and add missing files #114
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
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,90 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "application/vnd.databricks.v1+cell": { | ||
| "cellMetadata": {}, | ||
| "inputWidgets": {}, | ||
| "nuid": "9a626959-61c8-4bba-84d2-2a4ecab1f7ec", | ||
| "showTitle": false, | ||
| "title": "" | ||
| } | ||
| }, | ||
| "source": [ | ||
| "# Lakeflow Declarative Pipeline\n", | ||
| "\n", | ||
| "This Lakeflow Declarative Pipeline definition is executed using a pipeline defined in resources/default_python.pipeline.yml." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 0, | ||
| "metadata": { | ||
| "application/vnd.databricks.v1+cell": { | ||
| "cellMetadata": {}, | ||
| "inputWidgets": {}, | ||
| "nuid": "9198e987-5606-403d-9f6d-8f14e6a4017f", | ||
| "showTitle": false, | ||
| "title": "" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Import DLT and src/default_python\n", | ||
| "import dlt\n", | ||
| "import sys\n", | ||
| "\n", | ||
| "sys.path.append(spark.conf.get(\"bundle.sourcePath\", \".\"))\n", | ||
| "from pyspark.sql.functions import expr\n", | ||
| "from default_python import main" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 0, | ||
| "metadata": { | ||
| "application/vnd.databricks.v1+cell": { | ||
| "cellMetadata": {}, | ||
| "inputWidgets": {}, | ||
| "nuid": "3fc19dba-61fd-4a89-8f8c-24fee63bfb14", | ||
| "showTitle": false, | ||
| "title": "" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "@dlt.view\n", | ||
| "def taxi_raw():\n", | ||
| " return main.find_all_taxis()\n", | ||
| "\n", | ||
| "\n", | ||
| "@dlt.table\n", | ||
| "def filtered_taxis():\n", | ||
| " return dlt.read(\"taxi_raw\").filter(expr(\"fare_amount < 30\"))" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "application/vnd.databricks.v1+notebook": { | ||
| "dashboards": [], | ||
| "language": "python", | ||
| "notebookMetadata": { | ||
| "pythonIndentUnit": 2 | ||
| }, | ||
| "notebookName": "pipeline", | ||
| "widgets": {} | ||
| }, | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "name": "python", | ||
| "version": "3.11.4" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 0 | ||
| } |
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,59 @@ | ||
| """This file configures pytest.""" | ||
|
|
||
| import os, sys, pathlib | ||
| from contextlib import contextmanager | ||
|
|
||
|
|
||
| try: | ||
| from databricks.connect import DatabricksSession | ||
| from databricks.sdk import WorkspaceClient | ||
| from pyspark.sql import SparkSession | ||
| import pytest | ||
| except ImportError: | ||
| raise ImportError( | ||
| "Test dependencies not found.\n\nRun tests using 'uv run pytest'. See http://docs.astral.sh/uv to learn more about uv." | ||
| ) | ||
|
|
||
|
|
||
| def enable_fallback_compute(): | ||
| """Enable serverless compute if no compute is specified.""" | ||
| conf = WorkspaceClient().config | ||
| if conf.serverless_compute_id or conf.cluster_id or os.environ.get("SPARK_REMOTE"): | ||
| return | ||
|
|
||
| url = "https://docs.databricks.com/dev-tools/databricks-connect/cluster-config" | ||
| print("☁️ no compute specified, falling back to serverless compute", file=sys.stderr) | ||
| print(f" see {url} for manual configuration", file=sys.stderr) | ||
|
|
||
| os.environ["DATABRICKS_SERVERLESS_COMPUTE_ID"] = "auto" | ||
|
|
||
|
|
||
| @contextmanager | ||
| def allow_stderr_output(config: pytest.Config): | ||
| """Temporarily disable pytest output capture.""" | ||
| capman = config.pluginmanager.get_plugin("capturemanager") | ||
| if capman: | ||
| with capman.global_and_fixture_disabled(): | ||
| yield | ||
| else: | ||
| yield | ||
|
|
||
|
|
||
| def pytest_configure(config: pytest.Config): | ||
| """Configure pytest session.""" | ||
| with allow_stderr_output(config): | ||
| enable_fallback_compute() | ||
|
|
||
| # Initialize Spark session eagerly, so it is available even when | ||
| # SparkSession.builder.getOrCreate() is used. For DB Connect 15+, | ||
| # we validate version compatibility with the remote cluster. | ||
| if hasattr(DatabricksSession.builder, "validateSession"): | ||
| DatabricksSession.builder.validateSession().getOrCreate() | ||
| else: | ||
| DatabricksSession.builder.getOrCreate() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def spark() -> SparkSession: | ||
| """Provide a SparkSession fixture for tests.""" | ||
| return DatabricksSession.builder.getOrCreate() |
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,29 @@ | ||
| [project] | ||
| name = "lakeflow_pipelines_python" | ||
| version = "0.0.1" | ||
| authors = [{ name = "user@company.com" }] | ||
| requires-python = ">=3.10,<=3.13" | ||
| dependencies = [ | ||
| # Any dependencies for jobs and pipelines in this project can be added here | ||
| # See also https://docs.databricks.com/dev-tools/bundles/library-dependencies | ||
| # | ||
| # LIMITATION: for pipelines, dependencies are cached during development; | ||
| # add dependencies to the 'environment' section of pipeline.yml file instead | ||
| ] | ||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "pytest", | ||
| "databricks-dlt", | ||
| "databricks-connect>=15.4,<15.5", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
| main = "lakeflow_pipelines_python.main:main" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [tool.black] | ||
| line-length = 125 |
20 changes: 20 additions & 0 deletions
20
lakeflow_pipelines_python/resources/pipelines_python_etl.pipeline.yml
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,20 @@ | ||
| # The main pipeline for lakeflow_pipelines_python | ||
|
|
||
| resources: | ||
| pipelines: | ||
| pipelines_python_etl: | ||
| name: pipelines_python_etl | ||
| catalog: ${var.catalog} | ||
| schema: ${var.schema} | ||
| serverless: true | ||
| root_path: "../src/pipelines_python_etl" | ||
|
|
||
| libraries: | ||
| - glob: | ||
| include: ../src/pipelines_python_etl/transformations/** | ||
|
|
||
| environment: | ||
| dependencies: | ||
| # We include every dependency defined by pyproject.toml by defining an editable environment | ||
| # that points to the folder where pyproject.toml is deployed. | ||
| - --editable ${workspace.file_path} |
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,32 @@ | ||
| # A sample job for lakeflow_pipelines_python. | ||
|
|
||
| resources: | ||
| jobs: | ||
| sample_job: | ||
| name: sample_job | ||
|
|
||
| trigger: | ||
| # Run this job every day, exactly one day from the last run; see https://docs.databricks.com/api/workspace/jobs/create#trigger | ||
| periodic: | ||
| interval: 1 | ||
| unit: DAYS | ||
|
|
||
| #email_notifications: | ||
| # on_failure: | ||
| # - your_email@example.com | ||
|
|
||
| parameters: | ||
| - name: catalog | ||
| default: ${var.catalog} | ||
| - name: schema | ||
| default: ${var.schema} | ||
|
|
||
| tasks: | ||
| - task_key: refresh_pipeline | ||
| pipeline_task: | ||
| pipeline_id: ${resources.pipelines.pipelines_python_etl.id} | ||
|
|
||
| environments: | ||
| - environment_key: default | ||
| spec: | ||
| environment_version: "2" |
20 changes: 20 additions & 0 deletions
20
lakeflow_pipelines_python/src/pipelines_python_etl/README.md
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,20 @@ | ||
| # lakeflow_pipelines_python | ||
|
|
||
| This folder defines all source code for the lakeflow_pipelines_python pipeline: | ||
|
|
||
| - `explorations/`: Ad-hoc notebooks used to explore the data processed by this pipeline. | ||
| - `transformations/`: All dataset definitions and transformations. | ||
| - `utilities/` (optional): Utility functions and Python modules used in this pipeline. | ||
| - `data_sources/` (optional): View definitions describing the source data for this pipeline. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| To get started, go to the `transformations` folder -- most of the relevant source code lives there: | ||
|
|
||
| * By convention, every dataset under `transformations` is in a separate file. | ||
| * Take a look at the sample called "sample_trips_lakeflow_pipelines_python.py" to get familiar with the syntax. | ||
| Read more about the syntax at https://docs.databricks.com/dlt/python-ref.html. | ||
| * If you're using the workspace UI, use `Run file` to run and preview a single transformation. | ||
| * If you're using the CLI, use `databricks bundle run pipelines_python_etl --select sample_trips_lakeflow_pipelines_python` to run a single transformation. | ||
|
|
||
| For more tutorials and reference material, see https://docs.databricks.com/dlt. |
12 changes: 12 additions & 0 deletions
12
...python/src/pipelines_python_etl/transformations/sample_trips_lakeflow_pipelines_python.py
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,12 @@ | ||
| from pyspark import pipelines as dp | ||
| from pyspark.sql.functions import col | ||
|
|
||
|
|
||
| # This file defines a sample transformation. | ||
| # Edit the sample below or add new transformations | ||
| # using "+ Add" in the file browser. | ||
|
|
||
|
|
||
| @dp.table | ||
| def sample_trips_lakeflow_pipelines_python(): | ||
| return spark.read.table("samples.nyctaxi.trips") |
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.
This file is not referred to anywhere.
Does this come from a released CLI?
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.
This is from https://github.com/databricks/cli/blob/main/libs/template/templates/default-python/template/%7B%7B.project_name%7D%7D/src/pipeline.ipynb.tmpl
And yes this is all based on Databricks CLI 0.274.0
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.
Now that pipeline sources are all in a directory, do we still need the notebook or can it be removed?
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.
This is still the old template from main 🤷 We'll get rid of this soon!