Skip to content

Conversation

pkotikalapudi
Copy link

@pkotikalapudi pkotikalapudi commented Oct 1, 2025

Summary

Alter destination table along with materialized views on update.

Currently when we update a model materialized='materialized_view' it only updates underlying materialized view but not the destination table it is attached to. This issue is also brought up before.

This PR provides the ability to update the destination table along with Materialized view. It uses on_schema_change

Checklist

@CLAassistant
Copy link

CLAassistant commented Oct 1, 2025

Corporate CLA signed.

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

💡 To request another review, post a new comment with "/windsurf-review".

Comment on lines +89 to +97
{%- set on_schema_change = incremental_validate_on_schema_change(config.get('on_schema_change'), default='ignore') -%}
{{ log('on_schema_change strategy for destination table of MV: ' + on_schema_change, info=True) }}
{%- if on_schema_change != 'ignore' -%}
{%- set column_changes = adapter.check_incremental_schema_changes(on_schema_change, existing_relation, sql) -%}
{% if column_changes %}
{% do clickhouse__apply_column_changes(column_changes, existing_relation) %}
{% set existing_relation = load_cached_relation(this) %}
{% endif %}
{%- endif %}
Copy link
Contributor

Choose a reason for hiding this comment

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

The code should check if existing_relation exists before attempting to apply schema changes. Without this check, the code might try to apply schema changes to a non-existent relation.

Suggested change
{%- set on_schema_change = incremental_validate_on_schema_change(config.get('on_schema_change'), default='ignore') -%}
{{ log('on_schema_change strategy for destination table of MV: ' + on_schema_change, info=True) }}
{%- if on_schema_change != 'ignore' -%}
{%- set column_changes = adapter.check_incremental_schema_changes(on_schema_change, existing_relation, sql) -%}
{% if column_changes %}
{% do clickhouse__apply_column_changes(column_changes, existing_relation) %}
{% set existing_relation = load_cached_relation(this) %}
{% endif %}
{%- endif %}
{%- set on_schema_change = incremental_validate_on_schema_change(config.get('on_schema_change'), default='ignore') -%}
{{ log('on_schema_change strategy for destination table of MV: ' + on_schema_change, info=True) }}
{%- if existing_relation is not none and on_schema_change != 'ignore' -%}
{%- set column_changes = adapter.check_incremental_schema_changes(on_schema_change, existing_relation, sql) -%}
{% if column_changes %}
{% do clickhouse__apply_column_changes(column_changes, existing_relation) %}
{% set existing_relation = load_cached_relation(this) %}
{% endif %}
{%- endif %}

Copy link
Author

Choose a reason for hiding this comment

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

The default behavior in case of on_schema_change non existent is to ignore destination table change and just update the MV (current implementation)

@pkotikalapudi
Copy link
Author

@koletzilla Please take a look at this while I add/update tests for multiple MV and RMV

@pkotikalapudi
Copy link
Author

CLA assistant check Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.You have signed the CLA already but the status is still pending? Let us recheck it.

CCLA has been signed by Twilio. Is there somebody who can validate it?

@alexey-milovidov
Copy link
Member

I validated, all ok.

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.

3 participants