Skip to content

Commit bef14f2

Browse files
Noonan/data platfrom blog (#33083)
# Add Multi-Platform Data Example ## Summary Adds multi-platform-data example demonstrating a multi-code-location workspace architecture using Dagster's dg.toml workspace configuration ## Description Showcases how to structure a heterogeneous data platform with multiple code locations: Databricks Delta code location: Lakehouse medallion architecture (bronze → silver → gold) with Delta Lake storage Snowflake Medallion code location: ELT with dbt transformations and SQL-based medallion architecture Uses the dg.toml workspace configuration pattern for managing multiple independent projects within a single workspace. Both projects support demo mode for local development without external cloud dependencies. ## Test Plan [ ] Run tests in examples/multi-platform-data/projects/databricks-delta: uv sync && pytest tests/ -v [ ] Run tests in examples/multi-platform-data/projects/snowflake-medallion: uv sync && pytest tests/ -v [ ] Verify dg dev runs successfully from examples/multi-platform-data/deployments/local [ ] Verify make ruff passes [] Verify make pyright passes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds a new multi-code-location example (project_databricks_and_snowflake) with a Snowflake medallion project using dbt and Dagster components/resources, plus tests, and registers it in the download templates. > > - **Examples/Workspace**: > - Introduces `examples/project_databricks_and_snowflake` with workspace scaffolding and `pyproject.toml`. > - **Snowflake Medallion Project** (`projects/snowflake-medallion`): > - Adds Dagster defs: `definitions.py`, component `defs/components/medallion` (custom `SnowflakeKindTranslator`, `MedallionComponent`, params), and `resources.py` (configurable `SnowflakeResource`, `create_dbt_resource`, demo mode support). > - Includes dbt project (`dbt_project/`): profiles, project config, seeds (`raw_customers.csv`), and medallion models (`bronze`, `silver`, `gold`). > - Provides tests (`tests/`) for definitions and Snowflake resource. > - Locks dependencies (`uv.lock`) and project config (`pyproject.toml`). > - **Tooling**: > - Registers `project_databricks_and_snowflake` in `_generate/download.py` template list. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5c03b7c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent e88f03f commit bef14f2

40 files changed

Lines changed: 9040 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Databricks Configuration
2+
DATABRICKS_SERVER_HOSTNAME=your-workspace.cloud.databricks.com
3+
DATABRICKS_HTTP_PATH=/sql/1.0/warehouses/your-warehouse-id
4+
DATABRICKS_TOKEN=dapi_your_token_here
5+
DELTA_STORAGE_PATH=data/delta
6+
7+
# Snowflake Configuration
8+
SNOWFLAKE_ACCOUNT=your-account.region
9+
SNOWFLAKE_USER=your_user
10+
SNOWFLAKE_PASSWORD=your_password
11+
SNOWFLAKE_WAREHOUSE=COMPUTE_WH
12+
SNOWFLAKE_DATABASE=your_database
13+
SNOWFLAKE_SCHEMA=PUBLIC
14+
15+
# Demo Mode (set to empty string to disable)
16+
DEMO_MODE=true
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Databricks and Snowflake Example
2+
3+
A Dagster workspace demonstrating how to build heterogeneous data platforms using multiple code locations. This project showcases production data platform patterns with Databricks Delta Lake and Snowflake dbt medallion architectures as separate projects within a workspace.
4+
5+
## Project Structure
6+
7+
```
8+
project_databricks_and_snowflake/
9+
├── dg.toml # Workspace configuration
10+
├── dagster_cloud.yaml # Dagster+ deployment configuration
11+
├── deployments/
12+
│ └── local/
13+
│ └── pyproject.toml # Local environment for dg commands
14+
├── projects/
15+
│ ├── databricks-delta/ # Code location 1
16+
│ │ ├── pyproject.toml
17+
│ │ ├── tests/
18+
│ │ └── src/databricks_delta/
19+
│ │ ├── definitions.py
20+
│ │ └── defs/
21+
│ │ ├── components/lakehouse/
22+
│ │ └── resources.py
23+
│ └── snowflake-medallion/ # Code location 2
24+
│ ├── pyproject.toml
25+
│ ├── tests/
26+
│ └── src/snowflake_medallion/
27+
│ ├── definitions.py
28+
│ ├── dbt_project/
29+
│ └── defs/
30+
│ ├── components/medallion/
31+
│ └── resources.py
32+
├── .env.example
33+
├── pyproject.toml
34+
└── README.md
35+
```
36+
37+
## Getting Started
38+
39+
### Prerequisites
40+
41+
- Python 3.10+
42+
- [uv](https://github.com/astral-sh/uv) package manager
43+
44+
### Installation
45+
46+
1. Set up the local deployment environment:
47+
48+
```bash
49+
cd deployments/local
50+
uv sync
51+
source .venv/bin/activate
52+
```
53+
54+
2. Set up each project environment:
55+
56+
```bash
57+
cd ../../projects/databricks-delta
58+
uv sync
59+
60+
cd ../snowflake-medallion
61+
uv sync
62+
```
63+
64+
3. Copy the environment file and configure credentials:
65+
66+
```bash
67+
cp .env.example .env
68+
# Edit .env with your credentials
69+
```
70+
71+
### Running the Workspace
72+
73+
From the workspace root with the local environment activated:
74+
75+
```bash
76+
cd /path/to/project_databricks_and_snowflake
77+
source deployments/local/.venv/bin/activate
78+
dg dev
79+
```
80+
81+
This starts the Dagster webserver at `http://localhost:3000` and loads both code locations.
82+
83+
## Code Locations (Projects)
84+
85+
### 1. Databricks Delta
86+
87+
**Pattern**: Lakehouse with Medallion Architecture
88+
**Storage**: Delta Lake tables
89+
**Technology**: Databricks, Delta Lake
90+
91+
Implements the medallion architecture with:
92+
93+
- **Bronze Layer**: Raw sensor data loaded to Delta tables
94+
- **Silver Layer**: Cleaned and validated sensor data
95+
- **Gold Layer**: Aggregated sensor summaries
96+
97+
### 2. Snowflake Medallion
98+
99+
**Pattern**: ELT with Medallion Architecture
100+
**Storage**: Snowflake tables
101+
**Technology**: Snowflake, dbt, SQL transformations
102+
103+
Implements the medallion architecture with:
104+
105+
- **Bronze Layer**: Raw customer data loaded from sources
106+
- **Silver Layer**: Cleaned and validated customer data (dbt models)
107+
- **Gold Layer**: Curated customer summaries (dbt models)
108+
109+
## Demo Mode
110+
111+
Both projects support demo mode for local development without external dependencies:
112+
113+
- **Databricks Delta**: Uses local file system instead of Databricks
114+
- **Snowflake Medallion**: Uses DuckDB adapter instead of Snowflake
115+
116+
Demo mode is automatically enabled when environment variables are not set.
117+
118+
## Environment Variables
119+
120+
### Databricks Configuration
121+
122+
```bash
123+
DATABRICKS_SERVER_HOSTNAME=your-workspace.cloud.databricks.com
124+
DATABRICKS_HTTP_PATH=/sql/1.0/warehouses/your-warehouse-id
125+
DATABRICKS_TOKEN=dapi_your_token_here
126+
DELTA_STORAGE_PATH=data/delta
127+
```
128+
129+
### Snowflake Configuration
130+
131+
```bash
132+
SNOWFLAKE_ACCOUNT=your-account.region
133+
SNOWFLAKE_USER=your_user
134+
SNOWFLAKE_PASSWORD=your_password
135+
SNOWFLAKE_WAREHOUSE=COMPUTE_WH
136+
SNOWFLAKE_DATABASE=your_database
137+
SNOWFLAKE_SCHEMA=PUBLIC
138+
```
139+
140+
## Running Tests
141+
142+
Each project has its own tests. Run them from within each project directory:
143+
144+
```bash
145+
# Databricks Delta tests
146+
cd projects/databricks-delta
147+
source .venv/bin/activate
148+
pytest tests/ -v
149+
150+
# Snowflake Medallion tests
151+
cd projects/snowflake-medallion
152+
source .venv/bin/activate
153+
pytest tests/ -v
154+
```
155+
156+
## Deploying to Dagster+
157+
158+
This project includes a `dagster_cloud.yaml` file for deploying to Dagster+. The configuration defines both code locations with their respective environment variables and secrets.
159+
160+
### Setup
161+
162+
1. Configure environment variables in Dagster+:
163+
- Add non-sensitive variables (account names, hostnames) as environment variables
164+
- Add sensitive values (tokens, passwords) as secrets
165+
166+
2. Deploy using the Dagster+ CLI or GitHub integration:
167+
168+
```bash
169+
dagster-cloud workspace sync
170+
```
171+
172+
For more details, see the [Dagster+ deployment documentation](https://docs.dagster.io/dagster-plus/deployment/code-locations/dagster-cloud-yaml).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Dagster+ deployment configuration
2+
# See: https://docs.dagster.io/dagster-plus/deployment/code-locations/dagster-cloud-yaml
3+
4+
locations:
5+
- location_name: databricks-delta
6+
code_source:
7+
package_name: databricks_delta
8+
build:
9+
directory: ./projects/databricks-delta
10+
container_context:
11+
k8s:
12+
env_vars:
13+
- DATABRICKS_SERVER_HOSTNAME
14+
- DATABRICKS_HTTP_PATH
15+
- DELTA_STORAGE_PATH
16+
env_secrets:
17+
- DATABRICKS_TOKEN
18+
19+
- location_name: snowflake-medallion
20+
code_source:
21+
package_name: snowflake_medallion
22+
build:
23+
directory: ./projects/snowflake-medallion
24+
container_context:
25+
k8s:
26+
env_vars:
27+
- SNOWFLAKE_ACCOUNT
28+
- SNOWFLAKE_USER
29+
- SNOWFLAKE_WAREHOUSE
30+
- SNOWFLAKE_DATABASE
31+
- SNOWFLAKE_SCHEMA
32+
env_secrets:
33+
- SNOWFLAKE_PASSWORD
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "multi-platform-data-local"
3+
requires-python = ">=3.10,<3.14"
4+
version = "0.1.0"
5+
dependencies = [
6+
"dagster>=1.9.0",
7+
"dagster-webserver>=1.9.0",
8+
"dagster-dg-cli>=1.0.0",
9+
]
10+
11+
[tool.hatch.build.targets.wheel]
12+
only-include = []

0 commit comments

Comments
 (0)