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

Nfiann-prehook-emptyflag #6228

Open
wants to merge 23 commits into
base: current
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3f7349e
Created snippet file
nataliefiann Oct 2, 2024
f01188f
created snippet
nataliefiann Oct 2, 2024
dd354e0
Updated snippets file, reworded build file, and added reusable snipper
nataliefiann Oct 3, 2024
c3e578d
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
222d8aa
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
290defa
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
b7f20a0
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
98cc86c
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
7dbe42a
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
7492b0e
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
3610480
Merge branch 'current' into nfiann-prehook-emptyflag
nataliefiann Oct 3, 2024
37b9c02
Updated render method
nataliefiann Oct 3, 2024
f4b5183
Merge branch 'nfiann-prehook-emptyflag' of https://github.com/dbt-lab…
nataliefiann Oct 3, 2024
cb0e4b9
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
c1d859c
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
6b26b37
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
9d746ca
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
e1a218a
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
b6f6a1b
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
15dd0f2
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
676f4c7
Update website/snippets/_render-method.md
nataliefiann Oct 3, 2024
d349512
Merge branch 'current' into nfiann-prehook-emptyflag
mirnawong1 Oct 3, 2024
55666c1
Merge branch 'current' into nfiann-prehook-emptyflag
mirnawong1 Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions website/docs/reference/commands/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,9 @@ In DAG order, for selected resources or an entire project.

The `build` command supports the `--empty` flag for building schema-only dry runs. The `--empty` flag limits the refs and sources to zero rows. dbt will still execute the model SQL against the target data warehouse but will avoid expensive reads of input data. This validates dependencies and ensures your models will build properly.

#### SQL compilation error when running the `--empty` flag on a model

If you encounter the error: `SQL compilation error: syntax error line 1 at position 21 unexpected '('.` when running a model with the `--empty` flag, explicitly call the `.render()` method on that relation.


<File name='models.sql'>

```Jinja

-- models/staging/stg_sys__customers.sql
{{ config(
pre_hook = [
"alter external table {{ source('sys', 'customers').render() }} refresh"
]
) }}

with cus as (
select * from {{ source("sys", "customers") }} -- leave this as is!
)

select * from cus

```

</File>
import SQLCompilationError from '/snippets/_render-method.md';

<SQLCompilationError />

## Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Pre- and post-hooks can also call macros that return SQL statements. If your mac

dbt aims to provide all the boilerplate SQL you need (DDL, DML, and DCL) via out-of-the-box functionality, which you can configure quickly and concisely. In some cases, there may be SQL that you want or need to run, specific to functionality in your data platform, which dbt does not (yet) offer as a built-in feature. In those cases, you can write the exact SQL you need, using dbt's compilation context, and pass it into a `pre-` or `post-` hook to run before or after your model, seed, or snapshot.

import SQLCompilationError from '/snippets/_render-method.md';

<SQLCompilationError />

## Examples

<Snippet path="hooks-to-grants" />
Expand Down
17 changes: 17 additions & 0 deletions website/snippets/_render-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#### The render method

The `.render()` method is generally used to resolve or evaluate Jinja expressions (such as `{{ source(...) }}`) during runtime. When a pre-hook or post-hook contains a dynamic reference, such as a table or column, dbt might not automatically resolve the reference correctly, particularly when certain flags (such as `--empty`) are applied.
Copy link
Contributor

Choose a reason for hiding this comment

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

sugg removing the first paragraph to simplify the explanation since the 2nd paragraph already covers the key point about using .render() with the --empty flag


When using the `--empty flag`, dbt may skip processing `ref()` or `source()` for optimization. To avoid compilation errors and to explicitly tell dbt to process a specific relation (`ref()` or `source()`), use the `.render()` method in your model file. For example:


<File name='models.sql'>

```Jinja
{{ config(
pre_hook = [
"alter external table {{ source('sys', 'customers').render() }} refresh"
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
]
```

</File>
Loading