-
Notifications
You must be signed in to change notification settings - Fork 128
fix: fix replace_table_data broken on multiple adapters (Trino, Redshift, etc.) #969
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
25e0be7
fix: fix replace_table_data for multiple adapters (Trino, Redshift, C…
devin-ai-integration[bot] 6529f15
fix: ClickHouse cluster-aware truncate + Redshift data-loss comment
devin-ai-integration[bot] 454756e
test: add integration test for replace_table_data
devin-ai-integration[bot] 28a3fd1
test: verify replace_table_data actually replaces data
devin-ai-integration[bot] acb51ff
test: add sentinel row assertion to prove replace-specific behavior
devin-ai-integration[bot] 113cfc6
fix: add adapter.commit() to sentinel INSERT for Vertica compatibility
devin-ai-integration[bot] d5bf278
fix: use raw SQL COMMIT instead of adapter.commit() for Vertica
devin-ai-integration[bot] 0ca0fd5
fix: only COMMIT on Vertica; Spark does not support bare COMMIT
devin-ai-integration[bot] f398d3e
fix: use dynamic column list for sentinel INSERT (Spark/Delta require…
devin-ai-integration[bot] aa60ec7
fix: COMMIT on all SQL adapters except Spark/Databricks/BigQuery/Athena
devin-ai-integration[bot] 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
39 changes: 39 additions & 0 deletions
39
integration_tests/dbt_project/macros/insert_sentinel_row.sql
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| {% macro insert_sentinel_row(table_name, sentinel_alias) %} | ||
| {#- Insert a sentinel row into the given Elementary table. | ||
| Used by integration tests to verify that replace_table_data | ||
| actually truncates the whole table (sentinel disappears) rather | ||
| than doing a diff-based update (sentinel would survive). | ||
|
|
||
| Dynamically reads the table's columns so that every column is | ||
| included in the INSERT (Spark / Delta Lake rejects partial | ||
| column lists). Columns not explicitly set get NULL. -#} | ||
| {% set relation = ref(table_name) %} | ||
| {% set columns = adapter.get_columns_in_relation(relation) %} | ||
|
|
||
| {% set col_names = [] %} | ||
| {% set col_values = [] %} | ||
| {% for col in columns %} | ||
| {% do col_names.append(col.name) %} | ||
| {% if col.name | lower == "unique_id" %} | ||
| {% do col_values.append("'test.sentinel'") %} | ||
| {% elif col.name | lower == "alias" %} | ||
| {% do col_values.append("'" ~ sentinel_alias ~ "'") %} | ||
| {% elif col.name | lower == "name" %} {% do col_values.append("'sentinel'") %} | ||
| {% else %} {% do col_values.append("NULL") %} | ||
| {% endif %} | ||
| {% endfor %} | ||
|
|
||
| {% do run_query( | ||
| "INSERT INTO " ~ relation ~ " (" ~ col_names | ||
| | join(", ") ~ ")" ~ " VALUES (" ~ col_values | ||
| | join(", ") ~ ")" | ||
| ) %} | ||
|
|
||
| {#- Most SQL adapters need an explicit COMMIT because run_query DML is | ||
| not auto-committed. Spark-based and serverless engines do not | ||
| support bare COMMIT statements, so we skip them. -#} | ||
| {% set no_commit_adapters = ["spark", "databricks", "bigquery", "athena"] %} | ||
| {% if target.type not in no_commit_adapters %} | ||
| {% do run_query("COMMIT") %} | ||
| {% endif %} | ||
| {% endmacro %} | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Escape
sentinel_aliasbefore embedding it in the SQL literal.run_operationpasses raw strings into the macro, so any alias containing'will produce invalid SQL here and make this helper flaky for future test cases.Proposed fix
{% macro insert_sentinel_row(table_name, sentinel_alias) %} {`#-` Insert a sentinel row into the given Elementary table. Used by integration tests to verify that replace_table_data actually truncates the whole table (sentinel disappears) rather than doing a diff-based update (sentinel would survive). -#} {% set relation = ref(table_name) %} + {% set escaped_sentinel_alias = sentinel_alias | replace("'", "''") %} {% do run_query( "INSERT INTO " ~ relation ~ " (unique_id, alias, name)" - " VALUES ('test.sentinel', '" ~ sentinel_alias ~ "', 'sentinel')" + " VALUES ('test.sentinel', '" ~ escaped_sentinel_alias ~ "', 'sentinel')" ) %} {% endmacro %}📝 Committable suggestion
🤖 Prompt for AI Agents