diff --git a/.changes/unreleased/Features-20240806-144859.yaml b/.changes/unreleased/Features-20240806-144859.yaml new file mode 100644 index 00000000000..69df7fff614 --- /dev/null +++ b/.changes/unreleased/Features-20240806-144859.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Add `order_by` and `limit` fields to saved queries. +time: 2024-08-06T14:48:59.035914-07:00 +custom: + Author: plypaul + Issue: "10531" diff --git a/core/dbt/artifacts/resources/v1/saved_query.py b/core/dbt/artifacts/resources/v1/saved_query.py index 1eea7990cc1..e1d056d0422 100644 --- a/core/dbt/artifacts/resources/v1/saved_query.py +++ b/core/dbt/artifacts/resources/v1/saved_query.py @@ -44,6 +44,8 @@ class QueryParams(dbtClassMixin): metrics: List[str] group_by: List[str] where: Optional[WhereFilterIntersection] + order_by: List[str] = field(default_factory=list) + limit: Optional[int] = None @dataclass diff --git a/core/dbt/contracts/graph/unparsed.py b/core/dbt/contracts/graph/unparsed.py index f20e76a8b68..5e63c487e89 100644 --- a/core/dbt/contracts/graph/unparsed.py +++ b/core/dbt/contracts/graph/unparsed.py @@ -720,6 +720,8 @@ class UnparsedQueryParams(dbtClassMixin): group_by: List[str] = field(default_factory=list) # Note: `Union` must be the outermost part of the type annotation for serialization to work properly. where: Union[str, List[str], None] = None + order_by: List[str] = field(default_factory=list) + limit: Optional[int] = None @dataclass diff --git a/core/dbt/parser/schema_yaml_readers.py b/core/dbt/parser/schema_yaml_readers.py index dc99e87a218..9b4a550b5d3 100644 --- a/core/dbt/parser/schema_yaml_readers.py +++ b/core/dbt/parser/schema_yaml_readers.py @@ -788,6 +788,8 @@ def _get_query_params(self, unparsed: UnparsedQueryParams) -> QueryParams: group_by=unparsed.group_by, metrics=unparsed.metrics, where=parse_where_filter(unparsed.where), + order_by=unparsed.order_by, + limit=unparsed.limit, ) def parse_saved_query(self, unparsed: UnparsedSavedQuery) -> None: diff --git a/schemas/dbt/catalog/v1.json b/schemas/dbt/catalog/v1.json index 25c2b25b2b3..f104c5b977f 100644 --- a/schemas/dbt/catalog/v1.json +++ b/schemas/dbt/catalog/v1.json @@ -12,7 +12,7 @@ }, "dbt_version": { "type": "string", - "default": "1.9.0a1" + "default": "1.9.0b2" }, "generated_at": { "type": "string" diff --git a/schemas/dbt/manifest/v12.json b/schemas/dbt/manifest/v12.json index dc369a2cbe3..9cb7f732e62 100644 --- a/schemas/dbt/manifest/v12.json +++ b/schemas/dbt/manifest/v12.json @@ -13,7 +13,7 @@ }, "dbt_version": { "type": "string", - "default": "1.9.0a1" + "default": "1.9.0b2" }, "generated_at": { "type": "string" @@ -706,6 +706,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -1739,6 +1745,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -2387,6 +2399,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -3172,6 +3190,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -3976,6 +4000,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -5331,6 +5361,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -5979,6 +6015,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -6942,6 +6984,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -10543,6 +10591,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -11576,6 +11630,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -12224,6 +12284,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -13009,6 +13075,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -13813,6 +13885,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -15168,6 +15246,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -15816,6 +15900,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -16779,6 +16869,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -19542,6 +19638,23 @@ "type": "null" } ] + }, + "order_by": { + "type": "array", + "items": { + "type": "string" + } + }, + "limit": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null } }, "additionalProperties": false, @@ -21076,6 +21189,23 @@ "type": "null" } ] + }, + "order_by": { + "type": "array", + "items": { + "type": "string" + } + }, + "limit": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null } }, "additionalProperties": false, diff --git a/schemas/dbt/run-results/v6.json b/schemas/dbt/run-results/v6.json index 1f185a2135a..1bf1cf75e83 100644 --- a/schemas/dbt/run-results/v6.json +++ b/schemas/dbt/run-results/v6.json @@ -12,7 +12,7 @@ }, "dbt_version": { "type": "string", - "default": "1.9.0a1" + "default": "1.9.0b2" }, "generated_at": { "type": "string" diff --git a/schemas/dbt/sources/v3.json b/schemas/dbt/sources/v3.json index 5ade4a90be0..df2784f1a81 100644 --- a/schemas/dbt/sources/v3.json +++ b/schemas/dbt/sources/v3.json @@ -12,7 +12,7 @@ }, "dbt_version": { "type": "string", - "default": "1.9.0a1" + "default": "1.9.0b2" }, "generated_at": { "type": "string" diff --git a/tests/functional/saved_queries/fixtures.py b/tests/functional/saved_queries/fixtures.py index 96383ab5472..58ed73c81b0 100644 --- a/tests/functional/saved_queries/fixtures.py +++ b/tests/functional/saved_queries/fixtures.py @@ -16,6 +16,10 @@ - "{{ TimeDimension('id__ds', 'DAY') }} <= now()" - "{{ TimeDimension('id__ds', 'DAY') }} >= '2023-01-01'" - "{{ Metric('txn_revenue', ['id']) }} > 1" + order_by: + - "Metric('simple_metric')" + - "Dimension('id__ds')" + limit: 10 exports: - name: my_export config: diff --git a/tests/functional/saved_queries/test_saved_query_parsing.py b/tests/functional/saved_queries/test_saved_query_parsing.py index 40e4cdfa4fb..f00f7366562 100644 --- a/tests/functional/saved_queries/test_saved_query_parsing.py +++ b/tests/functional/saved_queries/test_saved_query_parsing.py @@ -66,6 +66,10 @@ def test_semantic_model_parsing(self, project): assert len(saved_query.query_params.group_by) == 1 assert len(saved_query.query_params.where.where_filters) == 3 assert len(saved_query.depends_on.nodes) == 1 + + assert len(saved_query.query_params.order_by) == 2 + assert saved_query.query_params.limit is not None + assert saved_query.description == "My SavedQuery Description" assert len(saved_query.exports) == 1 assert saved_query.exports[0].name == "my_export"