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 SavedQuery nodes #8798

Merged
merged 32 commits into from
Oct 11, 2023
Merged

Add SavedQuery nodes #8798

merged 32 commits into from
Oct 11, 2023

Conversation

QMalcolm
Copy link
Contributor

@QMalcolm QMalcolm commented Oct 9, 2023

resolves #8594

Problem

We need to support a new node type SavedQuery for 1.7 of core. This is work is to support MetricFlow and the Semantic Layer.

Solution

We

  • Added SavedQuery nodes to the manifest
  • Enabled parsing of SavedQuery nodes
  • Enabled partial parsing of SavedQuery nodes
  • Enabled selector method of SavedQuery nodes
  • Enabled doc support for SavedQuery node decsriptions
  • Provided upgrade support from v10 (1.6) to v11 (1.7)
  • Created a Lookup utility for SavedQuery nodes

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/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

In 0.3.x of `dbt-semantic-intefaces` the location of the WhereFilterParser
moved to be grouped in with a bunch of new adjacent code. As such,
we needed to correct our import path of it.
@QMalcolm QMalcolm added the Skip Changelog Skips GHA to check for changelog file label Oct 9, 2023
@cla-bot cla-bot bot added the cla:yes label Oct 9, 2023
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Attention: 47 lines in your changes are missing coverage. Please review.

Comparison is base (70b2e15) 86.54% compared to head (5c337b5) 84.65%.
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8798      +/-   ##
==========================================
- Coverage   86.54%   84.65%   -1.89%     
==========================================
  Files         176      177       +1     
  Lines       25856    26354     +498     
==========================================
- Hits        22376    22311      -65     
- Misses       3480     4043     +563     
Flag Coverage Δ
integration 81.34% <75.20%> (-1.95%) ⬇️
unit 64.65% <45.45%> (-0.42%) ⬇️

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

Files Coverage Δ
core/dbt/config/project.py 97.12% <100.00%> (-0.27%) ⬇️
core/dbt/config/runtime.py 96.23% <ø> (ø)
core/dbt/context/context_config.py 94.35% <100.00%> (+0.11%) ⬆️
core/dbt/contracts/files.py 94.57% <100.00%> (+0.02%) ⬆️
core/dbt/contracts/graph/manifest_upgrade.py 96.05% <100.00%> (+0.10%) ⬆️
core/dbt/contracts/graph/model_config.py 92.46% <100.00%> (+0.26%) ⬆️
core/dbt/contracts/graph/semantic_manifest.py 95.83% <100.00%> (-1.95%) ⬇️
core/dbt/contracts/graph/unparsed.py 93.05% <100.00%> (-0.46%) ⬇️
core/dbt/contracts/project.py 97.75% <100.00%> (+0.57%) ⬆️
core/dbt/node_types.py 98.14% <100.00%> (+0.10%) ⬆️
... and 10 more

... and 41 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@QMalcolm QMalcolm force-pushed the qmalcolm--8594-add-saved-query-nodes branch from 396ea4f to 88e46cd Compare October 10, 2023 10:16
Our grouping logic seems to be in a weird spot. It seems liek we're
moving to setting the `group` for a node in the node's `config` however,
all of the logic around grouping is still focused on the top level `group`
property on a nodes. To get group stuff plumbed I've thus added `group`
as a top level property of the `SavedQuery` node, and populated it from
the config group value.
I don't like making scatter shot commits like this. However, a lot
of this commit was written ~4am, soooo yea. Things were broken, I wanted
things to be unbroken. I mostly searched for `semantic_models` and added
the equivalent necessary `saved_queries`. Some stuff is in support of
writing out the manifest, some stuff helps with node selection, it's a
lot of miscelaneous stuff that I don't fully understand.
@QMalcolm QMalcolm force-pushed the qmalcolm--8594-add-saved-query-nodes branch from 88e46cd to 0e15768 Compare October 10, 2023 22:41
@QMalcolm QMalcolm removed the Skip Changelog Skips GHA to check for changelog file label Oct 10, 2023
@QMalcolm QMalcolm marked this pull request as ready for review October 10, 2023 22:43
@QMalcolm QMalcolm requested review from a team as code owners October 10, 2023 22:43
@QMalcolm QMalcolm removed the request for review from a team October 10, 2023 22:43
We don't actually append anything to `refs` for SavedQuery nodes currently.
I'm not sure if anything needs to be appended to them. Regardless, we
access the `refs` property throughout the codebase while iterating over
nodes. It seems wise to support this attribute as to not accidently blow
something up with it not existing.
@QMalcolm QMalcolm force-pushed the qmalcolm--8594-add-saved-query-nodes branch from 982fd98 to df343cf Compare October 10, 2023 22:52
We're gonna release DSI 0.3.0, and if this PR automatically pulls that
in things will break. But the things that need fixing should be handled
separately from this PR. After releasing DSI 0.3.0 I'm going to create
a branch off/ontop of this one, and open a stacked PR with the associated
changes.
if isinstance(node, SeedNode):
return
elif isinstance(node, SavedQuery):
metrics = [[metric] for metric in node.metrics]
Copy link
Contributor

@MichelleArk MichelleArk Oct 11, 2023

Choose a reason for hiding this comment

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

for my own understanding - why is this necessary?

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 necessary because the for loop that begins on 1620 expects each "metric" in the list of "metrics" to be a list of either 1 or 2 strings (i.e. List[List[str]]. Where the first string is the target_metric_name and the second (if it exists) is the target_metric_package. Saved query node metrics don't support package targeting. and it's metrics is just a list of strings (i.e. List[str]), with each string being a target_metric_name. Thus instead of handling them differently within the for loop that resolves the metrics, it was easier to just massage the saved query metrics to have the same shape.

…ueries

I missed this when I was copy and pasting 🤦
@QMalcolm QMalcolm merged commit af0cbcb into main Oct 11, 2023
49 of 50 checks passed
@QMalcolm QMalcolm deleted the qmalcolm--8594-add-saved-query-nodes branch October 11, 2023 22:54
@peterallenwebb
Copy link
Contributor

@QMalcolm I haven't looked into the intended semantics of this new node type, but one file you might have missed is compilation.py. I also missed it in my initial implementation of SemanticModel. Take a look at the spots that the semantic_models collection is mentioned in that file. In particular, without changes to link_graph and link_node functions, the new node type probably will not be treated like it is "part of the DAG" for some purposes.

mirnawong1 added a commit to dbt-labs/docs.getdbt.com that referenced this pull request Mar 25, 2024
[Preview](https://docs-getdbt-com-git-dbeatty10-patch-1-dbt-labs.vercel.app/reference/node-selection/methods#the-saved_query-method)

## What are you changing in this pull request and why?

The "saved_query" selector method was [added in
v1.7](https://github.com/dbt-labs/dbt-core/blob/1.7.latest/CHANGELOG.md#dbt-core-170---november-02-2023)
by dbt-labs/dbt-core#8594 /
dbt-labs/dbt-core#8798.

## Checklist
- [x] Review the [Content style
guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md)
so my content adheres to these guidelines.
- [x] I have verified all new code examples work as described
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-3091] Add SavedQuery node
3 participants