dbt-labs / dbt-labs/dbt-adapters
[Feature] Not able to reference _TABLE_SUFFIX column in limited queries of wildcard table sources
- Dominant language
- Python
- Stars
- 233
- Forks
- 362
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 9
Description
### Is this a new bug?
- [x] I believe this is a new bug
- [x] I have searched the existing issues, and I could not find an existing issue for this bug
### Which packages are affected?
- [ ] dbt-adapters
- [ ] dbt-tests-adapter
- [ ] dbt-athena
- [ ] dbt-athena-community
- [x] dbt-bigquery
- [ ] dbt-postgres
- [ ] dbt-redshift
- [ ] dbt-snowflake
- [ ] dbt-spark
### Current Behavior
When running `dbt run` with the `--empty` flag [wildcard tables](https://cloud.google.com/bigquery/docs/querying-wildcard-tables) aren't able to reference the `_TABLE_SUFFIX` column. This is because the `_TABLE_SUFFIX` isn't implicitly passed through with the `select *`.
For example,
```
select
*,
_TABLE_SUFFIX as table_suffix
from {{ source('sharded_table') }}
where length(_TABLE_SUFFIX) = 8
```
compiles to,
```
select
*,
_TABLE_SUFFIX as table_suffix
from (select * from `project`.`dataset`.`sharded_table_*` where false limit 0)
where length(_TABLE_SUFFIX) = 8
```
### Expected Behavior
If the table id ends in a *, the adapter should pass through the table suffix column for limited queries.
```
select
*,
_TABLE_SUFFIX as table_suffix
from (select *, _TABLE_SUFFIX from `project`.`dataset`.`sharded_table_*` where false limit 0)
where length(_TABLE_SUFFIX) = 8
```
### Steps To Reproduce
1. Create a source with a wildcard table.
2. Reference it in a model and attempt to query the `_TABLE_SUFFIX` column. This query should build with `dbt build `.
3. Now try `dbt build --empty`. You'll hit an error: `Unrecognized name: _TABLE_SUFFIX at ...`.
### Relevant log output
```shell
```
### Environment
```markdown
- OS: Linux (6.5.0-1025-azure)
- Python: Python 3.11.8
- dbt: 1.9.2
- dbt-adapters:
- bigquery: 1.9.1
```
### Additional Context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.