Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add order_by and limit fields to saved queries #10532

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

plypaul
Copy link
Contributor

@plypaul plypaul commented Aug 6, 2024

Resolves #10531

Problem

Saved queries do not allow specification of a limit to the number of rows returns or items to order the results.

Related: dbt-labs/metricflow#1113

Solution

Add order_by and limit fields to the saved query definition.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@plypaul plypaul self-assigned this Aug 6, 2024
@cla-bot cla-bot bot added the cla:yes label Aug 6, 2024
Copy link

codecov bot commented Aug 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.20%. Comparing base (78c0571) to head (253ea6d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10532      +/-   ##
==========================================
+ Coverage   89.18%   89.20%   +0.01%     
==========================================
  Files         183      183              
  Lines       23434    23438       +4     
==========================================
+ Hits        20899    20907       +8     
+ Misses       2535     2531       -4     
Flag Coverage Δ
integration 86.54% <100.00%> (+0.08%) ⬆️
unit 62.13% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.13% <100.00%> (+<0.01%) ⬆️
Integration Tests 86.54% <100.00%> (+0.08%) ⬆️

@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch 3 times, most recently from aa60b04 to a163ffa Compare August 10, 2024 20:48
@plypaul plypaul added the artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking label Aug 12, 2024
@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch 2 times, most recently from 5df9fc4 to a0db17d Compare August 12, 2024 17:32
@plypaul
Copy link
Contributor Author

plypaul commented Aug 12, 2024

@QMalcolm I'm getting a CI check failure wrt schemas so I must be missing something. Do you know what's up?

@courtneyholcomb
Copy link
Contributor

@QMalcolm I'm getting a CI check failure wrt schemas so I must be missing something. Do you know what's up?

@plypaul You'll need to update the schema docs in a different repo. The CI check won't pass until those match what's here. Kind of a race condition though. The CI failure seems more like a reminder to make sure you update the other repo. Instructions here: https://www.notion.so/dbtlabs/Bump-Schema-Version-dd308bab6a044c7d8cb6935691732ab3?pvs=4#7422ed5c56484401b74ce508916135d9

@courtneyholcomb
Copy link
Contributor

@plypaul also, I added a few targets in the Makefile (documented in the README) to help with the schema updates there. https://github.com/dbt-labs/schemas.getdbt.com

@@ -16,6 +16,10 @@
- "{{ Dimension('user__ds', 'DAY') }} <= now()"
- "{{ Dimension('user__ds', 'DAY') }} >= '2023-01-01'"
- "{{ Metric('txn_revenue', ['id']) }} > 1"
order_by:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding some logic in tests/functional/saved_queries/test_saved_query_parsing.py to test that these values parse as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added.

@@ -19098,6 +19098,23 @@
"type": "null"
}
]
},
"order_by": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you saw this / used it but there is a make json_schema target you can use to generate this.

@courtneyholcomb
Copy link
Contributor

Aside from the comments I left, this looks good to me from what context I have!

@plypaul plypaul marked this pull request as ready for review August 19, 2024 19:01
@plypaul plypaul requested review from a team as code owners August 19, 2024 19:01
@plypaul plypaul requested review from jcserv and removed request for a team August 19, 2024 19:01
@github-actions github-actions bot added the community This PR is from a community member label Aug 19, 2024
Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Paul! 🚢

@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch 2 times, most recently from ace0b32 to 485b70f Compare October 11, 2024 14:29
QMalcolm added a commit to dbt-labs/schemas.getdbt.com that referenced this pull request Oct 12, 2024
Originally this work was done as part of #49.
However as they are additive fields that have a default values, they aren't
breaking changes. Thus here we're adding them to the v12 manifest. This is
in support of the currently open dbt-core PR dbt-labs/dbt-core#10532.

Note this also _drops_ the `vars` field from a few objects. It was originally added
to support changes in core (dbt-labs/dbt-core#10793). However,
those changes were reverted in core (dbt-labs/dbt-core#10813).
Since `vars` as a field never went out in a GA release of dbt-core, it is safe for us
to drop it.
QMalcolm added a commit to dbt-labs/schemas.getdbt.com that referenced this pull request Oct 15, 2024
Originally this work was done as part of #49.
However as they are additive fields that have a default values, they aren't
breaking changes. Thus here we're adding them to the v12 manifest. This is
in support of the currently open dbt-core PR dbt-labs/dbt-core#10532.

Note this also _drops_ the `vars` field from a few objects. It was originally added
to support changes in core (dbt-labs/dbt-core#10793). However,
those changes were reverted in core (dbt-labs/dbt-core#10813).
Since `vars` as a field never went out in a GA release of dbt-core, it is safe for us
to drop it.
@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch 2 times, most recently from fce2cb4 to d9160e8 Compare October 15, 2024 17:26
@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch from d9160e8 to 05f5983 Compare October 15, 2024 17:27
QMalcolm added a commit to dbt-labs/schemas.getdbt.com that referenced this pull request Oct 15, 2024
Originally this work was done as part of #49.
However as they are additive fields that have a default values, they aren't
breaking changes. Thus here we're adding them to the v12 manifest. This is
in support of the currently open dbt-core PR dbt-labs/dbt-core#10532.

Note this also _drops_ the `vars` field from a few objects. It was originally added
to support changes in core (dbt-labs/dbt-core#10793). However,
those changes were reverted in core (dbt-labs/dbt-core#10813).
Since `vars` as a field never went out in a GA release of dbt-core, it is safe for us
to drop it.
@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch 3 times, most recently from b5ba524 to 189867c Compare October 16, 2024 16:52
@plypaul plypaul force-pushed the plypaul--01--sq-order-limit-support branch from 189867c to 253ea6d Compare October 17, 2024 17:01
@QMalcolm QMalcolm merged commit 8be0635 into main Oct 17, 2024
56 checks passed
@QMalcolm QMalcolm deleted the plypaul--01--sq-order-limit-support branch October 17, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking cla:yes community This PR is from a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add order_by and limit fields to saved queries
4 participants