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

Add behavior change flag docs for adapter maintainers #6092

Merged
merged 6 commits into from
Sep 19, 2024

Conversation

mikealfare
Copy link
Contributor

@mikealfare mikealfare commented Sep 18, 2024

What are you changing in this pull request and why?

We added behavior flags for adapter maintainers to use on first- and third-party adapters. This PR adds documentation explaining how to configure and use behavior flags.

Checklist

  • I have reviewed the Content style guide so my content adheres to these guidelines.
  • The topic I'm writing about is for specific dbt version(s) and I have versioned it according to the version a whole page and/or version a block of content guidelines.
  • I have added checklist item(s) to this list for anything anything that needs to happen before this PR is merged, such as "needs technical review" or "change base branch."
  • Approval by Product (@amychen1776)

@mikealfare mikealfare self-assigned this Sep 18, 2024
@mikealfare mikealfare requested a review from a team as a code owner September 18, 2024 22:51
Copy link

vercel bot commented Sep 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs-getdbt-com ✅ Ready (Inspect) Visit Preview Sep 19, 2024 2:18pm

@github-actions github-actions bot added content Improvements or additions to content guides Knowledge best suited for Guides labels Sep 18, 2024
@mikealfare mikealfare linked an issue Sep 18, 2024 that may be closed by this pull request
1 task
@github-actions github-actions bot added the size: medium This change will take up to a week to address label Sep 18, 2024

Starting in `dbt-adapters==1.5.0` and `dbt-core==1.8.7`, adapter maintainers have the ability to implement their own behavior change flags.
For more information on what a behavior change is, please refer to [Behavior changes](https://docs.getdbt.com/reference/global-configs/behavior-changes).
To implement a behavior change flag, provide a name, a default setting (`True` / `False`), and optional source, and either a description or a link to the flag's documentation on docs.getdbt.com.
Copy link
Collaborator

@amychen1776 amychen1776 Sep 18, 2024

Choose a reason for hiding this comment

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

Suggested change
To implement a behavior change flag, provide a name, a default setting (`True` / `False`), and optional source, and either a description or a link to the flag's documentation on docs.getdbt.com.
To implement a behavior change flag, you will need to provide a name for the flag, a default setting (`True` / `False`), optional source, and a description and/or a link to the flag's documentation on docs.getdbt.com. We recommend having a description and documentation link whenever possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also what is source?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

source is basically a namespace. I would list the adapter as the source for adapter behavior flags. But the framework can be used elsewhere, so I don't force that. I also provide a default that takes the calling module, so that even if the maintainer does not add a source, there's still something that we can use to differentiate flags with the same name across multiple adapters (or not in an adapter at all). I wanted to try and automate it since it would feel silly to need to specify the adapter for every flag. We could probably be smarter than this and set it in BaseAdapter somehow when they get registered.


</File>

It's best practice to evaluate a behavior flag as few times as possible. This will make it easier to remove once the behavior change has matured.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's best practice to evaluate a behavior flag as few times as possible.

what does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't pepper the code with a bunch individual checks like it's a configuration. It should truly represent "a legacy way" and "a novel way".

The dbt-redshift example is a good one. Depending on whether we use the SDK or not, we either call the macro, or we call the SDK. We check the flag once.

In more complicated scenarios this may not be possible. Take Iceberg support for example. We need to check the flag in list relations and we also need to check it when creating a table in the create table macro. So we need to check it twice, there's really no way around that. But let's look at the create table macro in particular. We should just have two versions of that macro, the legacy version without Iceberg and the novel way with Iceberg; these are gated by the flag. That's good.

Using two completely different versions of the code will result in a lot of duplicated code though. Both versions need a name, they need to put the sql at the end, they have shared options like warehouse, etc. But there are multiple points where they differ as well. There are different config options like external_volume. One uses create table my_table as... and the other uses create iceberg table my_table as.... So there will be an intuitive push towards DRY code where you can embed a check inside the macro at each point where it differs. That's not good. The behavior flag is becoming part of the code, and can more easily contribute to bugs in the code, in particular in the legacy code which was supposed to be gated from this whole change in the first place.

Co-authored-by: Amy Chen <46451573+amychen1776@users.noreply.github.com>
Copy link
Collaborator

@amychen1776 amychen1776 left a comment

Choose a reason for hiding this comment

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

:shipit:

@matthewshaver matthewshaver merged commit b6351b1 into current Sep 19, 2024
6 checks passed
@matthewshaver matthewshaver deleted the content/adapter-maintain-behavior-flags branch September 19, 2024 14:21
@matthewshaver
Copy link
Contributor

Thank you @mikealfare !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content guides Knowledge best suited for Guides size: medium This change will take up to a week to address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update adapter maintainer docs for Behavior Flags
3 participants