dbt-utils icon indicating copy to clipboard operation
dbt-utils copied to clipboard

Union Relations compilation doesn't include all columns

Open moseleyi opened this issue 1 year ago • 1 comments

From what I read in the documentation, even when relations differ, the macro will result in a list of unique columns from all relations and fill things with NULL when necessary. However, that's not what's happening in my case.

Steps to reproduce

model_a.sql

SELECT
  2 AS test,
  3 AS test2

model_b.sql

SELECT
  1 AS test

Expected results

( 
  SELECT
    CAST('''`project.schema.model_a`''' AS STRING) AS _dbt_source_relation,
    CAST(test AS INT64) AS test,
    CAST(test2 AS INT64) AS test2
  FROM model_a
) UNION ALL
(
  SELECT
    CAST('''`project.schema.model_b`''' AS STRING) AS _dbt_source_relation,
    CAST(test AS INT64) AS test,
    CAST(NULL AS INT64) AS test2
  FROM model_b
)

Actual results

test2 column is not even present in the compiled code

( 
  SELECT
    CAST('''`project.schema.mnodel_a`''' AS STRING) AS _dbt_source_relation,
    CAST(test AS INT64) AS test
  FROM model_a
) UNION ALL
(
  SELECT
    CAST('''`project.schema.mnodel_b`''' AS STRING) AS _dbt_source_relation,
    CAST(test AS INT64) AS test
  FROM model_b
)

System information

The contents of your packages.yml file:

packages:
  - package: dbt-labs/dbt_utils
    version: 1.3.0

Which database are you using dbt with?

  • [ ] postgres
  • [ ] redshift
  • [x] bigquery
  • [ ] snowflake
  • [ ] other (specify: ____________)

The output of dbt --version:

Core: 1.8.4
BigQuery: 1.8.2

moseleyi avatar Sep 24 '24 09:09 moseleyi

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

github-actions[bot] avatar Jun 03 '25 02:06 github-actions[bot]