Skip to content

Support incremental_strategy parameter and new insert_overwrite strategy#2195

Open
SuchodolskiEdvin wants to merge 1 commit into
mainfrom
insert_overwrite_incremental_strategy
Open

Support incremental_strategy parameter and new insert_overwrite strategy#2195
SuchodolskiEdvin wants to merge 1 commit into
mainfrom
insert_overwrite_incremental_strategy

Conversation

@SuchodolskiEdvin

Copy link
Copy Markdown
Collaborator
  • updated proto with new parameters
  • added new tests
  • added validation for chosen incremental_strategies
  • added new insert_overwrite strategy logic

@SuchodolskiEdvin SuchodolskiEdvin requested a review from a team as a code owner June 2, 2026 14:39
@SuchodolskiEdvin SuchodolskiEdvin requested review from zaptot and removed request for a team June 2, 2026 14:39
@SuchodolskiEdvin SuchodolskiEdvin force-pushed the insert_overwrite_incremental_strategy branch from 9f72a8c to 9724071 Compare June 2, 2026 15:13
@SuchodolskiEdvin SuchodolskiEdvin requested review from kolina and removed request for zaptot June 3, 2026 09:56
@SuchodolskiEdvin SuchodolskiEdvin force-pushed the insert_overwrite_incremental_strategy branch from 9724071 to 41d152d Compare June 3, 2026 13:46
const backtickedColumns = columns.map(column => `\`${column}\``);
const resolveTargetTable = this.resolveTarget(target);

return `CREATE OR REPLACE TEMP TABLE \`${stagingTableUnqualified}\` AS (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you split separate SQL statements into granular Task.statement calls?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe we can't split this SQL because we are using TEMP table. We could in case we would use persistent table.

MERGE ${resolveTargetTable} T
USING \`${stagingTableUnqualified}\` S
ON FALSE
WHEN NOT MATCHED BY SOURCE AND ${partitionBy} IN UNNEST(partitions_for_replacement) ${updatePartitionFilter ? `and T.${updatePartitionFilter}` : ""} THEN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Such code T.${updatePartitionFilter} will only work when updatePartitionFilter has exactly one expression?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are correct. It is a known limitation that T.${updatePartitionFilter} only works for simple expressions (and fails on multi-expression SQL). Current implementation is designed to match the existing behavior of the standard MERGE strategy to maintain consistency between the two strategies for now. The fix of using updatePartitionFilter with several expression will be introduced in a separate PR.

Comment thread cli/api/dbadapters/execution_sql.ts Outdated
Comment on lines +511 to +514
return this.mergeInto(
table.target,
columns,
incrementalQuery,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you deduplicate this with a call below?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread core/actions/incremental_table.ts Outdated
Comment on lines +222 to +243
switch (this.proto.incrementalStrategy) {
case dataform.IncrementalStrategy.INSERT_OVERWRITE:
if (!this.proto.bigquery || !this.proto.bigquery.partitionBy) {
this.session.compileError(
new Error("incrementalStrategy 'insert_overwrite' requires 'partitionBy' to be set."),
config.filename,
this.proto.target
);
}
break;
case dataform.IncrementalStrategy.MERGE:
if (!this.proto.uniqueKey || this.proto.uniqueKey.length === 0) {
this.session.compileError(
new Error("incrementalStrategy 'merge' requires 'uniqueKey' to be set."),
config.filename,
this.proto.target
);
}
break;
default:
break;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's move it into sub-function for readability

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment thread core/actions/incremental_table_test.ts Outdated
Comment on lines +1017 to +1019
expect(result.compile.compiledGraph.tables[0].incrementalStrategy).equals(
dataform.IncrementalStrategy.INSERT_OVERWRITE
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's check the whole object here (same below)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread protos/configs.proto Outdated
string reservation = 27;

// Optional. The incremental strategy to use when updating the table.
// Defaults to MERGE if uniqueKey is configured, or APPEND otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't include it into config protos (because it's run-time strategy and not related to compiled DAG generation)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@SuchodolskiEdvin SuchodolskiEdvin force-pushed the insert_overwrite_incremental_strategy branch 3 times, most recently from 277c48b to f11f8f3 Compare June 8, 2026 12:35
- updated proto with new parameters
- added new tests
- added validation for chosen incremental_strategies
- added new insert_overwrite strategy logic
@SuchodolskiEdvin SuchodolskiEdvin force-pushed the insert_overwrite_incremental_strategy branch from f11f8f3 to 1942a72 Compare June 8, 2026 16:29
@SuchodolskiEdvin SuchodolskiEdvin requested a review from kolina June 10, 2026 09:04
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