Skip to content

Commit

Permalink
Add order_by and limit fields to saved queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Aug 6, 2024
1 parent 21a4633 commit 390767d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/dbt/artifacts/resources/v1/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,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
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,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:
Expand Down
3 changes: 2 additions & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
# Accept patches but avoid automatically updating past a set minor version range.
"dbt-extractor>=0.5.0,<=0.6",
"minimal-snowplow-tracker>=0.0.2,<0.1",
"dbt-semantic-interfaces>=0.6.11,<0.7",
# "dbt-semantic-interfaces>=0.7.0,<0.8",
"dbt-semantic-interfaces>=0.6.0,<0.7",
# Minor versions for these are expected to be backwards-compatible
"dbt-common>=1.6.0,<2.0",
"dbt-adapters>=1.3.0,<2.0",
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/saved_queries/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
- "{{ Dimension('user__ds', 'DAY') }} <= now()"
- "{{ Dimension('user__ds', 'DAY') }} >= '2023-01-01'"
- "{{ Metric('txn_revenue', ['id']) }} > 1"
order_by:
- "Metric('simple_metric')"
- "Dimension('user__ds')"
limit: 10
exports:
- name: my_export
config:
Expand Down

0 comments on commit 390767d

Please sign in to comment.