diff --git a/schemas/latest/dbt_yml_files-latest.json b/schemas/latest/dbt_yml_files-latest.json index 5c080bd..e8ecbdb 100644 --- a/schemas/latest/dbt_yml_files-latest.json +++ b/schemas/latest/dbt_yml_files-latest.json @@ -223,6 +223,99 @@ "type", "type_params" ], + "if": { + "properties": { + "type": { + "enum": [ + "SIMPLE", + "simple" + ] + } + } + }, + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/simple_metric_type_params" + } + } + }, + "else": { + "if": { + "properties": { + "type": { + "enum": [ + "derived", + "DERIVED" + ] + } + } + }, + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/derived_metric_type_params" + } + } + }, + "else": { + "if": { + "properties": { + "type": { + "enum": [ + "cumulative", + "CUMULATIVE" + ] + } + } + }, + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/cumulative_metric_type_params" + } + } + }, + "else": { + "if": { + "properties": { + "type": { + "enum": [ + "conversion", + "CONVERSION" + ] + } + } + }, + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/conversion_metric_type_params" + } + } + }, + "else": { + "if": { + "properties": { + "type": { + "enum": [ + "ratio", + "RATIO" + ] + } + } + }, + "then": { + "properties": { + "type_params": { + "$ref": "#/$defs/ratio_metric_type_params" + } + } + } + } + } + } + }, "properties": { "name": { "type": "string", @@ -237,10 +330,12 @@ "RATIO", "CUMULATIVE", "DERIVED", + "CONVERSION", "simple", "ratio", "cumulative", - "derived" + "derived", + "conversion" ] }, "filter": { @@ -253,7 +348,7 @@ "type": "string" }, "type_params": { - "$ref": "#/$defs/metric_type_params" + "type": "object" } }, "additionalProperties": false @@ -273,9 +368,6 @@ "description": { "type": "string" }, - "deprecation_date": { - "type": "string" - }, "access": { "type": "string", "enum": [ @@ -302,6 +394,9 @@ "$ref": "#/$defs/data_tests" } }, + "deprecation_date": { + "type": "string" + }, "docs": { "$ref": "#/$defs/docs_config" }, @@ -1034,6 +1129,87 @@ } } }, + "conversion_metric_type_params": { + "type": "object", + "properties": { + "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 + }, + "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": [ { @@ -1151,6 +1327,21 @@ } ] }, + "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": [ @@ -1274,9 +1465,6 @@ "string", "boolean" ] - }, - "role": { - "type": "string" } }, "additionalProperties": false @@ -1425,7 +1613,7 @@ "SUM", "MIN", "MAX", - "AVERAGE", + "AVG", "COUNT_DISTINCT", "SUM_BOOLEAN", "COUNT", @@ -1434,7 +1622,7 @@ "sum", "min", "max", - "average", + "avg", "count_distinct", "sum_boolean", "count", @@ -1462,6 +1650,9 @@ "boolean" ] }, + "label": { + "type": "string" + }, "non_additive_dimension": { "$ref": "#/$defs/non_additive_dimension" } @@ -1469,26 +1660,29 @@ "additionalProperties": false }, "metric_input_measure": { - "oneOf": [ - { + "type": "object", + "properties": { + "name": { "type": "string" }, - { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "alias": { + "fill_nulls_with": { + "anyOf": [ + { "type": "string" }, - "filter": { - "type": "string" + { + "type": "integer" } - }, - "additionalProperties": false + ] + }, + "filter": { + "type": "string" + }, + "join_to_timespine": { + "type": "boolean" } - ] + }, + "additionalProperties": false }, "metric_input_schema": { "type": "object", @@ -1502,48 +1696,12 @@ "filter": { "type": "string" }, - "offset_to_grain": { - "type": "string" - }, "offset_window": { "type": "string" } }, "additionalProperties": false }, - "metric_type_params": { - "type": "object", - "properties": { - "denominator": { - "$ref": "#/$defs/metric_input_measure" - }, - "expr": { - "type": [ - "string", - "boolean" - ] - }, - "grain_to_date": { - "type": "string" - }, - "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": { @@ -1697,6 +1855,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": [ { 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 c6e1815..a1c5c87 100644 --- a/tests/latest/valid/dbt_yml_files.yml +++ b/tests/latest/valid/dbt_yml_files.yml @@ -181,16 +181,75 @@ 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' + - 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'" + + - 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 @@ -209,4 +268,4 @@ saved_queries: config: alias: my_export_alias export_as: table - schema: my_export_schema_name \ No newline at end of file + schema: my_export_schema_name