Skip to content

Commit 65b9b0a

Browse files
Update examples based on templates
1 parent e7e4acf commit 65b9b0a

File tree

9 files changed

+53
-128
lines changed

9 files changed

+53
-128
lines changed

default_python/README.md

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,18 @@
22

33
The 'default_python' project was generated by using the default-python template.
44

5-
For documentation on the Databricks Asset Bundles format use for this project,
6-
and for CI/CD configuration, see https://docs.databricks.com/aws/en/dev-tools/bundles.
7-
85
## Getting started
96

10-
Choose how you want to work on this project:
11-
12-
(a) Directly in your Databricks workspace, see
13-
https://docs.databricks.com/dev-tools/bundles/workspace.
14-
15-
(b) Locally with an IDE like Cursor or VS Code, see
16-
https://docs.databricks.com/vscode-ext.
17-
18-
(c) With command line tools, see https://docs.databricks.com/dev-tools/cli/databricks-cli.html
19-
20-
21-
Dependencies for this project should be installed using UV:
7+
0. Install UV: https://docs.astral.sh/uv/getting-started/installation/
228

23-
* Make sure you have the UV package manager installed.
24-
It's an alternative to tools like pip: https://docs.astral.sh/uv/getting-started/installation/.
25-
* Run `uv sync --dev` to install the project's dependencies.
9+
1. Install the Databricks CLI from https://docs.databricks.com/dev-tools/cli/databricks-cli.html
2610

27-
# Using this project using the CLI
28-
29-
The Databricks workspace and IDE extensions provide a graphical interface for working
30-
with this project. It's also possible to interact with it directly using the CLI:
31-
32-
1. Authenticate to your Databricks workspace, if you have not done so already:
11+
2. Authenticate to your Databricks workspace, if you have not done so already:
3312
```
3413
$ databricks configure
3514
```
3615
37-
2. To deploy a development copy of this project, type:
16+
3. To deploy a development copy of this project, type:
3817
```
3918
$ databricks bundle deploy --target dev
4019
```
@@ -44,9 +23,9 @@ with this project. It's also possible to interact with it directly using the CLI
4423
This deploys everything that's defined for this project.
4524
For example, the default template would deploy a job called
4625
`[dev yourname] default_python_job` to your workspace.
47-
You can find that job by opening your workpace and clicking on **Jobs & Pipelines**.
26+
You can find that job by opening your workpace and clicking on **Workflows**.
4827
49-
3. Similarly, to deploy a production copy, type:
28+
4. Similarly, to deploy a production copy, type:
5029
```
5130
$ databricks bundle deploy --target prod
5231
```
@@ -56,12 +35,17 @@ with this project. It's also possible to interact with it directly using the CLI
5635
is paused when deploying in development mode (see
5736
https://docs.databricks.com/dev-tools/bundles/deployment-modes.html).
5837
59-
4. To run a job or pipeline, use the "run" command:
38+
5. To run a job or pipeline, use the "run" command:
6039
```
6140
$ databricks bundle run
6241
```
63-
64-
5. Finally, to run tests locally, use `pytest`:
65-
```
66-
$ uv run pytest
67-
```
42+
6. Optionally, install the Databricks extension for Visual Studio code for local development from
43+
https://docs.databricks.com/dev-tools/vscode-ext.html. It can configure your
44+
virtual environment and setup Databricks Connect for running unit tests locally.
45+
When not using these tools, consult your development environment's documentation
46+
and/or the documentation for Databricks Connect for manually setting up your environment
47+
(https://docs.databricks.com/en/dev-tools/databricks-connect/python/index.html).
48+
49+
7. For documentation on the Databricks asset bundles format used
50+
for this project, and for CI/CD configuration, see
51+
https://docs.databricks.com/dev-tools/bundles/index.html.

default_python/conftest.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

default_python/pyproject.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ version = "0.0.1"
44
authors = [{ name = "[email protected]" }]
55
requires-python = ">= 3.11"
66

7-
[dependency-groups]
7+
[project.optional-dependencies]
88
dev = [
99
"pytest",
1010

1111
# Code completion support for DLT, also install databricks-connect
1212
"databricks-dlt",
1313

1414
# databricks-connect can be used to run parts of this project locally.
15-
# Note that for local development, you should use a version that is not newer
16-
# than the remote cluster or serverless compute you connect to.
17-
# See also https://docs.databricks.com/dev-tools/databricks-connect.html.
18-
"databricks-connect>=15.4,<15.5",
15+
# See https://docs.databricks.com/dev-tools/databricks-connect.html.
16+
#
17+
# Note, databricks-connect is automatically installed if you're using Databricks
18+
# extension for Visual Studio Code
19+
# (https://docs.databricks.com/dev-tools/vscode-ext/dev-tasks/databricks-connect.html).
20+
#
21+
# To manually install databricks-connect, uncomment the line below to install a version
22+
# of db-connect that corresponds to the Databricks Runtime version used for this project.
23+
# See https://docs.databricks.com/dev-tools/databricks-connect.html
24+
# "databricks-connect>=15.4,<15.5",
1925
]
2026

2127
[tool.pytest.ini_options]

default_python/scratch/exploration.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"sys.path.append(\"../src\")\n",
3333
"from default_python import main\n",
3434
"\n",
35-
"main.get_taxis().show(10)"
35+
"main.get_taxis(spark).show(10)"
3636
]
3737
}
3838
],

