Skip to content

feat!: add ignore destructive support#5117

Merged
eakmanrq merged 4 commits intomainfrom
eakmanrq/add_ignore_destructive_support
Aug 15, 2025
Merged

feat!: add ignore destructive support#5117
eakmanrq merged 4 commits intomainfrom
eakmanrq/add_ignore_destructive_support

Conversation

@eakmanrq
Copy link
Collaborator

@eakmanrq eakmanrq commented Aug 9, 2025

BREAKING: columns_to_types has been renamed to target_columns_to_types for engine adapter methods.

This PR adds support for "ignoring" a destructive change using the on_destructive_change property. As documentation says, this property should not be used in most cases and is really just being added for dbt support. It could be useful though for an "escape-hatch" situation.

The concept of ignoring a destructive change is pushed down to the SchemaDiffer class level because the SchemaDiffer needs to be aware of this property is being used due to positional changes. If the engine supports positional changes and the SchemaDiffer wasn't aware then it could generate alter commands that involve changing columns assuming a column order that wouldn't really happen.

Prior to this PR, the engine adapter class assumed that the Query or DataFrame had the same columns as columns_to_types. columns_to_types has been renamed to target_columns_to_types and now represents the target table columns and can now drift out of sync of the "source" query or DataFrame. To account for this, engine adapter methods which take a QueryOrDF now also take a source_columns which tells the adapter what columns are in that source. If needed, it will pad out the columns in the source to match the target.

Note: I am intentionally not changing dbt adapter implementation since I plan on updating it once on_additive_change support is added in follow up PR. That will isolate the breaking changes related to on_schema_change support to a single PR and it is just breaking for dbt adapter.

@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch from a73feca to 921ee2a Compare August 9, 2025 20:33
@eakmanrq eakmanrq marked this pull request as draft August 9, 2025 20:39
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch 3 times, most recently from 1fcb668 to 7384e43 Compare August 11, 2025 01:29
@eakmanrq eakmanrq marked this pull request as ready for review August 11, 2025 01:30

!!! warning "Ignore is Dangerous"

`ignore` is dangerous since it can result in error or data loss. It likely should never be used but could be useful as an "escape-hatch" or a way to workaround unexpected behavior.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would it result in data loss?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also how can it result in error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also how can it result in error?

If you made a data type change to a new type that isn't coerceable. The next time it runs it would error trying to insert the rows (since the underlying table wasn't actually changed).

Why would it result in data loss?

Not certain yet. Putting this warning for now as we do more testing with this fully implemented in the dbt adapter. After a bit if we don't identify any issues I can remove this part of the warning. For now though I would rather overly caution native users about this feature.

@izeigerman
Copy link
Collaborator

wasn't aware then it could generate alter commands that involve changing columns assuming a column order that wouldn't really happen.

I'm somewhat confused. Does changing the position result in a destructive change?

@eakmanrq
Copy link
Collaborator Author

I'm somewhat confused. Does changing the position result in a destructive change?

No it doesn't. The SchemaDiffer though requires that it can properly track the future state of the changes it is generating in order to properly understand where columns should be inserted. So if it thought columns would be dropped when they would actually still exist then it might put columns in expected positions as a result.

@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch 10 times, most recently from af20b9b to d1d6be9 Compare August 13, 2025 20:13
snowpark = optional_import("snowflake.snowpark")

Query = t.Union[exp.Query, exp.DerivedTable]
Query = exp.Query
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Discussed internally and we don't see a reason why exp.DerivedTable was expected before and that code is from version 0.0.2 so assuming it is no longer needed.

@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch 8 times, most recently from 404ea84 to c0cef4e Compare August 14, 2025 16:16
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch from a9c8d06 to fc7a0c7 Compare August 14, 2025 20:17
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch 2 times, most recently from 9d7f1fb to 0885a31 Compare August 14, 2025 20:47
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch 4 times, most recently from 155fc2b to 912348b Compare August 14, 2025 22:42
@eakmanrq eakmanrq changed the title feat: add ignore destructive support feat!: add ignore destructive support Aug 14, 2025
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch from c61f368 to 322249a Compare August 14, 2025 23:06
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch 4 times, most recently from d118afb to 990c979 Compare August 15, 2025 16:39
@eakmanrq eakmanrq force-pushed the eakmanrq/add_ignore_destructive_support branch from 990c979 to 8b5c788 Compare August 15, 2025 18:34
@eakmanrq eakmanrq merged commit 5e59d18 into main Aug 15, 2025
27 of 28 checks passed
@eakmanrq eakmanrq deleted the eakmanrq/add_ignore_destructive_support branch August 15, 2025 19:39
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.

2 participants