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

use fully qualified column name in unions #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wearpants
Copy link
Owner

better support for an edge case in Bigquery, which gets confused by casting a column with the same name as its parent table. Fixes dbt-labs#173

better support for an edge case in Bigquery, which gets confused by casting a column with the same name as its parent table. Fixes dbt-labs#173
@@ -58,8 +58,7 @@

{%- set col = column_superset[col_name] %}
{%- set col_type = column_override.get(col.column, col.data_type) %}
{%- set col_name = adapter.quote(col_name) if col_name in table_columns[table] else 'null' %}
cast({{ col_name }} as {{ col_type }}) as {{ col.quoted }} {% if not loop.last %},{% endif %}
{%- set col_name = adapter.quote(table.name) + '.' + adapter.quote(col_name) if col_name in table_columns[table] else 'null' %} cast({{ col_name }} as {{ col_type }}) as {{ col.quoted }} {% if not loop.last %},{% endif %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rewrite this as:

{%- set col_name - %}
  {{ adapter.quote(table.name) ~ '.' ~ adapter.quote(col_name) }} 
{%- else -%}
  null
{% endif %}
cast({{ col_name }} as {{ col_type }}) as {{ col.quoted }} {% if not loop.last %},{% endif %}

I actually think we're better off just always including the table name in the col_name variable - that makes more sense to me than including it conditionally based on the supplied list of tables.

This is one of those things that I'd need to think a lot harder about though. Different databases have different semantics for things like this and I'm afraid of breaking eg. Snowflake in pursuit of fixing BigQuery.

Just for the sake of discussion: we might be able to alternatively alias the table name in the from clause of each union query. That might accomplish something similar.

I'll poke around with this some more - just wanted to get you some initial feedback here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

union should explicitly specify table name in casts
2 participants