From 1b5dc0c82ce1b4599463b8a4333dbb8b78e49958 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 6 May 2024 09:34:20 -0500 Subject: [PATCH] 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