You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
knowledge_base: apply review feedback to metric_view examples
Apply Julia's PR #156 inline suggestions (and parallel changes for the
metric_view_dbt variant) plus a few related cleanups surfaced by a
clean-context review:
- Drop the dbt-variant cross-link from metric_view/README.md (don't
advertise dbt from the canonical example). Keep the inverse link.
- Drop the `workspace:` block (and prod root_path / permissions
placeholders) from both databricks.yml — let the user's profile pin
the host.
- Tighten databricks.yml comments: drop the dbt-PR/version reference,
drop "Bundles do not yet support" staleness risk.
- Periods on variable descriptions.
- README structure: drop redundant subheaders, `## Get started` (not
"Getting Started With This Project"), `## Learn more` (sentence case),
`### Notes` instead of `## Advanced Topics`.
- Snippet matches query (no undefined fields), placeholder consistency
(<catalog>.<your_schema>, no main.<your_schema> mix-up).
- Drop `aws/en/` from doc URLs (also in dbt model file).
- "Once registered" instead of "Once deployed" — accurate, matches
Julia's suggestion.
- Unify prod schema across variants (dbt prod schema was `default`,
SQL was `prod` — now both `prod`).
- Drop redundant "view integrates seamlessly with..." marketing line.
- Individual code blocks per command for easy copy-paste.
Co-authored-by: Isaac
Copy file name to clipboardExpand all lines: knowledge_base/metric_view/README.md
+16-22Lines changed: 16 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,6 @@
1
1
# Unity Catalog Metric View
2
2
3
-
This project demonstrates how to create a [Unity Catalog Metric View](https://docs.databricks.com/aws/en/metric-views/) using Declarative Automation Bundles. Once registered, the metric view becomes available to analysts and BI tools across your workspace, queryable via the `MEASURE()` SQL function.
4
-
5
-
6
-
## Concrete example: Definition and Usage
3
+
This project demonstrates how to create a [Unity Catalog Metric View](https://docs.databricks.com/metric-views/) using Declarative Automation Bundles. Once registered, the metric view becomes available to analysts and BI tools across your workspace, queryable via the `MEASURE()` SQL function.
7
4
8
5
## `bookings_kpis` metric view
9
6
@@ -32,29 +29,19 @@ $$;
32
29
33
30
`{{catalog}}` and `{{schema}}` in the SQL file are substituted from job parameters at run time.
34
31
35
-
### SQL Usage
36
-
37
32
Once registered, query the metric view from any SQL editor:
38
33
39
34
```sql
40
35
SELECT
41
36
check_in_month,
42
-
MEASURE(total_bookings) AS bookings,
43
-
MEASURE(total_revenue) AS revenue,
44
-
MEASURE(avg_booking_value) AS aov
45
-
FROM main.<your_schema>.bookings_kpis
46
-
WHERE check_in_date >='2024-01-01'
37
+
MEASURE(total_bookings) AS bookings,
38
+
MEASURE(total_revenue) AS revenue
39
+
FROM<catalog>.<your_schema>.bookings_kpis
47
40
GROUP BY check_in_month
48
41
ORDER BY check_in_month;
49
42
```
50
43
51
-
The view integrates seamlessly with:
52
-
53
-
- SQL editors and notebooks
54
-
- Databricks SQL dashboards / AI/BI Genie
55
-
- Any BI tool that connects to your workspace
56
-
57
-
## Getting Started With This Project
44
+
## Get started
58
45
59
46
### Prerequisites
60
47
@@ -64,20 +51,28 @@ The view integrates seamlessly with:
64
51
65
52
### Setup
66
53
67
-
1. In `databricks.yml`, replace `https://company.databricks.com` with your workspace URL, and replace `<your-warehouse-id>` with one of your warehouse IDs (`databricks warehouses list`).
68
-
2. If you don't have write access to `main`, change `catalog:` under `targets.dev.variables` to a catalog you can write to.
54
+
1. In `databricks.yml`, replace `<your-warehouse-id>` (in both `targets.dev`and `targets.prod`) with one of your warehouse IDs (`databricks warehouses list`).
55
+
2. If you don't have write access to `main`, change `catalog:` under `variables` to a catalog you can write to.
69
56
70
57
### Deployment
71
58
72
59
Deploy to dev:
60
+
73
61
```bash
74
62
databricks bundle deploy --target dev
63
+
```
64
+
65
+
```bash
75
66
databricks bundle run bookings_kpis_metric_view --target dev
76
67
```
77
68
78
69
Deploy to production:
70
+
79
71
```bash
80
72
databricks bundle deploy --target prod
73
+
```
74
+
75
+
```bash
81
76
databricks bundle run bookings_kpis_metric_view --target prod
82
77
```
83
78
@@ -86,10 +81,9 @@ The metric view will be created at `<catalog>.<your_username>.bookings_kpis` (de
86
81
### Notes
87
82
88
83
- The job has a daily `periodic` trigger so the view definition is re-applied in production. [Development-mode](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html) pauses the trigger automatically, so it only fires after `bundle deploy --target prod`.
89
-
90
84
- Set `source:` in the YAML body to any UC table you read from. The sample `samples.wanderbricks.bookings` is convenient for getting started. For production, use a table from your own pipeline.
91
85
92
-
## Learn More
86
+
## Learn more
93
87
94
88
-[Unity Catalog Metric Views](https://docs.databricks.com/metric-views/) — Official documentation
Copy file name to clipboardExpand all lines: knowledge_base/metric_view_dbt/README.md
+24-32Lines changed: 24 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,13 @@
1
1
# Unity Catalog Metric View using dbt
2
2
3
-
This project demonstrates how to materialize a [Unity Catalog Metric View](https://docs.databricks.com/metric-views/) via dbt-databricks using Declarative Automation Bundles. The metric view is defined as a dbt model with the [`metric_view` materialization](https://github.com/databricks/dbt-databricks/pull/1285) added in **dbt-databricks 1.12.0**.
3
+
This project demonstrates how to materialize a [Unity Catalog Metric View](https://docs.databricks.com/metric-views/) via dbt-databricks using Declarative Automation Bundles. The metric view is defined as a dbt model with the [`metric_view` materialization](https://github.com/databricks/dbt-databricks/pull/1285) added in dbt-databricks 1.12.0.
For the SQL-job variant, see [`../metric_view`](../metric_view).
6
6
7
-
## Concrete example: Definition and Usage
7
+
## `bookings_kpis` metric view
8
8
9
9
This project defines `bookings_kpis`, a metric view over the public sample dataset `samples.wanderbricks.bookings`.
10
10
11
-
### Metric View Definition (dbt model)
12
-
13
11
The model lives in [`src/models/bookings_kpis.sql`](src/models/bookings_kpis.sql):
14
12
15
13
```sql
@@ -30,68 +28,62 @@ measures:
30
28
31
29
The `{{ config(materialized='metric_view') }}` line is the only jinja; everything below it is the metric view YAML body. dbt-databricks issues the equivalent `CREATE OR REPLACE VIEW … WITH METRICS LANGUAGE YAML` against the warehouse at `dbt run` time.
32
30
33
-
### SQL Usage
34
-
35
31
Once materialized, query the metric view from any SQL editor:
36
32
37
33
```sql
38
34
SELECT
39
35
check_in_month,
40
-
MEASURE(total_bookings) AS bookings,
41
-
MEASURE(total_revenue) AS revenue,
42
-
MEASURE(avg_booking_value) AS aov
43
-
FROM main.<your_schema>.bookings_kpis
44
-
WHERE check_in_date >='2024-01-01'
36
+
MEASURE(total_bookings) AS bookings,
37
+
MEASURE(total_revenue) AS revenue
38
+
FROM<catalog>.<your_schema>.bookings_kpis
45
39
GROUP BY check_in_month
46
40
ORDER BY check_in_month;
47
41
```
48
42
49
-
The view integrates seamlessly with:
50
-
51
-
- SQL editors and notebooks
52
-
- Databricks SQL dashboards / AI/BI Genie
53
-
- Any BI tool that connects to your workspace
54
-
55
-
## Getting Started With This Project
43
+
## Get started
56
44
57
45
### Prerequisites
58
46
59
47
* Databricks workspace with Unity Catalog enabled
60
-
* A SQL warehouse on a runtime that supports Unity Catalog metric views (Public Preview; any recent serverless or PRO warehouse)
48
+
* A SQL warehouse on a runtime that supports Unity Catalog metric views
61
49
* Databricks CLI installed and configured
62
50
63
51
### Setup
64
52
65
-
1. In `databricks.yml`, replace `https://company.databricks.com` with your workspace URL.
66
-
2. In `dbt_profiles/profiles.yml`, set `http_path` to one of your warehouses (`databricks warehouses list`) and update `catalog` to one you can write to (the default `main` is often not writable).
53
+
1. In `dbt_profiles/profiles.yml`, set `http_path` (in both `dev` and `prod`) to one of your warehouses (`databricks warehouses list`) and update `catalog` to one you can write to (the default `main` is often not writable).
67
54
68
55
### Deployment
69
56
70
57
Deploy to dev:
58
+
71
59
```bash
72
60
databricks bundle deploy --target dev
61
+
```
62
+
63
+
```bash
73
64
databricks bundle run metric_view_dbt_job --target dev
74
65
```
75
66
76
67
Deploy to production:
68
+
77
69
```bash
78
70
databricks bundle deploy --target prod
79
-
databricks bundle run metric_view_dbt_job --target prod
80
71
```
81
72
82
-
The metric view will be created at `<catalog>.<your_username>.bookings_kpis` (dev) or `<catalog>.default.bookings_kpis` (prod).
83
-
84
-
## Advanced Topics
85
-
86
-
**Scheduling:** The job has a daily `periodic` trigger so `dbt run` re-applies the view definition in production. [Development-mode](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html) deploys pause the trigger automatically, so it only fires after `bundle deploy --target prod`.
73
+
```bash
74
+
databricks bundle run metric_view_dbt_job --target prod
75
+
```
87
76
88
-
**dbt-databricks version:** Requires `dbt-databricks >= 1.12.0` (the `metric_view` materialization). The job pins this in its task environment (`resources/metric_view_dbt.job.yml`).
77
+
The metric view will be created at `<catalog>.<your_username>.bookings_kpis` (dev) or `<catalog>.prod.bookings_kpis` (prod).
89
78
90
-
**File extension:** The model file is `.sql` even though its body is YAML — dbt model files must use `.sql`. dbt-databricks wraps the body in `CREATE OR REPLACE VIEW … LANGUAGE YAML AS $$ … $$` at run time.
79
+
### Notes
91
80
92
-
**Custom source table:** Point `source:` in the YAML body at any UC table you read from. For production, replace the public `samples.wanderbricks.bookings` with a curated table from your own pipeline.
81
+
- The job has a daily `periodic` trigger so `dbt run` re-applies the view definition in production. [Development-mode](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html) pauses the trigger automatically, so it only fires after `bundle deploy --target prod`.
82
+
- Requires `dbt-databricks >= 1.12.0` (the version that introduced the `metric_view` materialization). The job pins this in its task environment.
83
+
- The model file is `.sql` even though its body is YAML — dbt model files must use `.sql`. dbt-databricks wraps the body in `CREATE OR REPLACE VIEW … LANGUAGE YAML AS $$ … $$` at run time.
84
+
- Set `source:` in the YAML body to any UC table you read from. For production, replace `samples.wanderbricks.bookings` with a table from your own pipeline.
93
85
94
-
## Learn More
86
+
## Learn more
95
87
96
88
-[Unity Catalog Metric Views](https://docs.databricks.com/metric-views/) — Official documentation
0 commit comments