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

ADAP-835: Optimize manual refresh on auto-refreshed materialized views #8847

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

mikealfare
Copy link
Contributor

@mikealfare mikealfare commented Oct 13, 2023

resolves #6911

Problem

dbt run will issue a manual refresh of a materialized view if there are no changes detected during a run. This happens regardless of whether the materialized view is setup to be automatically refreshed. If the materialized view is already scheduled to be refreshed, there is no need to insert an additional refresh. This will add cost and potentially introduce unexpected data as the refresh schedule will not match what's set with the extra refresh.

Solution

dbt will inspect the materialized view to determine if it is set to automatically refresh. If it is, and there are no changes, then dbt run will do nothing. If it is not set to automatically refresh, then dbt run will issue a refresh command.

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

@mikealfare mikealfare self-assigned this Oct 13, 2023
@cla-bot cla-bot bot added the cla:yes label Oct 13, 2023
@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

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

Comparison is base (efa6339) 86.35% compared to head (c006503) 86.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8847      +/-   ##
==========================================
- Coverage   86.35%   86.30%   -0.06%     
==========================================
  Files         177      179       +2     
  Lines       26383    26453      +70     
==========================================
+ Hits        22784    22829      +45     
- Misses       3599     3624      +25     
Flag Coverage Δ
integration 83.09% <82.50%> (-0.13%) ⬇️
unit 64.59% <66.25%> (-0.01%) ⬇️

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

Files Coverage Δ
core/dbt/adapters/base/impl.py 80.37% <100.00%> (+0.11%) ⬆️
core/dbt/adapters/relation_configs/__init__.py 100.00% <100.00%> (ø)
...bt/adapters/relation_configs/_materialized_view.py 100.00% <100.00%> (ø)
core/dbt/context/providers.py 88.87% <100.00%> (+0.06%) ⬆️
...ore/dbt/adapters/relation_configs/config_change.py 94.11% <50.00%> (ø)
core/dbt/adapters/relation_configs/_factory.py 87.50% <87.50%> (ø)
core/dbt/tests/util.py 85.52% <33.33%> (-1.08%) ⬇️
core/dbt/adapters/relation_configs/config_base.py 84.61% <79.31%> (-8.25%) ⬇️

... and 3 files with indirect coverage changes

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

@@ -66,31 +65,16 @@ def from_dict(cls, config_dict: dict) -> "PostgresMaterializedViewConfig":
return materialized_view

@classmethod
def from_model_node(cls, model_node: ModelNode) -> "PostgresMaterializedViewConfig":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to RelationConfigBase

}
return config_dict

@classmethod
def from_relation_results(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to RelationConfigBase

@@ -36,7 +37,6 @@ class PostgresMaterializedViewConfig(RelationConfigBase, RelationConfigValidatio
"""

table_name: str = ""
query: str = ""
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 not used, and is the only difference in this context between a ModelNode and a ParsedNode

@mikealfare mikealfare added the user docs [docs.getdbt.com] Needs better documentation label Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-2068] [Feature] Let's add Materialized View as a materialization, finally
1 participant