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

Update incremental table execution to avoid create or replace #1712

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Ekrekr
Copy link
Contributor

@Ekrekr Ekrekr commented Apr 4, 2024

Fixes #1561

@Ekrekr Ekrekr requested a review from lewish April 4, 2024 10:53
}${options.length > 0 ? `OPTIONS(${options.join(",")})` : ""}as ${table.query}`;
let statement = "create ";
if (table.enumType !== dataform.TableType.INCREMENTAL) {
statement += "or replace ";
Copy link
Collaborator

Choose a reason for hiding this comment

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

From the bug - I think we still want to create or replace in the case that it is incremental AND it's not projected AND it's full refresh?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also add a test for this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is projected? Have added the full refresh.

This is tested, but not obviously, across

const expectedExecutionActions: dataform.IExecutionAction[] = [

Copy link
Collaborator

Choose a reason for hiding this comment

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

*protected!

Copy link
Contributor Author

@Ekrekr Ekrekr Apr 4, 2024

Choose a reason for hiding this comment

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

Ah right! Done.

I had to update the protected logic, such as removing the error that we test for here

test("trying to fully refresh a protected dataset fails", () => {
. But now it should act as the incremental spec suggests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, sorry I think this has got really confusing, a few thoughts.

  1. leave this method as createOrReplace and don't pass in run options or do all that logic.
  2. Add a createIfNotExists method next to it (they can share some private impl if you want, but I wouldn't bother)
  3. Update the logic in publishTasks, only for the incremental tables, to do what you want to do and call createIfNotExists by default, and createOrReplace only when !protected && fullRefresh

The original method was clear what it did, but now you've moved this logic into it, I'd say it's much harder to follow what's going on in publishTasks.

@Ekrekr Ekrekr requested a review from lewish April 4, 2024 15:48
@@ -74,10 +74,6 @@ export class Builder {
tableMetadata: dataform.ITableMetadata,
runConfig: dataform.IRunConfig
) {
if (table.protected && this.runConfig.fullRefresh) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep this?

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.

Generated incremental SQL when table does not exist should not do a create or replace
2 participants