dbt-labs / dbt-labs/dbt

[BUG] `LAG()` / `LEAD()` with `IGNORE NULLS` modifier not supported by static analysis parser

Open
#14,559 0 comments 0 reactions 0 assignees View on GitHub
area:static-analysis engine:v2 status:needs-repro status:triage type:bug
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

## Describe the bug

Fusion's SQL parser fails to parse the `IGNORE NULLS` (or `RESPECT NULLS`) modifier when used as an inline argument to `LAG()` or `LEAD()` window functions. This results in a `dbt1070` warning:

```
warning: dbt1070: Syntax error after rendering with introspection (see docs.getdbt.com/docs/fusion/new-concepts):
no viable alternative at input 'LAG(
CASE
WHEN routes.transaction_response_status_code IN ('P', 'D', 'A', 'S')
THEN routes.transaction_response_status_code
END,
1
IGNORE'
--> models/intermediate/isp/int_isp__routes.sql:175:17 (target/compiled/models/intermediate/isp/int_isp__routes.sql:170:17)
```

The SQL pattern that triggers this:

```sql
LAG(
CASE
WHEN routes.transaction_response_status_code IN ('P', 'D', 'A', 'S')
THEN routes.transaction_response_status_code
END,
1
IGNORE NULLS
) OVER (...)
```

`IGNORE NULLS` / `RESPECT NULLS` as an inline modifier to `LAG` / `LEAD` is valid SQL and supported by multiple warehouses (Snowflake, BigQuery, Redshift, etc.). dbt Core compiles and runs this successfully.

**What version of dbt Fusion is this bug in? (find out by running `dbt --version`)**

_(Please provide your version)_

**Is this a discrepancy between the dbt Fusion Engine and dbt Core? Check one.**
- [x] YES
- [ ] NO

## To Reproduce

Use a model with a `LAG()` or `LEAD()` call that includes the `IGNORE NULLS` modifier as an inline argument:

```sql
SELECT
LAG(
CASE
WHEN status IN ('A', 'B') THEN status
END,
1
IGNORE NULLS
) OVER (PARTITION BY id ORDER BY created_at) AS prev_status
FROM my_table
```

Run `dbt compile` and observe the `dbt1070` warning.

## Expected behavior

Fusion's SQL parser should recognize `IGNORE NULLS` / `RESPECT NULLS` as a valid modifier on `LAG()` / `LEAD()` window functions and not raise a syntax error.

## Workaround

Set `static_analysis: off` on the affected model to suppress the warning:

```yaml
models:
your_project:
path_to_model:
model_name:
+static_analysis: off
```

## Operating System and CPU Type

_(Please provide your OS and CPU type)_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.