Skip to content

get_relations_by_pattern does not build downstream tables #966

Open
@jeremy-thomas-roc

Description

Describe the bug

When using the get_relations_by_pattern macro to populate a table with them in a union, when trying to build the table using the + selector on the model name, it does not build the downstream tables and results in a failed model build.

Steps to reproduce

{{ config(materialized="table") }}

{% set relations = dbt_utils.get_relations_by_pattern(target.schema, "%my%pattern%") %}

with unions as ({{ dbt_utils.union_relations(relations=relations) }})

select *
from unions

Expected results

I would expect to be able to use these macros to generate upstream models without having to manually generate the downstream models, negating the usefulness of this macro. I understand that this macro reads from information_schema (in Snowflake) to populate, but without the ability to generate the models, how would we use this to build upstream models with a single command?

Actual results

Model fails to build because the union_relations macro does not have any relations, creating invalid SQL.

Screenshots and log output

14:58:39    Database Error in model stg_addresses (models/my_model.sql)
  001003 (42000): SQL compilation error:
  syntax error line 11 at position 4 unexpected ')'.
  compiled code at target/run/my_project/models/my_model.sql

Generated file at target/run/my_project/models/my_model.sql:

with unions as (
    )

select *
from unions

System information

The contents of your packages.yml file:

Which database are you using dbt with?

  • postgres
  • redshift
  • bigquery
  • snowflake
  • other (specify: ____________)

The output of dbt --version:

Core:
  - installed: 1.8.8
  - latest:    1.8.8 - Up to date!

Plugins:
  - snowflake: 1.8.4 - Up to date!

Additional context

Are you interested in contributing the fix?

With some direction, I have attempted to contribute to dbt before and was not successful. If there is a fix to be made, I am happy to take a shot at it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions