|
| 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). |
0 commit comments