Skip to content

Conversation

@GuyEshdat
Copy link
Contributor

@GuyEshdat GuyEshdat commented Dec 2, 2025

…nds because redshift started to throw errors when executing it as one command

Summary by CodeRabbit

  • New Features
    • Added Redshift support for combined delete-and-insert operations that can conditionally run delete and/or insert steps, improving data manipulation efficiency and aligning behavior with other supported engines.

✏️ Tip: You can customize this high-level summary in your review settings.

…nds because redshift started to throw errors when executing it as one command
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

👋 @GuyEshdat
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@coderabbitai
Copy link

coderabbitai bot commented Dec 2, 2025

Walkthrough

A new Redshift-specific public macro redshift__get_delete_and_insert_queries was added to assemble and return a list of delete and/or insert SQL queries based on the provided relation, insert_relation, delete_relation, and delete_column_key parameters.

Changes

Cohort / File(s) Summary
Redshift delete-and-insert macro
macros/utils/table_operations/delete_and_insert.sql
Added public macro redshift__get_delete_and_insert_queries(relation, insert_relation, delete_relation, delete_column_key). Initializes a queries list, conditionally appends a delete query when delete_relation is provided, conditionally appends an insert query when insert_relation is provided, and returns the assembled queries list.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check macro name and signature for consistency with other engine-specific macros.
  • Verify conditional branches produce correct SQL and handle null/empty inputs.
  • Confirm return format (list of queries) matches callers' expectations.

Poem

🐰 I hopped in the schema, neat and spry,

Built queries that dance and never lie.
Delete then insert — a rhythmic beat,
Rows tumble out and new ones meet.
A tiny rabbit's tidy feat. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change - splitting DELETE and INSERT operations in Redshift into separate commands, which matches the core objective in the PR description.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch redshit-delete-and-insert-fix

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5c1f532 and 941bf17.

📒 Files selected for processing (1)
  • macros/utils/table_operations/delete_and_insert.sql (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: haritamar
Repo: elementary-data/dbt-data-reliability PR: 825
File: macros/utils/cross_db_utils/incremental_strategy.sql:13-15
Timestamp: 2025-10-05T16:25:01.719Z
Learning: In macros/utils/cross_db_utils/incremental_strategy.sql, the get_default_incremental_strategy() macro and its adapter-specific variants are used exclusively for Elementary's internal dbt artifact tables, all of which have unique keys defined. Therefore, defaulting to "merge" strategy for Redshift (and other adapters) is safe in this context.
📚 Learning: 2025-10-05T16:25:01.719Z
Learnt from: haritamar
Repo: elementary-data/dbt-data-reliability PR: 825
File: macros/utils/cross_db_utils/incremental_strategy.sql:13-15
Timestamp: 2025-10-05T16:25:01.719Z
Learning: In macros/utils/cross_db_utils/incremental_strategy.sql, the get_default_incremental_strategy() macro and its adapter-specific variants are used exclusively for Elementary's internal dbt artifact tables, all of which have unique keys defined. Therefore, defaulting to "merge" strategy for Redshift (and other adapters) is safe in this context.

Applied to files:

  • macros/utils/table_operations/delete_and_insert.sql
📚 Learning: 2025-08-10T11:28:43.632Z
Learnt from: GuyEshdat
Repo: elementary-data/dbt-data-reliability PR: 838
File: macros/utils/table_operations/insert_rows.sql:156-0
Timestamp: 2025-08-10T11:28:43.632Z
Learning: In the Elementary dbt-data-reliability codebase, the `dremio__escape_special_chars` macro in `macros/utils/table_operations/insert_rows.sql` receives strings where single quotes are already escaped as `\'` from upstream processing. The macro correctly converts these to Dremio's SQL escaping format by replacing `\'` with `''`. This is different from other database implementations that handle bare single quotes directly.

Applied to files:

  • macros/utils/table_operations/delete_and_insert.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (fusion, snowflake) / test
🔇 Additional comments (2)
macros/utils/table_operations/delete_and_insert.sql (2)

113-113: ✓ Critical typo from previous review has been corrected.

The macro name is now correctly spelled as redshift__get_delete_and_insert_queries instead of redshit__. The dispatcher on line 37 will now correctly discover this Redshift-specific implementation, allowing Redshift to use separate query execution instead of the default transaction wrapper.


113-134: Macro logic correctly returns delete and insert as separate queries.

The implementation properly:

  • Initializes a queries list
  • Conditionally appends delete and insert queries based on provided relations
  • Returns the list for separate execution by the caller (lines 21-23)

This mirrors the established patterns used by Athena, Dremio, and Trino adapters and achieves the PR objective of executing DELETE and INSERT as independent commands.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 15c3290 and 5c1f532.

📒 Files selected for processing (1)
  • macros/utils/table_operations/delete_and_insert.sql (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: haritamar
Repo: elementary-data/dbt-data-reliability PR: 825
File: macros/utils/cross_db_utils/incremental_strategy.sql:13-15
Timestamp: 2025-10-05T16:25:01.719Z
Learning: In macros/utils/cross_db_utils/incremental_strategy.sql, the get_default_incremental_strategy() macro and its adapter-specific variants are used exclusively for Elementary's internal dbt artifact tables, all of which have unique keys defined. Therefore, defaulting to "merge" strategy for Redshift (and other adapters) is safe in this context.
📚 Learning: 2025-10-05T16:25:01.719Z
Learnt from: haritamar
Repo: elementary-data/dbt-data-reliability PR: 825
File: macros/utils/cross_db_utils/incremental_strategy.sql:13-15
Timestamp: 2025-10-05T16:25:01.719Z
Learning: In macros/utils/cross_db_utils/incremental_strategy.sql, the get_default_incremental_strategy() macro and its adapter-specific variants are used exclusively for Elementary's internal dbt artifact tables, all of which have unique keys defined. Therefore, defaulting to "merge" strategy for Redshift (and other adapters) is safe in this context.

Applied to files:

  • macros/utils/table_operations/delete_and_insert.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (latest_official, bigquery) / test

@GuyEshdat GuyEshdat merged commit d38c883 into master Dec 3, 2025
60 of 61 checks passed
@GuyEshdat GuyEshdat deleted the redshit-delete-and-insert-fix branch December 3, 2025 08:30
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