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 4 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 @@ -192,6 +192,10 @@ See: [Apache Spark docs on `ANALYZE TABLE`](https://spark.apache.org/docs/latest

</File>

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

<SQLCompilationError />
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

### Additional examples
We've compiled some more in-depth examples [here](/docs/build/hooks-operations#additional-examples).

Expand Down
27 changes: 27 additions & 0 deletions website/snippets/_render-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### The render method

If you encounter a SQL compilation error when running a model with the `--empty` flag, explicitly call the `.render()` method on that relation. The error occurs because dbt processes certain parts of the workflow differently when the `--empty flag` is used, leading to confusion when it encounters the table reference (`{{ source(...) }}`) in the pre-hook. The error you're seeing is a result of dbt not handling the reference as you anticipated.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

The recommended solution is to explicitly instruct dbt on how to interpret the reference in the pre-hook by using the `.render()` method. This approach ensures that dbt properly prepares the reference before executing it.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved


<File name='models.sql'>

```Jinja

-- models/staging/stg_sys__customers.sql
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
{{ config(
pre_hook = [
"alter external table {{ source('sys', 'customers').render() }} refresh"
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
]
) }}
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

with cus as (
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
select * from {{ source("sys", "customers") }} -- leave this as is!
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
)
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

select * from cus
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

```

</File>
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
Loading