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

union should explicitly specify table name in casts #173

Open
wearpants opened this issue Nov 6, 2019 · 3 comments · May be fixed by wearpants/dbt-utils#1

Comments

@wearpants
Copy link

@wearpants wearpants commented Nov 6, 2019

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, like:

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

@clausherther

This comment has been minimized.

Copy link
Contributor

@clausherther clausherther commented Nov 6, 2019

I would think that's a general problem with BigQuery and would have to be addressed everywhere you cast a column, not just in this macro? The other obvious "fix" is to not have columns with the same name as a table?

@wearpants

This comment has been minimized.

Copy link
Author

@wearpants wearpants commented Nov 6, 2019

@wearpants

This comment has been minimized.

Copy link
Author

@wearpants wearpants commented Nov 6, 2019

wearpants added a commit to wearpants/dbt-utils that referenced this issue Nov 7, 2019
better support for an edge case in Bigquery, which gets confused by casting a column with the same name as its parent table. Fixes fishtown-analytics#173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.