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 config change detection not working for multiple sortkey in materialized views #1

Conversation

lvitti
Copy link
Collaborator

@lvitti lvitti commented Jun 18, 2024

resolves dbt-labs#838

Problem

Having multiple sort keys and without changes between the model and the Materialized View, the change check between model and view ends up returning as a result that it has changes. This is because svv_table_info.sortkey1 is being used instead of use the list of sort key that the Materialized View have

Solution

We can get the list of SortKeys using the mv_tbl related table

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

Steps To Reproduce:

  1. Make sure to delete the MV first.
    drop materialized view if exists dev.public.mv_double_sort

  2. Add an mv to the project with more than 1 sort key:

-- models/mv_double_sort.sql
{{
    config(
        materialized = 'materialized_view',
        dist = 'b',
        sort = ['b', 'a'],
        on_configuration_change = 'fail'
    )
}}

select a, b, c from foo

  1. $ dbt --debug build -s my_double_sort Should create the materialized view
  2. Run again $ dbt --debug build -s my_double_sort and should refresh the materialized view instead of drop and recreate the view

@lvitti lvitti changed the title Lvitti/fix config change detection not working for multiple sortkey Fix config change detection not working for multiple sortkey in materialized views Jun 18, 2024
@lvitti lvitti merged commit f58b706 into Shiphero:main Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Materialized view config change identification not working with multiple sort keys
1 participant