Skip to content

expectations break when expecting a Struct in BigQuery #166

@JakoboEU

Description

@JakoboEU

Generating an expected result such as:

    {% call dbt_unit_testing.expect() %}
        SELECT
            DATE('2023-02-11') AS snapshot_date,
            STRUCT(
                '01'                AS event_id,
                DATE('2022-01-01')  AS created_on,
                'Sam'         AS name
            ) AS event
        UNION ALL
        SELECT
            DATE('2023-02-11') AS snapshot_date,
            STRUCT(
                '02'                AS event_id,
                DATE('2022-01-01')  AS created_on,
                'Bob'         AS name
            ) AS event
    {% endcall %}

Results in the following SQL being run against BigQuery:

select * FROM 
      (select count(1) as expectation_count from (
        select count(1) as count, `snapshot_date`,`event` from (
        SELECT
            DATE('2023-02-11') AS snapshot_date,
            STRUCT(
                '01'                AS event_id,
                DATE('2022-01-01')  AS created_on,
                'Sam'         AS name
            ) AS event
        UNION ALL
        SELECT
            DATE('2023-02-11') AS snapshot_date,
            STRUCT(
                '02'                AS event_id,
                DATE('2022-01-01')  AS created_on,
                'Bob'         AS name
            ) AS event
    ) as s group by `snapshot_date`,`event`

Which generates the following error:

Grouping by expressions of type STRUCT is not allowed at [21:37]

Because group by snapshot_date, event is illegal due to event being a struct.

dbt_unit_testing version:

  - package: EqualExperts/dbt_unit_testing
    version: 0.3.2

dbt version:

Running with dbt=1.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions