aws-samples / aws-samples/dbt-glue

dbt build --empty fails when refs already have aliases

Open
#679 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
Python
Stars
147
Forks
96
Avg merge
7h 4m
Merged PRs (30d)
5

Description

### Describe the bug
This is a known issue with dbt-core whereby it generates SQL like this when the empty flag is used:

`{{ ref('table'}} as my_table`

`(select * from schema.table where false limit 0) _dbt_limit_subq_table as my_table`

This sql then fails on execution because of the multiple aliases.

Issue on dbt-adapters is here:
https://github.com/dbt-labs/dbt-adapters/issues/474

The fix suggested there was to update relation.py in affected adapters.

The fix applied on dbt-spark is here:
https://github.com/databricks/dbt-databricks/commit/796bc4a28832cfc72d847e08500454ef23662f05

### Steps To Reproduce
Create a SQL model as follows:

`select * from {{ ref('table'}} as my_table`

Then run:

dbt build --select table --empty

### Expected behavior
dbt build should complete without error

### System information
**The output of `dbt --version`:**
```
1.10.20
```

**The operating system you're using:**

Windows/Ubuntu/RHEL

**The output of `python --version`:**

Python 3.13.0

### Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start with relation.py in the affected adapter and reproduce the problem using the SQL model containing ref('table') as my_table, then run dbt build --select table --empty. Compare the generated SQL with the dbt-spark fix linked in the issue; done means the build completes without the duplicate-alias execution error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.