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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions macros/sql/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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.

{%- endfor %}

from {{ table }}
Expand Down