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

Move SemanticModel data artifacts to dbt/artifacts #9485

Merged
merged 10 commits into from
Feb 1, 2024

Conversation

QMalcolm
Copy link
Contributor

@QMalcolm QMalcolm commented Jan 29, 2024

resolves #9387

Problem

We are moving data artifacts to dbt/artifacts in a piecewise fashion. We needed to move SemanticModel as part of that.

Solution

Moved data portion of SemanticModel to dbt/artifacts (and all other classes that doing so required)

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

@QMalcolm QMalcolm added the Skip Changelog Skips GHA to check for changelog file label Jan 29, 2024
@cla-bot cla-bot bot added the cla:yes label Jan 29, 2024
@QMalcolm QMalcolm changed the title Qmalcolm 9387 move semantic model to dbt artifacts Move SemanticModel data artifacts to dbt/artifacts Jan 29, 2024
@QMalcolm QMalcolm force-pushed the qmalcolm--9387-move-semantic-model-to-dbt-artifacts branch from 44405cf to 0365498 Compare January 30, 2024 00:42
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

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

Comparison is base (98bbbc1) 87.96% compared to head (32a12fa) 87.95%.
Report is 5 commits behind head on main.

Files Patch % Lines
core/dbt/artifacts/resources/v1/semantic_model.py 97.51% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9485      +/-   ##
==========================================
- Coverage   87.96%   87.95%   -0.01%     
==========================================
  Files         166      166              
  Lines       22094    22119      +25     
==========================================
+ Hits        19435    19455      +20     
- Misses       2659     2664       +5     
Flag Coverage Δ
integration 85.42% <79.23%> (-0.02%) ⬇️
unit 62.34% <96.17%> (+<0.01%) ⬆️

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

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

@QMalcolm QMalcolm removed the Skip Changelog Skips GHA to check for changelog file label Jan 30, 2024
@QMalcolm QMalcolm marked this pull request as ready for review January 30, 2024 00:48
@QMalcolm QMalcolm requested a review from a team as a code owner January 30, 2024 00:48
@QMalcolm QMalcolm requested a review from martynydbt January 30, 2024 00:48


@dataclass
class SemanticModel(GraphResource):
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 class has a fair number of @property methods, and even a method that isn't @property'd. Felt kind of weird moving them all, however they are expected parts of the dbt-semantic-interfaces protocol specification for SemanticModel. I would like to reduce some of these in the protocol itself, but for now keeping them together in this implementation seems right-ish

@MichelleArk MichelleArk requested review from MichelleArk and removed request for martynydbt January 30, 2024 03:02
@MichelleArk
Copy link
Contributor

Let's also do the satisfying thing and remove the dbt.contracts.graph.nodes in v12/manifest.py in favor of dbt.artifacts.resources. Presumably at this point we can do this for SavedQuery, Metric, and SemanticModel

Similar to this commit: cdfdb7a

@QMalcolm
Copy link
Contributor Author

QMalcolm commented Jan 30, 2024

Mypy keeps finding errors in GHA that it's not raising locally on pre-commit hooks 🙃

…tor search

In the `search` method in `selector_methods.py`, we were getting object
representations from the incoming writable manifest by unique id. What we
get from the writable manifest though is increasingly the `resource`
(data artifact) part of the node, not the full node. This was problematic
because a number of the selector processes _compare_ the old node to the
new node, but the `resource` representation doesn't have the comparator
methods.

In this commit we dict-ify the resource and then get the full node by
undictifying that. We should probably have a better built in process to
the full node objects to do this, but this will do for now.
…node conversion

We want to easily be able to create nodes from their resource counter
parts. It's actually imperative that we can do so. The previous commit
had a manual way to do so where needed. However, we don't want to have
to put `from_dict(.to_dict())` everywhere. So here we hadded a `from_resource`
class method to `BaseNode`. Everything that inherits from `BaseNode` thus
automatically gets this functionality.

HOWEVER, the implementation currently has a problem. Specifically, the
type for `resource_instance` is `BaseResource`. Which means if one is
calling say `Metric.from_resource()`, one could hand it a `SemanticModelResource`
and mypy won't complain. In this case, a semi-cryptic error might get
raised at runtime. Whether or not an error gets raised depends entirely
on whether or not the dictified resource instance manages to satisfy all
the required attributes of the desired node class. THIS IS VERY BAD.

We should be able to solve this issue in an upcoming (hopefully next)
commit, wherein we genericize `BaseNode` such that when inheriting it
you declare it with a resource type. Technically a runtime error will
still be possible, however any mixups should be caught by mypy on
pre-commit hooks as well as PRs.
Turning `BaseNode` into an ABC generic allows us to say that the inheriting
class can define what resource type from artifacts it should be used with.
This gives us added type safety to what resource type can be passed into
`from_resource` when called via `SemanticModel.from_resource(...)`,
`Metric.from_resource(...)`, and etc.

NOTE: This only gives us type safety from mypy. If we begin ignoring
mypy errors during development, we can still get into a situation for
runtime errors (it's just harder to do so now).
@QMalcolm QMalcolm merged commit 0836095 into main Feb 1, 2024
51 checks passed
@QMalcolm QMalcolm deleted the qmalcolm--9387-move-semantic-model-to-dbt-artifacts branch February 1, 2024 00:50
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-3557] Define SemanticModel contract in dbt/artifacts
2 participants