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

Fix parsing of database results for materialized view autorefresh #643

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231025-203732.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix parsing of database results for materialized view auto refresh
time: 2023-10-25T20:37:32.191259-04:00
custom:
Author: mikealfare
Issue: "643"
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ def parse_relation_results(cls, relation_results: RelationResults) -> dict:
"mv_name": materialized_view.get("table"),
"schema_name": materialized_view.get("schema"),
"database_name": materialized_view.get("database"),
"autorefresh": materialized_view.get("autorefresh"),
"query": cls._parse_query(query.get("definition")),
}

autorefresh_value = materialized_view.get("autorefresh")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redshift returns the value as a single character: 't' or 'f'. Sometimes agate picks this up and converts and sometimes it does not.

if autorefresh_value is not None:
bool_filter = {"t": True, "f": False}
config_dict["autorefresh"] = bool_filter.get(autorefresh_value, autorefresh_value)

# the default for materialized views differs from the default for diststyle in general
# only set it if we got a value
if materialized_view.get("diststyle"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,6 @@ def test_change_is_applied_via_alter_str_true(self, project, my_materialized_vie
assert_message_in_logs(f"Applying ALTER to: {my_materialized_view}", logs)
assert_message_in_logs(f"Applying REPLACE to: {my_materialized_view}", logs, False)

def test_change_is_applied_via_alter_str_false(self, project, my_materialized_view):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The string version of this is already tested with the test above. Also, this does not represent a change, and just the fact that "False" is treated the same as False. This is covered in a unit test.

self.check_start_state(project, my_materialized_view)

self.change_config_via_alter_str_false(project, my_materialized_view)
_, logs = run_dbt_and_capture_with_retries_redshift_mv(
["--debug", "run", "--models", my_materialized_view.name]
)

self.check_state_alter_change_is_applied_str_false(project, my_materialized_view)

assert_message_in_logs(f"Applying ALTER to: {my_materialized_view}", logs)
assert_message_in_logs(f"Applying REPLACE to: {my_materialized_view}", logs, False)

def test_change_is_applied_via_replace(self, project, my_materialized_view):
self.check_start_state(project, my_materialized_view)

Expand Down
Loading