Skip to content

Commit

Permalink
update schema with if else for type params
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-connors-3 committed May 6, 2024
1 parent d6a8f37 commit 1b5dc0c
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 37 deletions.
162 changes: 128 additions & 34 deletions schemas/latest/dbt_yml_files-latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@
"RATIO",
"CUMULATIVE",
"DERIVED",
"CONVERSION",
"simple",
"ratio",
"cumulative",
"derived"
"derived",
"conversion"
]
},
"filter": {
Expand All @@ -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
Expand Down Expand Up @@ -1218,9 +1277,6 @@
"string",
"boolean"
]
},
"role": {
"type": "string"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1338,7 +1394,7 @@
"SUM",
"MIN",
"MAX",
"AVERAGE",
"AVG",
"COUNT_DISTINCT",
"SUM_BOOLEAN",
"COUNT",
Expand All @@ -1347,7 +1403,7 @@
"sum",
"min",
"max",
"average",
"avg",
"count_distinct",
"sum_boolean",
"count",
Expand Down Expand Up @@ -1375,33 +1431,32 @@
"boolean"
]
},
"label": {
"type": "string"
},
"non_additive_dimension": {
"$ref": "#/$defs/non_additive_dimension"
}
},
"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",
Expand All @@ -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"
},
Expand Down
24 changes: 21 additions & 3 deletions tests/latest/valid/dbt_yml_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
{{ 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'"

0 comments on commit 1b5dc0c

Please sign in to comment.