dbt-labs / dbt-labs/dbt-utils

union should explicitly specify table name in casts

Open
#173 11 comments 0 reactions 0 assignees View on GitHub
bug nested Stale
Dominant language
Makefile
Stars
1.8k
Forks
632
PR merge metrics
No merged PRs in 30d

Description

Bigquery gets confused by tables that have a column with the same name in CASTs, and will try to cast the entire table instead of the column.

```
-- causes error, as foo is a struct
select cast(`foo` as STRING) as `foo`
from `data-playground-1234`.`myschema`.`foo`

-- works when table name is specified
select cast(`foo`.`foo` as STRING) as `foo`
from `data-playground-1234`.`myschema`.`foo`
```

I *think* this is a simple as adding `table.name` [here](https://github.com/fishtown-analytics/dbt-utils/blob/master/macros/sql/union.sql#L61), like:

``` {%- set col_name = adapter.quote(table.name) + '.' + adapter.quote(col_name) if col_name in table_columns[table] else 'null' %}```

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.