From 27b513e6e85ecf4f47b7901dba46038ee4760bf6 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 15 Feb 2024 17:29:48 +0000 Subject: [PATCH 01/19] addd expandables --- website/docs/docs/build/custom-aliases.md | 3 +++ website/docs/docs/build/custom-databases.md | 4 ++++ website/docs/docs/build/custom-schemas.md | 9 ++++++--- website/docs/docs/build/jinja-macros.md | 3 +++ website/snippets/_whitespace-control.md | 7 +++++++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 website/snippets/_whitespace-control.md diff --git a/website/docs/docs/build/custom-aliases.md b/website/docs/docs/build/custom-aliases.md index b4962aad00a..2837e6d511a 100644 --- a/website/docs/docs/build/custom-aliases.md +++ b/website/docs/docs/build/custom-aliases.md @@ -127,6 +127,9 @@ The default implementation of `generate_alias_name` simply uses the supplied `al +import WhitespaceControl from '/snippets/_whitespace-control.md'; + + ### Dispatch macro - SQL alias management for databases and dbt packages diff --git a/website/docs/docs/build/custom-databases.md b/website/docs/docs/build/custom-databases.md index dd54d6998e8..3ffd8ae3354 100644 --- a/website/docs/docs/build/custom-databases.md +++ b/website/docs/docs/build/custom-databases.md @@ -85,6 +85,10 @@ The default implementation of `generate_database_name` simply uses the supplied +import WhitespaceControl from '/snippets/_whitespace-control.md'; + + + ### Managing different behaviors across packages diff --git a/website/docs/docs/build/custom-schemas.md b/website/docs/docs/build/custom-schemas.md index 24cd4194a1c..02324fadb0b 100644 --- a/website/docs/docs/build/custom-schemas.md +++ b/website/docs/docs/build/custom-schemas.md @@ -84,6 +84,10 @@ The following code represents the default macro's logic: {%- endmacro %} ``` +import WhitespaceControl from '/snippets/_whitespace-control.md'; + + + ## Changing the way dbt generates a schema name If your dbt project has a custom macro called `generate_schema_name`, dbt will use it instead of the default macro. This allows you to customize the name generation according to your needs. @@ -92,8 +96,7 @@ To customize this macro, copy the example code in the section [How does dbt gene Be careful. dbt will ignore any custom `generate_schema_name` macros included in installed packages. -
-❗️ Warning: Don't replace default_schema in the macro. + If you're modifying how dbt generates schema names, don't just replace ```{{ default_schema }}_{{ custom_schema_name | trim }}``` with ```{{ custom_schema_name | trim }}``` in the ```generate_schema_name``` macro. @@ -119,7 +122,7 @@ If you remove ```{{ default_schema }}```, it causes developers to override each ``` -
+ ### generate_schema_name arguments diff --git a/website/docs/docs/build/jinja-macros.md b/website/docs/docs/build/jinja-macros.md index ea60c7d48e0..cb839aa089c 100644 --- a/website/docs/docs/build/jinja-macros.md +++ b/website/docs/docs/build/jinja-macros.md @@ -124,6 +124,9 @@ from app_data.payments +import WhitespaceControl from '/snippets/_whitespace-control.md'; + + ### Using a macro from a package A number of useful macros have also been grouped together into [packages](/docs/build/packages) — our most popular package is [dbt-utils](https://hub.getdbt.com/dbt-labs/dbt_utils/latest/). diff --git a/website/snippets/_whitespace-control.md b/website/snippets/_whitespace-control.md new file mode 100644 index 00000000000..9b696447aa7 --- /dev/null +++ b/website/snippets/_whitespace-control.md @@ -0,0 +1,7 @@ + + + +When you're changing macros, like the `generate_schema_name` macro, in your project — you might notice extra white space in your code in the `target/compiled` folder. + +You can use Jinja's [whitespace control](/faqs/Jinja/jinja-whitespace) using a minus sign `(-)` to tidy that up and remove unwanted spaces/lines. For example, use `{{- ... -}}` or `{%- ... %}` around your macro definitions( such as `{%- macro generate_schema_name(...) -%} ... {%- endmacro -%}`). + From e7dad3eb8463debb28472ec90904e5fa907a8e6e Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 15 Feb 2024 17:31:34 +0000 Subject: [PATCH 02/19] update --- website/snippets/_whitespace-control.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/snippets/_whitespace-control.md b/website/snippets/_whitespace-control.md index 9b696447aa7..d9fc88a1645 100644 --- a/website/snippets/_whitespace-control.md +++ b/website/snippets/_whitespace-control.md @@ -1,7 +1,7 @@ -When you're changing macros, like the `generate_schema_name` macro, in your project — you might notice extra white space in your code in the `target/compiled` folder. +When you're changing macros, like the `generate_schema_name`, in your project — you might notice extra white space in your code in the `target/compiled` folder. -You can use Jinja's [whitespace control](/faqs/Jinja/jinja-whitespace) using a minus sign `(-)` to tidy that up and remove unwanted spaces/lines. For example, use `{{- ... -}}` or `{%- ... %}` around your macro definitions( such as `{%- macro generate_schema_name(...) -%} ... {%- endmacro -%}`). +You can use Jinja's [whitespace control](/faqs/Jinja/jinja-whitespace) using a minus sign `(-)` to tidy that up and remove unwanted spaces/lines. For example, use `{{- ... -}}` or `{%- ... %}` around your macro definitions (such as `{%- macro generate_schema_name(...) -%} ... {%- endmacro -%}`). From 024116196698813c67e382d561ac7f91294d6b0c Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:34:19 +0000 Subject: [PATCH 03/19] Update website/snippets/_whitespace-control.md Co-authored-by: Ly Nguyen <107218380+nghi-ly@users.noreply.github.com> --- website/snippets/_whitespace-control.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/snippets/_whitespace-control.md b/website/snippets/_whitespace-control.md index d9fc88a1645..3c3e298dd92 100644 --- a/website/snippets/_whitespace-control.md +++ b/website/snippets/_whitespace-control.md @@ -3,5 +3,5 @@ When you're changing macros, like the `generate_schema_name`, in your project — you might notice extra white space in your code in the `target/compiled` folder. -You can use Jinja's [whitespace control](/faqs/Jinja/jinja-whitespace) using a minus sign `(-)` to tidy that up and remove unwanted spaces/lines. For example, use `{{- ... -}}` or `{%- ... %}` around your macro definitions (such as `{%- macro generate_schema_name(...) -%} ... {%- endmacro -%}`). +You can remove unwanted spaces and lines with Jinja's [whitespace control](/faqs/Jinja/jinja-whitespace) by using a minus sign. For example, use `{{- ... -}}` or `{%- ... %}` around your macro definitions (such as `{%- macro generate_schema_name(...) -%} ... {%- endmacro -%}`). From 5e7c7b141e9d8e636de5546f5306e48c4538b131 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Mon, 19 Feb 2024 10:57:32 +0000 Subject: [PATCH 04/19] tweaks --- website/docs/docs/build/custom-schemas.md | 4 +++- website/snippets/_whitespace-control.md | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/website/docs/docs/build/custom-schemas.md b/website/docs/docs/build/custom-schemas.md index 02324fadb0b..970d782668b 100644 --- a/website/docs/docs/build/custom-schemas.md +++ b/website/docs/docs/build/custom-schemas.md @@ -83,11 +83,13 @@ The following code represents the default macro's logic: {%- endmacro %} ``` +
import WhitespaceControl from '/snippets/_whitespace-control.md'; + ## Changing the way dbt generates a schema name If your dbt project has a custom macro called `generate_schema_name`, dbt will use it instead of the default macro. This allows you to customize the name generation according to your needs. @@ -96,7 +98,7 @@ To customize this macro, copy the example code in the section [How does dbt gene Be careful. dbt will ignore any custom `generate_schema_name` macros included in installed packages. - + If you're modifying how dbt generates schema names, don't just replace ```{{ default_schema }}_{{ custom_schema_name | trim }}``` with ```{{ custom_schema_name | trim }}``` in the ```generate_schema_name``` macro. diff --git a/website/snippets/_whitespace-control.md b/website/snippets/_whitespace-control.md index 3c3e298dd92..c2f275ba9dd 100644 --- a/website/snippets/_whitespace-control.md +++ b/website/snippets/_whitespace-control.md @@ -1,7 +1,8 @@ +
+💡 Use Jinja's whitespace control to tidy your macros! - - -When you're changing macros, like the `generate_schema_name`, in your project — you might notice extra white space in your code in the `target/compiled` folder. +When you're modifying macros in your project, you might notice extra white space in your code in the `target/compiled` folder. You can remove unwanted spaces and lines with Jinja's [whitespace control](/faqs/Jinja/jinja-whitespace) by using a minus sign. For example, use `{{- ... -}}` or `{%- ... %}` around your macro definitions (such as `{%- macro generate_schema_name(...) -%} ... {%- endmacro -%}`). - + +
From 4da817cdb6d598d66d1e8791766e396c2471f545 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 21 Feb 2024 15:13:18 +0000 Subject: [PATCH 05/19] add new capability --- website/docs/docs/build/python-models.md | 41 ++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 3fe194a4cb7..dce26651204 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -153,6 +153,23 @@ with upstream_python_model as ( Referencing [ephemeral](/docs/build/materializations#ephemeral) models is currently not supported (see [feature request](https://github.com/dbt-labs/dbt-core/issues/7288)) ::: +Python models also support dynamic referencing of models and configurations within Python f-strings. This allows for more nuanced and dynamic model configurations directly within your Python code. For example: + + + +```python +# Previously, attempting to access a configuration value like this would result in None +print(f"{dbt.config.get('my_var')}") # Output before change: None + +# Now you can access the actual configuration value +# Assuming 'my_var' is configured to 5 for the current model +print(f"{dbt.config.get('my_var')}") # Output after change: 5 +``` + +This also means you can use `dbt.config.get()` within Python models, ensuring that configuration values are now effectively retrievable and usable within Python f-strings. + + + ## Configuring Python models Just like SQL models, there are three ways to configure Python models: @@ -173,7 +190,7 @@ def model(dbt, session): -There's a limit to how complex you can get with the `dbt.config()` method. It accepts _only_ literal values (strings, booleans, and numeric types). Passing another function or a more complex data structure is not possible. The reason is that dbt statically analyzes the arguments to `config()` while parsing your model without executing your Python code. If you need to set a more complex configuration, we recommend you define it using the [`config` property](/reference/resource-properties/config) in a YAML file. +There's a limit to how complex you can get with the `dbt.config()` method. It accepts _only_ literal values (strings, booleans, and numeric types) and [dynamic configuration](#dynamic-configurations). Passing another function or a more complex data structure is not possible. The reason is that dbt statically analyzes the arguments to `config()` while parsing your model without executing your Python code. If you need to set a more complex configuration, we recommend you define it using the [`config` property](/reference/resource-properties/config) in a YAML file. #### Accessing project context @@ -184,7 +201,7 @@ Out of the box, the `dbt` class supports: - Accessing the database location of the current model: `dbt.this()` (also: `dbt.this.database`, `.schema`, `.identifier`) - Determining if the current model's run is incremental: `dbt.is_incremental` -It is possible to extend this context by "getting" them via `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: +It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). The `dbt.config.get()` method now supports [dynamic access to configurations](#dynamic-configurations) within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: @@ -221,6 +238,26 @@ def model(dbt, session): +#### Dynamic configurations + +In addition to the existing methods of configuring Python models, you also have dynamic access to configuration values set with `dbt.config()` within Python models using f-strings. This expands the possibilities for custom logic and configuration management. + + + +```python +def model(dbt, session): + dbt.config(materialized="table") + + # Dynamic configuration access within Python f-strings, which allows for real-time retrieval and use of configuration values. + # Example: Dynamically accessing a configuration value + print(f"Dynamic config value: {dbt.config.get('my_var')}") + # Assuming 'my_var' is set to 5, this will print: Dynamic config value: 5 + +``` + + + + ### Materializations Python models support these materializations: From 800eb1941644b4452a8b0b79331094a26b331744 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:34:06 +0000 Subject: [PATCH 06/19] Update website/docs/docs/build/python-models.md --- website/docs/docs/build/python-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index dce26651204..663e6c90bc7 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -256,7 +256,7 @@ def model(dbt, session): ``` - +
### Materializations From ac8fea276b010d32d91ff3f5538f21fc23128cff Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:34:17 +0000 Subject: [PATCH 07/19] Update website/docs/docs/build/python-models.md --- website/docs/docs/build/python-models.md | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 663e6c90bc7..9cf0b584776 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -238,6 +238,7 @@ def model(dbt, session): + #### Dynamic configurations In addition to the existing methods of configuring Python models, you also have dynamic access to configuration values set with `dbt.config()` within Python models using f-strings. This expands the possibilities for custom logic and configuration management. From 196d9811e04a3dc64b3d3ec3ae77e351e576aa0a Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:36:05 +0000 Subject: [PATCH 08/19] Update website/docs/docs/build/python-models.md --- website/docs/docs/build/python-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 9cf0b584776..caf0034442f 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -169,7 +169,7 @@ print(f"{dbt.config.get('my_var')}") # Output after change: 5 This also means you can use `dbt.config.get()` within Python models, ensuring that configuration values are now effectively retrievable and usable within Python f-strings. - + ## Configuring Python models Just like SQL models, there are three ways to configure Python models: From 818b70c205c8da5180d87cf439dfb1e7bf57865f Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:36:10 +0000 Subject: [PATCH 09/19] Update website/docs/docs/build/python-models.md --- website/docs/docs/build/python-models.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index caf0034442f..57a1a97d59e 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -153,7 +153,9 @@ with upstream_python_model as ( Referencing [ephemeral](/docs/build/materializations#ephemeral) models is currently not supported (see [feature request](https://github.com/dbt-labs/dbt-core/issues/7288)) ::: -Python models also support dynamic referencing of models and configurations within Python f-strings. This allows for more nuanced and dynamic model configurations directly within your Python code. For example: + + +From dbt version 1.8, Python models also support dynamic referencing of models and configurations within Python f-strings. This allows for more nuanced and dynamic model configurations directly within your Python code. For example: From eb5bc1ab25a5c9368b9d21ca9063a262e71692a2 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:36:50 +0000 Subject: [PATCH 10/19] Update website/docs/docs/build/python-models.md --- website/docs/docs/build/python-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 57a1a97d59e..9e9447bb5a9 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -203,7 +203,7 @@ Out of the box, the `dbt` class supports: - Accessing the database location of the current model: `dbt.this()` (also: `dbt.this.database`, `.schema`, `.identifier`) - Determining if the current model's run is incremental: `dbt.is_incremental` -It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). The `dbt.config.get()` method now supports [dynamic access to configurations](#dynamic-configurations) within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: +It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). Starting from dbt v1.8, the `dbt.config.get()` method supports [dynamic access to configurations](#dynamic-configurations) within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: From 74edaa27f0ddb6893773306a5c8131284484f99b Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:09:51 +0000 Subject: [PATCH 11/19] Update python-models.md --- website/docs/docs/build/python-models.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 9e9447bb5a9..293b54f3456 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -172,6 +172,7 @@ This also means you can use `dbt.config.get()` within Python models, ensuring th + ## Configuring Python models Just like SQL models, there are three ways to configure Python models: @@ -192,7 +193,7 @@ def model(dbt, session): -There's a limit to how complex you can get with the `dbt.config()` method. It accepts _only_ literal values (strings, booleans, and numeric types) and [dynamic configuration](#dynamic-configurations). Passing another function or a more complex data structure is not possible. The reason is that dbt statically analyzes the arguments to `config()` while parsing your model without executing your Python code. If you need to set a more complex configuration, we recommend you define it using the [`config` property](/reference/resource-properties/config) in a YAML file. +There's a limit to how complex you can get with the `dbt.config()` method. It accepts _only_ literal values (strings, booleans, and numeric types) and dynamic configuration. Passing another function or a more complex data structure is not possible. The reason is that dbt statically analyzes the arguments to `config()` while parsing your model without executing your Python code. If you need to set a more complex configuration, we recommend you define it using the [`config` property](/reference/resource-properties/config) in a YAML file. #### Accessing project context @@ -203,7 +204,7 @@ Out of the box, the `dbt` class supports: - Accessing the database location of the current model: `dbt.this()` (also: `dbt.this.database`, `.schema`, `.identifier`) - Determining if the current model's run is incremental: `dbt.is_incremental` -It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). Starting from dbt v1.8, the `dbt.config.get()` method supports [dynamic access to configurations](#dynamic-configurations) within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: +It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). Starting from dbt v1.8, the `dbt.config.get()` method supports dynamic access to configurations within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: From 9edadc832062c97b6fc9cf20c41e89df36be110e Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:18:22 +0000 Subject: [PATCH 12/19] Update python-models.md --- website/docs/docs/build/python-models.md | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 293b54f3456..0ad189c2d62 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -242,6 +242,7 @@ def model(dbt, session): + #### Dynamic configurations In addition to the existing methods of configuring Python models, you also have dynamic access to configuration values set with `dbt.config()` within Python models using f-strings. This expands the possibilities for custom logic and configuration management. From 7dda31c6d6a249b59008b03c2b290ebeee1cfd87 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 11:45:49 +0000 Subject: [PATCH 13/19] Update python-models.md --- website/docs/docs/build/python-models.md | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 0ad189c2d62..cb86b7620d9 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -243,6 +243,7 @@ def model(dbt, session): + #### Dynamic configurations In addition to the existing methods of configuring Python models, you also have dynamic access to configuration values set with `dbt.config()` within Python models using f-strings. This expands the possibilities for custom logic and configuration management. From 9bb955b5cafde8f3beff31d9a9bb3d9812fb0e36 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:49:52 +0000 Subject: [PATCH 14/19] Update website/docs/docs/build/python-models.md Co-authored-by: Ly Nguyen <107218380+nghi-ly@users.noreply.github.com> --- website/docs/docs/build/python-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index cb86b7620d9..dfe163b5ed4 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -168,7 +168,7 @@ print(f"{dbt.config.get('my_var')}") # Output before change: None print(f"{dbt.config.get('my_var')}") # Output after change: 5 ``` -This also means you can use `dbt.config.get()` within Python models, ensuring that configuration values are now effectively retrievable and usable within Python f-strings. +This also means you can use `dbt.config.get()` within Python models to ensure that configuration values are effectively retrievable and usable within Python f-strings. From 5ba53aaff31eaf541909ef9598527b90e89563fb Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:50:13 +0000 Subject: [PATCH 15/19] Update website/docs/docs/build/python-models.md Co-authored-by: Ly Nguyen <107218380+nghi-ly@users.noreply.github.com> --- website/docs/docs/build/python-models.md | 1 - 1 file changed, 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index dfe163b5ed4..67614ca59e5 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -255,7 +255,6 @@ def model(dbt, session): dbt.config(materialized="table") # Dynamic configuration access within Python f-strings, which allows for real-time retrieval and use of configuration values. - # Example: Dynamically accessing a configuration value print(f"Dynamic config value: {dbt.config.get('my_var')}") # Assuming 'my_var' is set to 5, this will print: Dynamic config value: 5 From 6f2a07c9b29566f1a02d9a790237f2ec673feb4f Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:50:24 +0000 Subject: [PATCH 16/19] Update website/docs/docs/build/python-models.md Co-authored-by: Ly Nguyen <107218380+nghi-ly@users.noreply.github.com> --- website/docs/docs/build/python-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 67614ca59e5..802620cd757 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -204,7 +204,7 @@ Out of the box, the `dbt` class supports: - Accessing the database location of the current model: `dbt.this()` (also: `dbt.this.database`, `.schema`, `.identifier`) - Determining if the current model's run is incremental: `dbt.is_incremental` -It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). Starting from dbt v1.8, the `dbt.config.get()` method supports dynamic access to configurations within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values to power conditional logic in your model, we require setting them through a dedicated `.yml` file config: +It is possible to extend this context by "getting" them with `dbt.config.get()` after they are configured in the [model's config](/reference/model-configs). Starting from dbt v1.8, the `dbt.config.get()` method supports dynamic access to configurations within Python models, enhancing flexibility in model logic. This includes inputs such as `var`, `env_var`, and `target`. If you want to use those values for the conditional logic in your model, we require setting them through a dedicated YAML file config: From e14c5e47276cb74fbbd5cc8c6c4eed9eb4e006c0 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:50:31 +0000 Subject: [PATCH 17/19] Update website/docs/docs/build/python-models.md Co-authored-by: Ly Nguyen <107218380+nghi-ly@users.noreply.github.com> --- website/docs/docs/build/python-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index 802620cd757..dff34bb38bf 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -246,7 +246,7 @@ def model(dbt, session): #### Dynamic configurations -In addition to the existing methods of configuring Python models, you also have dynamic access to configuration values set with `dbt.config()` within Python models using f-strings. This expands the possibilities for custom logic and configuration management. +In addition to the existing methods of configuring Python models, you also have dynamic access to configuration values set with `dbt.config()` within Python models using f-strings. This increases the possibilities for custom logic and configuration management. From 7b49355b9b7c0a29f9176d126bae500a16e29977 Mon Sep 17 00:00:00 2001 From: Himanshu <141146043+Mckesson-Himanshu@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:27:47 +0530 Subject: [PATCH 18/19] Update unit-tests.md Grammar correction --- website/docs/docs/build/unit-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/unit-tests.md b/website/docs/docs/build/unit-tests.md index d91cbed73a0..9828788dd67 100644 --- a/website/docs/docs/build/unit-tests.md +++ b/website/docs/docs/build/unit-tests.md @@ -15,7 +15,7 @@ For dbt Core, unit tests will be available in v1.8, planned for late April 2024. ::: -Historically, dbt's test coverage was confined to [“data” tests](/docs/build/data-tests), assessing the quality of input data or resulting datasets' structure. However, these tests could only be executed _after_ a building a model. +Historically, dbt's test coverage was confined to [“data” tests](/docs/build/data-tests), assessing the quality of input data or resulting datasets' structure. However, these tests could only be executed _after_ building a model. Now, we are introducing a new type of test to dbt - unit tests. In software programming, unit tests validate small portions of your functional code, and they work much the same way here. Unit tests allow you to validate your SQL modeling logic on a small set of static inputs _before_ you materialize your full model in production. Unit tests enable test-driven development, benefiting developer efficiency and code reliability. From db6bf1eb7d0be0fe11a1f6ee55f2627d9106abaa Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 23 Feb 2024 11:54:41 +0000 Subject: [PATCH 19/19] fold in feedback --- website/docs/docs/build/python-models.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/website/docs/docs/build/python-models.md b/website/docs/docs/build/python-models.md index dff34bb38bf..083ddd4473d 100644 --- a/website/docs/docs/build/python-models.md +++ b/website/docs/docs/build/python-models.md @@ -155,7 +155,7 @@ Referencing [ephemeral](/docs/build/materializations#ephemeral) models is curren -From dbt version 1.8, Python models also support dynamic referencing of models and configurations within Python f-strings. This allows for more nuanced and dynamic model configurations directly within your Python code. For example: +From dbt version 1.8, Python models also support dynamic configurations within Python f-strings. This allows for more nuanced and dynamic model configurations directly within your Python code. For example: @@ -242,7 +242,6 @@ def model(dbt, session): - #### Dynamic configurations @@ -254,10 +253,10 @@ In addition to the existing methods of configuring Python models, you also have def model(dbt, session): dbt.config(materialized="table") - # Dynamic configuration access within Python f-strings, which allows for real-time retrieval and use of configuration values. - print(f"Dynamic config value: {dbt.config.get('my_var')}") + # Dynamic configuration access within Python f-strings, + # which allows for real-time retrieval and use of configuration values. # Assuming 'my_var' is set to 5, this will print: Dynamic config value: 5 - + print(f"Dynamic config value: {dbt.config.get('my_var')}") ```