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

Prefer DEFAULT to NULL when inserting into, actually validate append #607

Merged
merged 3 commits into from
Mar 6, 2024

Conversation

benc-db
Copy link
Collaborator

@benc-db benc-db commented Mar 6, 2024

Description

A github user pointed out that technically using NULL could lead to different behavior than *, where DEFAULT would be honored for missing columns, so I have adjusted insert into to use DEFAULT instead. Also, noticed that at some point I lost my config that made the append tests actually test append, so added that back. The second half of the 'append columns' test for the append strategy validates that DEFAULT is used and does not break.

Checklist

  • 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
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

@benc-db benc-db merged commit 3f2e84b into main Mar 6, 2024
18 checks passed
@@ -60,7 +60,7 @@
{%- if dest_col in source_columns -%}
{%- do common_columns.append(dest_col) -%}
{%- else -%}
{%- do common_columns.append('NULL') -%}
{%- do common_columns.append('DEFAULT') -%}

Choose a reason for hiding this comment

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

Hi,
This seems to be a breaking change, "NULL" (String value) or "DEFAULT" (String value) won't solve the purpose. For all the unmatched columns, we will end up having multiple "DEFAULT" (String) values as columns that can raise conflict/ambiguous column error.

Default value works when we don't pass the column in the argument of insert statement. Could you please try this simple resolution:

{%- set common_columns_csv = set(source_columns).intersection(dest_columns) | sort | join(', ') -%}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good call

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They're not inserted as strings, but as literals.

Example from test run:

insert into table `peco`.`test17110372962014884605_test_incremental_on_schema_change`.`incremental_append_new_columns_remove_one` (`id`, `field1`, `field2`, `field3`, `field4`)
select `id`, `field1`, DEFAULT, `field3`, `field4` from `incremental_append_new_columns_remove_one__dbt_tmp`

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.

None yet

2 participants