-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use common columns for incremental schema changes #4170
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbd378a
Use common columns for incremental schema changes
Kayrnt 6dd30e4
on_schema_change:append_new_columns should gracefully handle column r…
jtcohen6 1676882
review changes
Kayrnt 267a2a6
Lean approach for `process_schema_changes` to simplify
Kayrnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,15 @@ | |
|
||
{% endmacro %} | ||
|
||
{% macro diff_columns(source_columns, target_columns) %} | ||
{% macro compare_columns(source_columns, target_columns, should_include) %} | ||
|
||
{% set result = [] %} | ||
{% set source_names = source_columns | map(attribute = 'column') | list %} | ||
{% set target_names = target_columns | map(attribute = 'column') | list %} | ||
|
||
{# --check whether the name attribute exists in the target - this does not perform a data type check #} | ||
{% for sc in source_columns %} | ||
{% if sc.name not in target_names %} | ||
{% if (sc.name in target_names) == should_include %} | ||
{{ result.append(sc) }} | ||
{% endif %} | ||
{% endfor %} | ||
|
@@ -32,6 +32,14 @@ | |
|
||
{% endmacro %} | ||
|
||
{% macro diff_columns(source_columns, target_columns) %} | ||
{{ return(compare_columns(source_columns, target_columns, false) ) }} | ||
{% endmacro %} | ||
|
||
{% macro intersect_columns(source_columns, target_columns) %} | ||
{{ return(compare_columns(source_columns, target_columns, true) ) }} | ||
{% endmacro %} | ||
|
||
{% macro diff_column_data_types(source_columns, target_columns) %} | ||
|
||
{% set result = [] %} | ||
|
@@ -57,7 +65,8 @@ | |
{%- set target_columns = adapter.get_columns_in_relation(target_relation) -%} | ||
{%- set source_not_in_target = diff_columns(source_columns, target_columns) -%} | ||
{%- set target_not_in_source = diff_columns(target_columns, source_columns) -%} | ||
|
||
{%- set in_target_and_source = intersect_columns(target_columns, source_columns) -%} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add in |
||
|
||
{% set new_target_types = diff_column_data_types(source_columns, target_columns) %} | ||
|
||
{% if source_not_in_target != [] %} | ||
|
@@ -72,6 +81,8 @@ | |
'schema_changed': schema_changed, | ||
'source_not_in_target': source_not_in_target, | ||
'target_not_in_source': target_not_in_source, | ||
'in_target_and_source': in_target_and_source, | ||
'target_columns': target_columns, | ||
'new_target_types': new_target_types | ||
} %} | ||
|
||
|
@@ -132,7 +143,11 @@ | |
|
||
{% macro process_schema_changes(on_schema_change, source_relation, target_relation) %} | ||
|
||
{% if on_schema_change != 'ignore' %} | ||
{% if on_schema_change == 'ignore' %} | ||
|
||
{{ return({}) }} | ||
|
||
{% else %} | ||
|
||
{% set schema_changes_dict = check_for_schema_changes(source_relation, target_relation) %} | ||
|
||
|
@@ -158,6 +173,8 @@ | |
{% endif %} | ||
|
||
{% endif %} | ||
|
||
{{ return(schema_changes_dict) }} | ||
|
||
{% endif %} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.