|
| 1 | +--- |
| 2 | +resource_types: [models] |
| 3 | +title: "static_analysis" |
| 4 | +description: "Use static_analysis config to control how the Fusion engine performs static SQL analysis for models." |
| 5 | +datatype: string |
| 6 | +default_value: on |
| 7 | +sidebar_label: "static_analysis" |
| 8 | +--- |
| 9 | + |
| 10 | +:::info |
| 11 | + |
| 12 | +The `static_analysis` config is available in the <Constant name="fusion_engine"/> only. It isn't available in <Constant name="core" /> and will be ignored. To upgrade to <Constant name="fusion"/>, refer to [Install <Constant name="fusion"/>](/docs/fusion/install-fusion). |
| 13 | + |
| 14 | +::: |
| 15 | + |
| 16 | +<Tabs> |
| 17 | + |
| 18 | +<TabItem value="dbt_project.yml" label="Project file"> |
| 19 | + |
| 20 | +<File name='dbt_project.yml'> |
| 21 | + |
| 22 | +```yml |
| 23 | +models: |
| 24 | + [resource-path](/reference/resource-configs/resource-path): |
| 25 | + +static_analysis: on | unsafe | off |
| 26 | + |
| 27 | +``` |
| 28 | + |
| 29 | +</File> |
| 30 | + |
| 31 | +</TabItem> |
| 32 | + |
| 33 | +<TabItem value="Property file"> |
| 34 | + |
| 35 | +<File name='models/filename.yml'> |
| 36 | + |
| 37 | +```yml |
| 38 | +models: |
| 39 | + - name: model_name |
| 40 | + [config](/reference/resource-properties/config): |
| 41 | + static_analysis: on | unsafe | off |
| 42 | +``` |
| 43 | +
|
| 44 | +</File> |
| 45 | +</TabItem> |
| 46 | +
|
| 47 | +<TabItem value="SQL config"> |
| 48 | +
|
| 49 | +<File name='models/model_name.sql'> |
| 50 | +
|
| 51 | +```sql |
| 52 | +{{ config(static_analysis='on' | 'unsafe' | 'off') }} |
| 53 | + |
| 54 | +select |
| 55 | + user_id, |
| 56 | + my_cool_udf(ip_address) as cleaned_ip |
| 57 | +from {{ ref('my_model') }} |
| 58 | +``` |
| 59 | + |
| 60 | +</File> |
| 61 | + |
| 62 | +</TabItem> |
| 63 | + |
| 64 | +</Tabs> |
| 65 | + |
| 66 | +## Definition |
| 67 | + |
| 68 | +You can configure if and when the <Constant name="fusion_engine" /> performs static SQL analysis for a model. Configure the `static_analysis` config in your `dbt_project.yml` file, model YAML file, or in the `config` block of your model file. Refer to [rendering strategies](/docs/fusion/new-concepts#rendering-strategies) for more information on how the <Constant name="fusion_engine" /> renders models. |
| 69 | + |
| 70 | +The following values are available for `static_analysis`: |
| 71 | + |
| 72 | +- `on`: Statically analyze SQL ahead-of-time (AOT). Default for non-introspective models, depends on AOT rendering. |
| 73 | +- `unsafe`: Statically analyze SQL just-in-time (JIT). The default for when a model (or any of its parents) uses introspective queries. JIT analysis still catches most SQL errors, but [analysis happens]( /docs/fusion/new-concepts#static-analysis-and-introspective-queries) after some upstream execution. |
| 74 | +- `off`: Skip SQL analysis for this model and its descendants. |
| 75 | + |
| 76 | +A model is _only_ eligible for static analysis if all of its parents are also eligible. |
| 77 | + |
| 78 | +Refer to the Fusion concepts page for deeper discussion and visuals: [New concepts](/docs/fusion/new-concepts). For more info on the JSON schema, refer to the [dbt-jsonschema file](https://github.com/dbt-labs/dbt-jsonschema/blob/1e2c1536fbdd421e49c8b65c51de619e3cd313ff/schemas/latest_fusion/dbt_project-latest-fusion.json#L4689). |
| 79 | + |
| 80 | +## CLI override |
| 81 | + |
| 82 | +You can override model-level configuration for a run using the following CLI flags. For example, to disable static analysis for a run: |
| 83 | + |
| 84 | +```bash |
| 85 | +dbt run --static-analysis off # disable static analysis for all models |
| 86 | +dbt run --static-analysis unsafe # use JIT analysis for all models |
| 87 | +``` |
| 88 | + |
| 89 | +See [static analysis CLI flag](/reference/global-configs/static-analysis-flag). |
| 90 | + |
| 91 | +## Examples |
| 92 | + |
| 93 | +The following examples show how to disable static analysis for all models in a package, for a single model, and for a model that uses a custom UDF. |
| 94 | + |
| 95 | +<!-- no toc --> |
| 96 | +- [Disable static analysis for all models in a package](#disable-static-analysis-for-all-models-in-a-package) |
| 97 | +- [Disable static analysis in YAML for a single model](#disable-static-analysis-in-yaml-for-a-single-model) |
| 98 | +- [Disable static analysis in SQL for a model using a custom UDF](#disable-static-analysis-in-sql-for-a-model-using-a-custom-udf) |
| 99 | + |
| 100 | +#### Disable static analysis for all models in a package |
| 101 | +This example shows how to disable static analysis for all models in a package. The [`+` prefix](/reference/resource-configs/plus-prefix) applies the config to all models in the package. |
| 102 | + |
| 103 | +<File name='dbt_project.yml'> |
| 104 | + |
| 105 | +```yml |
| 106 | +name: jaffle_shop |
| 107 | + |
| 108 | +models: |
| 109 | + jaffle_shop: |
| 110 | + marts: |
| 111 | + +materialized: table |
| 112 | + |
| 113 | + a_package_with_introspective_queries: |
| 114 | + +static_analysis: off |
| 115 | +``` |
| 116 | +
|
| 117 | +</File> |
| 118 | +
|
| 119 | +#### Disable static analysis in YAML for a single model |
| 120 | +
|
| 121 | +This example shows how to disable static analysis for a single model in YAML. |
| 122 | +
|
| 123 | +<File name='models/my_udf_using_model.yml'> |
| 124 | +
|
| 125 | +```yml |
| 126 | +models: |
| 127 | + - name: model_with_static_analysis_off |
| 128 | + config: |
| 129 | + static_analysis: off |
| 130 | +``` |
| 131 | +
|
| 132 | +</File> |
| 133 | +
|
| 134 | +#### Disable static analysis in SQL for a model using a custom UDF |
| 135 | +
|
| 136 | +This example shows how to disable static analysis for a model using a custom [user-defined function (UDF)](/docs/build/udfs) in a SQL file. |
| 137 | +
|
| 138 | +<File name='models/my_udf_using_model.sql'> |
| 139 | +
|
| 140 | +```sql |
| 141 | +{{ config(static_analysis='off') }} |
| 142 | + |
| 143 | +select |
| 144 | + user_id, |
| 145 | + my_cool_udf(ip_address) as cleaned_ip |
| 146 | +from {{ ref('my_model') }} |
| 147 | +``` |
| 148 | + |
| 149 | +</File> |
| 150 | + |
| 151 | +## Considerations |
| 152 | + |
| 153 | +- Disabling static analysis means that features of the VS Code extension that depend on SQL comprehension will be unavailable. |
| 154 | +- Static analysis might fail in some cases (for example, dynamic SQL constructs or unrecognized UDFs) and may require setting `static_analysis: off`. For more examples, refer to [When should I turn static analysis off?](/docs/fusion/new-concepts#when-should-i-turn-static-analysis-off). |
0 commit comments