default_python/src/default_python/main.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
from databricks.sdk.runtime import spark
2-
from pyspark.sql import DataFrame
1+
from pyspark.sql import SparkSession, DataFrame
32

43

5-
def find_all_taxis() -> DataFrame:
4+
def get_taxis(spark: SparkSession) -> DataFrame:
65
return spark.read.table("samples.nyctaxi.trips")
76

87

8+
# Create a new Databricks Connect session. If this fails,
9+
# check that you have configured Databricks Connect correctly.
10+
# See https://docs.databricks.com/dev-tools/databricks-connect.html.
11+
def get_spark() -> SparkSession:
12+
try:
13+
from databricks.connect import DatabricksSession
14+
15+
return DatabricksSession.builder.getOrCreate()
16+
except ImportError:
17+
return SparkSession.builder.getOrCreate()
18+
19+
920
def main():
10-
find_all_taxis().show(5)
21+
get_taxis(get_spark()).show(5)
1122

1223

1324
if __name__ == "__main__":

default_python/src/dlt_pipeline.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"source": [
5757
"@dlt.view\n",
5858
"def taxi_raw():\n",
59-
" return main.find_all_taxis()\n",
59+
" return main.get_taxis(spark)\n",
6060
"\n",
6161
"\n",
6262
"@dlt.table\n",

default_python/src/notebook.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"source": [
4747
"from default_python import main\n",
4848
"\n",
49-
"main.find_all_taxis().show(10)"
49+
"main.get_taxis(spark).show(10)"
5050
]
5151
}
5252
],

default_python/tests/main_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from default_python import main
1+
from default_python.main import get_taxis, get_spark
22

33

4-
def test_find_all_taxis():
5-
taxis = main.find_all_taxis()
4+
def test_main():
5+
taxis = get_taxis(get_spark())
66
assert taxis.count() > 5

scripts/update_from_templates.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ if [ ! "$DATABRICKS_HOST" ]; then
5050
exit 1
5151
fi
5252

53-
if [ -n "$1" ]; then
53+
# Prompt for CURRENT_USER_NAME if not passed as first arg
54+
if [ -n "${1-}" ]; then
5455
CURRENT_USER_NAME="$1"
5556
else
56-
read -p "Enter the current user name (e.g., 'lennart_kats'): " CURRENT_USER_NAME
57-
read -p "Enter the current user name (e.g., 'lennart_kats'): " CURRENT_USER_NAME
58-
if [ ! "$CURRENT_USER_NAME" ]; then
57+
read -r -p "Enter the current user name of your 'DEFAULT' profile (e.g., 'lennart_kats'): " CURRENT_USER_NAME
58+
if [ -z "${CURRENT_USER_NAME:-}" ]; then
5959
echo "Error: current user name is required." >&2
6060
exit 1
6161
fi

0 commit comments

Comments
 (0)