From 1b5dc0c82ce1b4599463b8a4333dbb8b78e49958 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 6 May 2024 09:34:20 -0500 Subject: [PATCH 1/5] update schema with if else for type params --- schemas/latest/dbt_yml_files-latest.json | 162 ++++++++++++++++++----- tests/latest/valid/dbt_yml_files.yml | 24 +++- 2 files changed, 149 insertions(+), 37 deletions(-) diff --git a/schemas/latest/dbt_yml_files-latest.json b/schemas/latest/dbt_yml_files-latest.json index 664c74a..8d7b437 100644 --- a/schemas/latest/dbt_yml_files-latest.json +++ b/schemas/latest/dbt_yml_files-latest.json @@ -229,10 +229,12 @@ "RATIO", "CUMULATIVE", "DERIVED", + "CONVERSION", "simple", "ratio", "cumulative", - "derived" + "derived", + "conversion" ] }, "filter": { @@ -245,7 +247,64 @@ "type": "string" }, "type_params": { - "$ref": "#/$defs/metric_type_params" + "if": { + "properties": { + "type": { + "enum": ["SIMPLE", "simple"] + } + } + }, + "then": { + "$ref": "#/$defs/simple_metric_type_params" + }, + "else": { + "if": { + "properties": { + "type": { + "enum": ["derived", "DERIVED"] + } + } + }, + "then": { + "$ref": "#/$defs/derived_metric_type_params" + }, + "else": { + "if": { + "properties": { + "type": { + "enum": ["cumulative", "CUMULATIVE"] + } + } + }, + "then": { + "$ref": "#/$defs/cumulative_metric_type_params" + }, + "else": { + "if": { + "properties": { + "type": { + "enum": ["conversion", "CONVERSION"] + } + } + }, + "then": { + "$ref": "#/$defs/conversion_metric_type_params" + }, + "else": { + "if": { + "properties": { + "type": { + "enum": ["ratio", "RATIO"] + } + } + }, + "then": { + "$ref": "#/$defs/ratio_metric_type_params" + } + } + } + } + } } }, "additionalProperties": false @@ -1218,9 +1277,6 @@ "string", "boolean" ] - }, - "role": { - "type": "string" } }, "additionalProperties": false @@ -1338,7 +1394,7 @@ "SUM", "MIN", "MAX", - "AVERAGE", + "AVG", "COUNT_DISTINCT", "SUM_BOOLEAN", "COUNT", @@ -1347,7 +1403,7 @@ "sum", "min", "max", - "average", + "avg", "count_distinct", "sum_boolean", "count", @@ -1375,6 +1431,9 @@ "boolean" ] }, + "label": { + "type": "string" + }, "non_additive_dimension": { "$ref": "#/$defs/non_additive_dimension" } @@ -1382,26 +1441,22 @@ "additionalProperties": false }, "metric_input_measure": { - "oneOf": [ - { + "type": "object", + "properties": { + "name": { "type": "string" }, - { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "alias": { - "type": "string" - }, - "filter": { - "type": "string" - } - }, - "additionalProperties": false + "fill_nulls_with": { + "type": ["string", "integer"] + }, + "filter": { + "type": "string" + }, + "join_to_timespine": { + "type": "boolean" } - ] + }, + "additionalProperties": false }, "metric_input_schema": { "type": "object", @@ -1415,30 +1470,69 @@ "filter": { "type": "string" }, - "offset_to_grain": { - "type": "string" - }, "offset_window": { "type": "string" } }, "additionalProperties": false }, - "metric_type_params": { + "simple_metric_type_params": { "type": "object", "properties": { - "denominator": { + "measure": { "$ref": "#/$defs/metric_input_measure" - }, + } + }, + "additionalProperties": false + }, + "derived_metric_type_params": { + "type": "object", + "properties": { "expr": { - "type": [ - "string", - "boolean" - ] + "$ref": "string" + }, + "metrics": { + "type": "array", + "items": { + "$ref": "#/$defs/metric_input_schema" + } + } + }, + "additionalProperties": false + }, + "cumulative_metric_type_params": { + "type": "object", + "properties": { + "measure": { + "$ref": "#/$defs/metric_input_measure" }, "grain_to_date": { + "enum": ["day", "week", "month", "quarter", "year"] + }, + "window": { + "type": "string" + } + }, + "additionalProperties": false + }, + "ratio_metric_type_params": { + "type": "object", + "properties": { + "filter": { "type": "string" }, + "numerator": { + "$ref": "#/$defs/metric_input_schema" + }, + "denominator": { + "$ref": "#/$defs/metric_input_schema" + } + }, + "additionalProperties": false + }, + "conversion_metric_type_params": { + "type": "object", + "properties": { "measure": { "$ref": "#/$defs/metric_input_measure" }, diff --git a/tests/latest/valid/dbt_yml_files.yml b/tests/latest/valid/dbt_yml_files.yml index bedadc1..c49027f 100644 --- a/tests/latest/valid/dbt_yml_files.yml +++ b/tests/latest/valid/dbt_yml_files.yml @@ -181,12 +181,30 @@ metrics: type: simple label: Customers w/ Orders type_params: - measure: customers_with_orders + measure: + name: customers_with_orders + fill_nulls_with: 0 + join_to_timespine: true - name: new_customer description: Unique count of new customers. label: New Customers type: simple type_params: - measure: customers_with_orders + measure: + name: customers_with_orders filter: | - {{ Dimension('customer__customer_type') }} = 'new' \ No newline at end of file + {{ Dimension('customer__customer_type') }} = 'new' + + - name: average_transaction_total_us + description: "The average total for each transaction in the US" + label: Transaction Total Average US + type: ratio + type_params: + numerator: + name: transaction_total + filter: | + "{{ Dimension('transaction__location') }} = 'US'" + denominator: + name: transactions + filter: | + "{{ Dimension('transaction__location') }} = 'US'" \ No newline at end of file From b5b72df89405f26bf7019a3313efdbe6b9f62092 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 6 May 2024 09:57:29 -0500 Subject: [PATCH 2/5] update placement of if else --- schemas/latest/dbt_yml_files-latest.json | 141 +++++++++++++---------- 1 file changed, 83 insertions(+), 58 deletions(-) diff --git a/schemas/latest/dbt_yml_files-latest.json b/schemas/latest/dbt_yml_files-latest.json index 8d7b437..ac398dc 100644 --- a/schemas/latest/dbt_yml_files-latest.json +++ b/schemas/latest/dbt_yml_files-latest.json @@ -215,90 +215,76 @@ "type", "type_params" ], - "properties": { - "name": { - "type": "string", - "pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$" - }, - "description": { - "type": "string" - }, - "type": { - "enum": [ - "SIMPLE", - "RATIO", - "CUMULATIVE", - "DERIVED", - "CONVERSION", - "simple", - "ratio", - "cumulative", - "derived", - "conversion" - ] - }, - "filter": { - "type": "string" - }, - "group": { - "$ref": "#/$defs/group" + "if": { + "properties": { + "type": { + "enum": ["SIMPLE", "simple"] + } + } + }, + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/simple_metric_type_params" + } + } + }, + "else": { + "if": { + "properties": { + "type": { + "enum": ["derived", "DERIVED"] + } + } }, - "label": { - "type": "string" + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/derived_metric_type_params" + } + } }, - "type_params": { + "else": { "if": { "properties": { "type": { - "enum": ["SIMPLE", "simple"] + "enum": ["cumulative", "CUMULATIVE"] } } }, "then": { - "$ref": "#/$defs/simple_metric_type_params" + "properties": { + "type_params": { + "$ref": "#/$defs/cumulative_metric_type_params" + } + } }, "else": { "if": { "properties": { "type": { - "enum": ["derived", "DERIVED"] + "enum": ["conversion", "CONVERSION"] } } }, "then": { - "$ref": "#/$defs/derived_metric_type_params" + "properties": { + "type_params": { + "$ref": "#/$defs/conversion_metric_type_params" + } + } }, "else": { "if": { "properties": { "type": { - "enum": ["cumulative", "CUMULATIVE"] + "enum": ["ratio", "RATIO"] } } }, "then": { - "$ref": "#/$defs/cumulative_metric_type_params" - }, - "else": { - "if": { - "properties": { - "type": { - "enum": ["conversion", "CONVERSION"] - } - } - }, - "then": { - "$ref": "#/$defs/conversion_metric_type_params" - }, - "else": { - "if": { - "properties": { - "type": { - "enum": ["ratio", "RATIO"] - } - } - }, - "then": { + "properties": { + "type_params": { "$ref": "#/$defs/ratio_metric_type_params" } } @@ -307,6 +293,38 @@ } } }, + "properties": { + "name": { + "type": "string", + "pattern": "(?!.*__).*^[a-z][a-z0-9_]*[a-z0-9]$" + }, + "description": { + "type": "string" + }, + "type": { + "enum": [ + "SIMPLE", + "RATIO", + "CUMULATIVE", + "DERIVED", + "CONVERSION", + "simple", + "ratio", + "cumulative", + "derived", + "conversion" + ] + }, + "filter": { + "type": "string" + }, + "group": { + "$ref": "#/$defs/group" + }, + "label": { + "type": "string" + } + }, "additionalProperties": false } }, @@ -1447,7 +1465,14 @@ "type": "string" }, "fill_nulls_with": { - "type": ["string", "integer"] + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] }, "filter": { "type": "string" From 006c07137846db5509d1120773f6697610e2ebd3 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 6 May 2024 10:03:21 -0500 Subject: [PATCH 3/5] fix string reference --- schemas/latest/dbt_yml_files-latest.json | 230 +++++------------------ 1 file changed, 47 insertions(+), 183 deletions(-) diff --git a/schemas/latest/dbt_yml_files-latest.json b/schemas/latest/dbt_yml_files-latest.json index ac398dc..f82686f 100644 --- a/schemas/latest/dbt_yml_files-latest.json +++ b/schemas/latest/dbt_yml_files-latest.json @@ -11,9 +11,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -25,9 +23,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -64,12 +60,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "depends_on", - "name", - "owner", - "type" - ], + "required": ["depends_on", "name", "owner", "type"], "$comment": "NB: depends_on is not strictly required, but is _expected_ according to the documentation", "properties": { "name": { @@ -80,13 +71,7 @@ }, "type": { "type": "string", - "enum": [ - "dashboard", - "notebook", - "analysis", - "ml", - "application" - ] + "enum": ["dashboard", "notebook", "analysis", "ml", "application"] }, "depends_on": { "type": "array", @@ -100,21 +85,14 @@ }, "maturity": { "type": "string", - "enum": [ - "high", - "medium", - "low" - ] + "enum": ["high", "medium", "low"] }, "meta": { "type": "object" }, "owner": { "type": "object", - "anyOf": [ - {"required": ["email"]}, - {"required": ["name"]} - ], + "anyOf": [{ "required": ["email"] }, { "required": ["name"] }], "properties": { "name": { "type": "string" @@ -138,10 +116,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name", - "owner" - ], + "required": ["name", "owner"], "properties": { "name": { "type": "string" @@ -167,9 +142,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -181,9 +154,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -209,12 +180,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name", - "label", - "type", - "type_params" - ], + "required": ["name", "label", "type", "type_params"], "if": { "properties": { "type": { @@ -332,9 +298,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -344,11 +308,7 @@ }, "access": { "type": "string", - "enum": [ - "private", - "protected", - "public" - ] + "enum": ["private", "protected", "public"] }, "columns": { "type": "array", @@ -390,9 +350,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "v" - ], + "required": ["v"], "properties": { "columns": { "type": "array", @@ -424,9 +382,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -492,10 +448,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name", - "model" - ], + "required": ["name", "model"], "properties": { "name": { "type": "string", @@ -546,9 +499,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -638,9 +589,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "description": "How you will identify the schema in {{ source() }} calls. Unless `schema` is also set, this will be the name of the schema in the database.", @@ -701,9 +650,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "title": "Name", @@ -784,11 +731,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "name", - "model", - "expect" - ], + "required": ["name", "model", "expect"], "properties": { "name": { "type": "string" @@ -844,10 +787,7 @@ "format": { "description": "Defaults to `dict` when not specified", "type": "string", - "enum": [ - "dict", - "csv" - ] + "enum": ["dict", "csv"] }, "additionalProperties": false } @@ -890,10 +830,7 @@ "format": { "description": "Defaults to `dict` when not specified", "type": "string", - "enum": [ - "dict", - "csv" - ] + "enum": ["dict", "csv"] }, "input": { "description": "The relation whose inputs you need to mock. Enclose in ref or source without curly braces", @@ -911,9 +848,7 @@ "model": { "description": "The name of the model whose behaviour you are testing. Does not need to be wrapped in a ref.", "type": "string", - "examples": [ - "my_model" - ] + "examples": ["my_model"] }, "overrides": { "type": "object", @@ -977,9 +912,7 @@ }, "column_properties": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "uniqueItems": true, "properties": { "name": { @@ -1030,9 +963,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "type" - ], + "required": ["type"], "properties": { "name": { "type": "string" @@ -1066,10 +997,7 @@ "properties": { "relationships": { "type": "object", - "required": [ - "to", - "field" - ], + "required": ["to", "field"], "properties": { "name": { "type": "string" @@ -1104,9 +1032,7 @@ "properties": { "accepted_values": { "type": "object", - "required": [ - "values" - ], + "required": ["values"], "properties": { "name": { "type": "string" @@ -1174,10 +1100,7 @@ }, "dimension": { "type": "object", - "required": [ - "name", - "type" - ], + "required": ["name", "type"], "anyOf": [ { "not": { @@ -1185,9 +1108,7 @@ } }, { - "required": [ - "type_params" - ] + "required": ["type_params"] } ], "properties": { @@ -1199,18 +1120,10 @@ "type": "string" }, "type": { - "enum": [ - "CATEGORICAL", - "TIME", - "categorical", - "time" - ] + "enum": ["CATEGORICAL", "TIME", "categorical", "time"] }, "expr": { - "type": [ - "string", - "boolean" - ] + "type": ["string", "boolean"] }, "is_partition": { "type": "boolean" @@ -1223,9 +1136,7 @@ }, "dimension_type_params": { "type": "object", - "required": [ - "time_granularity" - ], + "required": ["time_granularity"], "properties": { "time_granularity": { "enum": [ @@ -1266,10 +1177,7 @@ }, "entity": { "type": "object", - "required": [ - "name", - "type" - ], + "required": ["name", "type"], "properties": { "name": { "type": "string", @@ -1291,10 +1199,7 @@ "type": "string" }, "expr": { - "type": [ - "string", - "boolean" - ] + "type": ["string", "boolean"] } }, "additionalProperties": false @@ -1333,21 +1238,14 @@ }, "freshness_rules": { "type": "object", - "required": [ - "count", - "period" - ], + "required": ["count", "period"], "properties": { "count": { "$ref": "#/$defs/number_or_jinja_string" }, "period": { "type": "string", - "enum": [ - "minute", - "hour", - "day" - ] + "enum": ["minute", "hour", "day"] } }, "additionalProperties": false @@ -1377,15 +1275,10 @@ } }, "is-time-dimension": { - "required": [ - "type" - ], + "required": ["type"], "properties": { "type": { - "enum": [ - "TIME", - "time" - ] + "enum": ["TIME", "time"] } } }, @@ -1395,10 +1288,7 @@ }, "measure": { "type": "object", - "required": [ - "name", - "agg" - ], + "required": ["name", "agg"], "properties": { "name": { "type": "string", @@ -1443,11 +1333,7 @@ "type": "string" }, "expr": { - "type": [ - "string", - "integer", - "boolean" - ] + "type": ["string", "integer", "boolean"] }, "label": { "type": "string" @@ -1514,7 +1400,7 @@ "type": "object", "properties": { "expr": { - "$ref": "string" + "type": "string" }, "metrics": { "type": "array", @@ -1602,10 +1488,7 @@ "type": "array", "items": { "type": "object", - "required": [ - "database", - "project" - ], + "required": ["database", "project"], "properties": { "database": { "type": "string" @@ -1649,20 +1532,11 @@ }, "on_configuration_change": { "type": "string", - "enum": [ - "apply", - "continue", - "fail" - ] + "enum": ["apply", "continue", "fail"] }, "on_schema_change": { "type": "string", - "enum": [ - "append_new_columns", - "fail", - "ignore", - "sync_all_columns" - ] + "enum": ["append_new_columns", "fail", "ignore", "sync_all_columns"] }, "snowflake_warehouse": { "type": "string" @@ -1678,20 +1552,13 @@ }, "non_additive_dimension": { "type": "object", - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" }, "window_choice": { - "enum": [ - "MIN", - "MAX", - "min", - "max" - ] + "enum": ["MIN", "MAX", "min", "max"] }, "window_groupings": { "type": "array", @@ -1775,10 +1642,7 @@ }, { "type": "string", - "enum": [ - "warn", - "error" - ] + "enum": ["warn", "error"] } ] }, @@ -1806,4 +1670,4 @@ "additionalProperties": false } } -} \ No newline at end of file +} From 6931ae5a06eccb8e7d0ceb76e2da1519801161b3 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Thu, 23 May 2024 14:22:14 -0500 Subject: [PATCH 4/5] linting --- schemas/latest/dbt_yml_files-latest.json | 417 ++++++++++++++++------- 1 file changed, 291 insertions(+), 126 deletions(-) diff --git a/schemas/latest/dbt_yml_files-latest.json b/schemas/latest/dbt_yml_files-latest.json index f82686f..de79f11 100644 --- a/schemas/latest/dbt_yml_files-latest.json +++ b/schemas/latest/dbt_yml_files-latest.json @@ -11,7 +11,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -23,7 +25,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -60,7 +64,12 @@ "type": "array", "items": { "type": "object", - "required": ["depends_on", "name", "owner", "type"], + "required": [ + "depends_on", + "name", + "owner", + "type" + ], "$comment": "NB: depends_on is not strictly required, but is _expected_ according to the documentation", "properties": { "name": { @@ -71,7 +80,13 @@ }, "type": { "type": "string", - "enum": ["dashboard", "notebook", "analysis", "ml", "application"] + "enum": [ + "dashboard", + "notebook", + "analysis", + "ml", + "application" + ] }, "depends_on": { "type": "array", @@ -85,14 +100,29 @@ }, "maturity": { "type": "string", - "enum": ["high", "medium", "low"] + "enum": [ + "high", + "medium", + "low" + ] }, "meta": { "type": "object" }, "owner": { "type": "object", - "anyOf": [{ "required": ["email"] }, { "required": ["name"] }], + "anyOf": [ + { + "required": [ + "email" + ] + }, + { + "required": [ + "name" + ] + } + ], "properties": { "name": { "type": "string" @@ -116,7 +146,10 @@ "type": "array", "items": { "type": "object", - "required": ["name", "owner"], + "required": [ + "name", + "owner" + ], "properties": { "name": { "type": "string" @@ -142,7 +175,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -154,7 +189,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -180,11 +217,19 @@ "type": "array", "items": { "type": "object", - "required": ["name", "label", "type", "type_params"], + "required": [ + "name", + "label", + "type", + "type_params" + ], "if": { "properties": { "type": { - "enum": ["SIMPLE", "simple"] + "enum": [ + "SIMPLE", + "simple" + ] } } }, @@ -199,7 +244,10 @@ "if": { "properties": { "type": { - "enum": ["derived", "DERIVED"] + "enum": [ + "derived", + "DERIVED" + ] } } }, @@ -214,7 +262,10 @@ "if": { "properties": { "type": { - "enum": ["cumulative", "CUMULATIVE"] + "enum": [ + "cumulative", + "CUMULATIVE" + ] } } }, @@ -229,7 +280,10 @@ "if": { "properties": { "type": { - "enum": ["conversion", "CONVERSION"] + "enum": [ + "conversion", + "CONVERSION" + ] } } }, @@ -244,7 +298,10 @@ "if": { "properties": { "type": { - "enum": ["ratio", "RATIO"] + "enum": [ + "ratio", + "RATIO" + ] } } }, @@ -298,7 +355,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -308,7 +367,11 @@ }, "access": { "type": "string", - "enum": ["private", "protected", "public"] + "enum": [ + "private", + "protected", + "public" + ] }, "columns": { "type": "array", @@ -350,7 +413,9 @@ "type": "array", "items": { "type": "object", - "required": ["v"], + "required": [ + "v" + ], "properties": { "columns": { "type": "array", @@ -382,7 +447,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -448,7 +515,10 @@ "type": "array", "items": { "type": "object", - "required": ["name", "model"], + "required": [ + "name", + "model" + ], "properties": { "name": { "type": "string", @@ -499,7 +569,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -589,7 +661,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "description": "How you will identify the schema in {{ source() }} calls. Unless `schema` is also set, this will be the name of the schema in the database.", @@ -650,7 +724,9 @@ "type": "array", "items": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "title": "Name", @@ -731,7 +807,11 @@ "type": "array", "items": { "type": "object", - "required": ["name", "model", "expect"], + "required": [ + "name", + "model", + "expect" + ], "properties": { "name": { "type": "string" @@ -787,7 +867,10 @@ "format": { "description": "Defaults to `dict` when not specified", "type": "string", - "enum": ["dict", "csv"] + "enum": [ + "dict", + "csv" + ] }, "additionalProperties": false } @@ -830,7 +913,10 @@ "format": { "description": "Defaults to `dict` when not specified", "type": "string", - "enum": ["dict", "csv"] + "enum": [ + "dict", + "csv" + ] }, "input": { "description": "The relation whose inputs you need to mock. Enclose in ref or source without curly braces", @@ -848,7 +934,9 @@ "model": { "description": "The name of the model whose behaviour you are testing. Does not need to be wrapped in a ref.", "type": "string", - "examples": ["my_model"] + "examples": [ + "my_model" + ] }, "overrides": { "type": "object", @@ -912,7 +1000,9 @@ }, "column_properties": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "uniqueItems": true, "properties": { "name": { @@ -963,7 +1053,9 @@ "type": "array", "items": { "type": "object", - "required": ["type"], + "required": [ + "type" + ], "properties": { "name": { "type": "string" @@ -986,6 +1078,48 @@ } } }, + "conversion_metric_type_params": { + "type": "object", + "properties": { + "measure": { + "$ref": "#/$defs/metric_input_measure" + }, + "metrics": { + "type": "array", + "items": { + "$ref": "#/$defs/metric_input_schema" + } + }, + "numerator": { + "$ref": "#/$defs/metric_input_measure" + }, + "window": { + "type": "string" + } + }, + "additionalProperties": false + }, + "cumulative_metric_type_params": { + "type": "object", + "properties": { + "grain_to_date": { + "enum": [ + "day", + "week", + "month", + "quarter", + "year" + ] + }, + "measure": { + "$ref": "#/$defs/metric_input_measure" + }, + "window": { + "type": "string" + } + }, + "additionalProperties": false + }, "data_tests": { "anyOf": [ { @@ -997,7 +1131,10 @@ "properties": { "relationships": { "type": "object", - "required": ["to", "field"], + "required": [ + "to", + "field" + ], "properties": { "name": { "type": "string" @@ -1032,7 +1169,9 @@ "properties": { "accepted_values": { "type": "object", - "required": ["values"], + "required": [ + "values" + ], "properties": { "name": { "type": "string" @@ -1098,9 +1237,27 @@ } ] }, + "derived_metric_type_params": { + "type": "object", + "properties": { + "expr": { + "type": "string" + }, + "metrics": { + "type": "array", + "items": { + "$ref": "#/$defs/metric_input_schema" + } + } + }, + "additionalProperties": false + }, "dimension": { "type": "object", - "required": ["name", "type"], + "required": [ + "name", + "type" + ], "anyOf": [ { "not": { @@ -1108,7 +1265,9 @@ } }, { - "required": ["type_params"] + "required": [ + "type_params" + ] } ], "properties": { @@ -1120,10 +1279,18 @@ "type": "string" }, "type": { - "enum": ["CATEGORICAL", "TIME", "categorical", "time"] + "enum": [ + "CATEGORICAL", + "TIME", + "categorical", + "time" + ] }, "expr": { - "type": ["string", "boolean"] + "type": [ + "string", + "boolean" + ] }, "is_partition": { "type": "boolean" @@ -1136,7 +1303,9 @@ }, "dimension_type_params": { "type": "object", - "required": ["time_granularity"], + "required": [ + "time_granularity" + ], "properties": { "time_granularity": { "enum": [ @@ -1177,7 +1346,10 @@ }, "entity": { "type": "object", - "required": ["name", "type"], + "required": [ + "name", + "type" + ], "properties": { "name": { "type": "string", @@ -1199,7 +1371,10 @@ "type": "string" }, "expr": { - "type": ["string", "boolean"] + "type": [ + "string", + "boolean" + ] } }, "additionalProperties": false @@ -1238,14 +1413,21 @@ }, "freshness_rules": { "type": "object", - "required": ["count", "period"], + "required": [ + "count", + "period" + ], "properties": { "count": { "$ref": "#/$defs/number_or_jinja_string" }, "period": { "type": "string", - "enum": ["minute", "hour", "day"] + "enum": [ + "minute", + "hour", + "day" + ] } }, "additionalProperties": false @@ -1275,10 +1457,15 @@ } }, "is-time-dimension": { - "required": ["type"], + "required": [ + "type" + ], "properties": { "type": { - "enum": ["TIME", "time"] + "enum": [ + "TIME", + "time" + ] } } }, @@ -1288,7 +1475,10 @@ }, "measure": { "type": "object", - "required": ["name", "agg"], + "required": [ + "name", + "agg" + ], "properties": { "name": { "type": "string", @@ -1333,7 +1523,11 @@ "type": "string" }, "expr": { - "type": ["string", "integer", "boolean"] + "type": [ + "string", + "integer", + "boolean" + ] }, "label": { "type": "string" @@ -1387,81 +1581,6 @@ }, "additionalProperties": false }, - "simple_metric_type_params": { - "type": "object", - "properties": { - "measure": { - "$ref": "#/$defs/metric_input_measure" - } - }, - "additionalProperties": false - }, - "derived_metric_type_params": { - "type": "object", - "properties": { - "expr": { - "type": "string" - }, - "metrics": { - "type": "array", - "items": { - "$ref": "#/$defs/metric_input_schema" - } - } - }, - "additionalProperties": false - }, - "cumulative_metric_type_params": { - "type": "object", - "properties": { - "measure": { - "$ref": "#/$defs/metric_input_measure" - }, - "grain_to_date": { - "enum": ["day", "week", "month", "quarter", "year"] - }, - "window": { - "type": "string" - } - }, - "additionalProperties": false - }, - "ratio_metric_type_params": { - "type": "object", - "properties": { - "filter": { - "type": "string" - }, - "numerator": { - "$ref": "#/$defs/metric_input_schema" - }, - "denominator": { - "$ref": "#/$defs/metric_input_schema" - } - }, - "additionalProperties": false - }, - "conversion_metric_type_params": { - "type": "object", - "properties": { - "measure": { - "$ref": "#/$defs/metric_input_measure" - }, - "metrics": { - "type": "array", - "items": { - "$ref": "#/$defs/metric_input_schema" - } - }, - "numerator": { - "$ref": "#/$defs/metric_input_measure" - }, - "window": { - "type": "string" - } - }, - "additionalProperties": false - }, "model_configs": { "type": "object", "properties": { @@ -1488,7 +1607,10 @@ "type": "array", "items": { "type": "object", - "required": ["database", "project"], + "required": [ + "database", + "project" + ], "properties": { "database": { "type": "string" @@ -1532,11 +1654,20 @@ }, "on_configuration_change": { "type": "string", - "enum": ["apply", "continue", "fail"] + "enum": [ + "apply", + "continue", + "fail" + ] }, "on_schema_change": { "type": "string", - "enum": ["append_new_columns", "fail", "ignore", "sync_all_columns"] + "enum": [ + "append_new_columns", + "fail", + "ignore", + "sync_all_columns" + ] }, "snowflake_warehouse": { "type": "string" @@ -1552,13 +1683,20 @@ }, "non_additive_dimension": { "type": "object", - "required": ["name"], + "required": [ + "name" + ], "properties": { "name": { "type": "string" }, "window_choice": { - "enum": ["MIN", "MAX", "min", "max"] + "enum": [ + "MIN", + "MAX", + "min", + "max" + ] }, "window_groupings": { "type": "array", @@ -1596,6 +1734,30 @@ }, "additionalProperties": false }, + "ratio_metric_type_params": { + "type": "object", + "properties": { + "denominator": { + "$ref": "#/$defs/metric_input_schema" + }, + "filter": { + "type": "string" + }, + "numerator": { + "$ref": "#/$defs/metric_input_schema" + } + }, + "additionalProperties": false + }, + "simple_metric_type_params": { + "type": "object", + "properties": { + "measure": { + "$ref": "#/$defs/metric_input_measure" + } + }, + "additionalProperties": false + }, "string_or_array_of_strings": { "oneOf": [ { @@ -1642,7 +1804,10 @@ }, { "type": "string", - "enum": ["warn", "error"] + "enum": [ + "warn", + "error" + ] } ] }, @@ -1670,4 +1835,4 @@ "additionalProperties": false } } -} +} \ No newline at end of file From c8a2b0b861b8d2c650c9fbb9558c27e2391111b8 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Thu, 23 May 2024 14:50:30 -0500 Subject: [PATCH 5/5] updates --- schemas/latest/dbt_yml_files-latest.json | 76 ++++++++++++++++++------ tests/latest/invalid/dbt_yml_files.yml | 60 +++++++++++++++++++ tests/latest/valid/dbt_yml_files.yml | 42 +++++++++++++ 3 files changed, 161 insertions(+), 17 deletions(-) diff --git a/schemas/latest/dbt_yml_files-latest.json b/schemas/latest/dbt_yml_files-latest.json index 76e12f9..e8ecbdb 100644 --- a/schemas/latest/dbt_yml_files-latest.json +++ b/schemas/latest/dbt_yml_files-latest.json @@ -346,6 +346,9 @@ }, "label": { "type": "string" + }, + "type_params": { + "type": "object" } }, "additionalProperties": false @@ -365,9 +368,6 @@ "description": { "type": "string" }, - "deprecation_date": { - "type": "string" - }, "access": { "type": "string", "enum": [ @@ -394,6 +394,9 @@ "$ref": "#/$defs/data_tests" } }, + "deprecation_date": { + "type": "string" + }, "docs": { "$ref": "#/$defs/docs_config" }, @@ -1129,20 +1132,59 @@ "conversion_metric_type_params": { "type": "object", "properties": { - "measure": { - "$ref": "#/$defs/metric_input_measure" - }, - "metrics": { - "type": "array", - "items": { - "$ref": "#/$defs/metric_input_schema" - } - }, - "numerator": { - "$ref": "#/$defs/metric_input_measure" - }, - "window": { - "type": "string" + "conversion_type_params": { + "type": "object", + "required": [ + "entity", + "base_measure", + "conversion_measure" + ], + "properties": { + "base_measure": { + "$ref": "#/$defs/metric_input_measure" + }, + "calculation": { + "type": "string", + "default": "conversion_rate", + "enum": [ + "conversions", + "conversion_rate", + "CONVERSIONS", + "CONVERSION_RATE" + ] + }, + "constant_properties": { + "type": "array", + "items": { + "type": "object", + "required": [ + "base_property", + "conversion_property" + ], + "properties": { + "base_property": { + "description": "DIMENSION or ENTITY", + "type": "string" + }, + "conversion_property": { + "description": "DIMENSION or ENTITY", + "type": "string" + } + } + } + }, + "conversion_measure": { + "$ref": "#/$defs/metric_input_measure" + }, + "entity": { + "description": "The entity to calculate over", + "type": "string" + }, + "window": { + "type": "string" + } + }, + "additionalProperties": false } }, "additionalProperties": false diff --git a/tests/latest/invalid/dbt_yml_files.yml b/tests/latest/invalid/dbt_yml_files.yml index 309909f..6539f4e 100644 --- a/tests/latest/invalid/dbt_yml_files.yml +++ b/tests/latest/invalid/dbt_yml_files.yml @@ -66,6 +66,66 @@ metrics: calculation_method: derived expression: "{{ metric('new_customers') }} * 2" + - name: new_customer + description: Unique count of new customers. + label: New Customers + type: simple + type_params: + measure: + name: customers_with_orders + metrics: + - name: order_total + alias: revenue + filter: | + {{ Dimension('order__is_food_order') }} = True + window: 1 month + filter: | + {{ Dimension('customer__customer_type') }} = 'new' + + - name: food_order_gross_profit + label: Food order gross profit + description: "The gross profit for each food order." + type: derived + type_params: + expr: revenue - cost + measure: + name: customers_with_orders + metrics: + - name: order_total + alias: revenue + filter: | + {{ Dimension('order__is_food_order') }} = True + - name: order_cost + alias: cost + filter: | + {{ Dimension('order__is_food_order') }} = True + + - name: cumulative_order_total_l1m + label: Cumulative Order total (L1M) + description: Trailing 1-month cumulative order amount + type: joel + type_params: + measure: + name: order_total + fill_nulls_with: 0 + window: 1 month + + - name: visit_to_buy_conversion_rate_7_day_window + description: "Conversion rate from viewing a page to making a purchase" + type: conversion + label: Visit to Seller Conversion Rate (7 day window) + type_params: + conversion_type_params: + expr: revenue - cost + calculation: conversions + base_measure: + name: visits + conversion_measure: + name: buys + fill_nulls_with: 0 + entity: user + window: 7 days + unit_tests: - name: some_unit_test diff --git a/tests/latest/valid/dbt_yml_files.yml b/tests/latest/valid/dbt_yml_files.yml index f05c703..a1c5c87 100644 --- a/tests/latest/valid/dbt_yml_files.yml +++ b/tests/latest/valid/dbt_yml_files.yml @@ -185,6 +185,7 @@ metrics: name: customers_with_orders fill_nulls_with: 0 join_to_timespine: true + - name: new_customer description: Unique count of new customers. label: New Customers @@ -209,6 +210,47 @@ metrics: filter: | "{{ Dimension('transaction__location') }} = 'US'" + - name: food_order_gross_profit + label: Food order gross profit + description: "The gross profit for each food order." + type: derived + type_params: + expr: revenue - cost + metrics: + - name: order_total + alias: revenue + filter: | + {{ Dimension('order__is_food_order') }} = True + - name: order_cost + alias: cost + filter: | + {{ Dimension('order__is_food_order') }} = True + + - name: cumulative_order_total_l1m + label: Cumulative Order total (L1M) + description: Trailing 1-month cumulative order amount + type: cumulative + type_params: + measure: + name: order_total + fill_nulls_with: 0 + window: 1 month + + - name: visit_to_buy_conversion_rate_7_day_window + description: "Conversion rate from viewing a page to making a purchase" + type: conversion + label: Visit to Seller Conversion Rate (7 day window) + type_params: + conversion_type_params: + calculation: conversions + base_measure: + name: visits + conversion_measure: + name: buys + fill_nulls_with: 0 + entity: user + window: 7 days + saved_queries: - name: test_saved_query description: "{{ doc('saved_query_description') }}"