diff --git a/.test/skills/databricks-metric-views/ground_truth.yaml b/.test/skills/databricks-metric-views/ground_truth.yaml index 720f0da6..ad7b1a1f 100644 --- a/.test/skills/databricks-metric-views/ground_truth.yaml +++ b/.test/skills/databricks-metric-views/ground_truth.yaml @@ -10,7 +10,7 @@ test_cases: outputs: response: "Here's a metric view for order analytics:\n\n```sql\nCREATE OR REPLACE\ \ VIEW catalog.schema.orders_metrics\nWITH METRICS\nLANGUAGE YAML\nAS $$\n \ - \ version: 1.1\n comment: \"Orders KPIs for sales analysis\"\n source: catalog.schema.orders\n\ + \ version: 1.1\n source: catalog.schema.orders\n comment: \"Orders KPIs for sales analysis\"\n\ \ filter: order_date > '2020-01-01'\n dimensions:\n - name: Order Month\n\ \ expr: DATE_TRUNC('MONTH', order_date)\n comment: \"Month of order\"\ \n - name: Order Status\n expr: CASE\n WHEN status = 'O' THEN\ @@ -179,8 +179,8 @@ test_cases: prompt: Show me the full YAML specification for a metric view definition outputs: response: "```yaml\nversion: 1.1 # Required: \"1.1\" for DBR\ - \ 17.2+\ncomment: \"Description\" # Optional\nsource: catalog.schema.table\ - \ # Required: source table/view\nfilter: column > value # Optional:\ + \ 17.2+\nsource: catalog.schema.table # Required: source table/view\ncomment:\ + \ \"Description\" # Optional: metric view description\nfilter: column > value # Optional:\ \ global WHERE filter\n\ndimensions: # Required: at least\ \ one\n - name: Display Name\n expr: sql_expression\n comment: \"Description\"\ \n\nmeasures: # Required: at least one\n - name: Display\ @@ -825,8 +825,8 @@ test_cases: LANGUAGE YAML AS $$ version: 1.1 - comment: "Customer support ticket KPIs" source: catalog.schema.support_tickets + comment: "Customer support ticket KPIs" filter: created_at >= '2024-01-01' dimensions: @@ -1058,8 +1058,8 @@ test_cases: LANGUAGE YAML AS $$ version: 1.1 - comment: "Transaction metrics - migrated from standard view" source: catalog.schema.transactions + comment: "Transaction metrics - migrated from standard view" dimensions: - name: Region @@ -1226,8 +1226,8 @@ test_cases: LANGUAGE YAML AS $$ version: 1.1 - comment: "Product usage KPIs: DAU and feature adoption" source: catalog.schema.product_usage + comment: "Product usage KPIs: DAU and feature adoption" dimensions: - name: Date diff --git a/databricks-skills/databricks-metric-views/SKILL.md b/databricks-skills/databricks-metric-views/SKILL.md index bddc74ad..3cc4b427 100644 --- a/databricks-skills/databricks-metric-views/SKILL.md +++ b/databricks-skills/databricks-metric-views/SKILL.md @@ -46,8 +46,8 @@ WITH METRICS LANGUAGE YAML AS $$ version: 1.1 - comment: "Orders KPIs for sales analysis" source: catalog.schema.orders + comment: "Orders KPIs for sales analysis" filter: order_date > '2020-01-01' dimensions: - name: Order Month @@ -167,8 +167,8 @@ manage_metric_views( ```yaml version: 1.1 # Required: "1.1" for DBR 17.2+ -comment: "Description" # Optional: metric view description source: catalog.schema.table # Required: source table/view +comment: "Description" # Optional: metric view description filter: column > value # Optional: global WHERE filter dimensions: # Required: at least one diff --git a/databricks-skills/databricks-metric-views/patterns.md b/databricks-skills/databricks-metric-views/patterns.md index 48c7f9e3..1f067f4c 100644 --- a/databricks-skills/databricks-metric-views/patterns.md +++ b/databricks-skills/databricks-metric-views/patterns.md @@ -14,8 +14,8 @@ WITH METRICS LANGUAGE YAML AS $$ version: 1.1 - comment: "Product sales metrics" source: catalog.schema.sales + comment: "Product sales metrics" dimensions: - name: Product Name expr: product_name @@ -98,8 +98,8 @@ WITH METRICS LANGUAGE YAML AS $$ version: 1.1 - comment: "Efficiency and per-unit metrics" source: catalog.schema.transactions + comment: "Efficiency and per-unit metrics" dimensions: - name: Department expr: department_name @@ -176,8 +176,8 @@ WITH METRICS LANGUAGE YAML AS $$ version: 1.1 - comment: "Sales analytics with customer and product dimensions" source: catalog.schema.fact_sales + comment: "Sales analytics with customer and product dimensions" joins: - name: customer @@ -329,8 +329,8 @@ WITH METRICS LANGUAGE YAML AS $$ version: 1.1 - comment: "TPC-H Orders KPIs - demo metric view" source: samples.tpch.orders + comment: "TPC-H Orders KPIs - demo metric view" filter: o_orderdate > '1990-01-01' dimensions: diff --git a/databricks-tools-core/databricks_tools_core/unity_catalog/metric_views.py b/databricks-tools-core/databricks_tools_core/unity_catalog/metric_views.py index 42238828..60f3e056 100644 --- a/databricks-tools-core/databricks_tools_core/unity_catalog/metric_views.py +++ b/databricks-tools-core/databricks_tools_core/unity_catalog/metric_views.py @@ -44,11 +44,11 @@ def _build_yaml_block( """ lines = [f"version: {version}"] + lines.append(f"source: {source}") + if comment: lines.append(f'comment: "{comment}"') - lines.append(f"source: {source}") - if filter_expr: lines.append(f"filter: {filter_expr}")