Skip to content

[BUG] expect_row_values_to_have_data_for_every_n_datepart fails on Trino due to GROUP BY alias #39

Description

@kovipaulo

Is this a new bug in dbt-expectations?

  • I believe this is a new bug in dbt-expectations
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When running expect_row_values_to_have_data_for_every_n_datepart on Trino (Starburst), the test fails with a SQL compilation error.

TrinoUserError(type=USER_ERROR, name=COLUMN_NOT_FOUND, message="line 150:9: Column 'date_day' cannot be resolved"

This happens because the macro generates a query that attempts to GROUP BY the column alias (e.g., date_day) defined in the SELECT clause. Trino/Presto engines resolve the GROUP BY clause before the SELECT projection, so the alias is not yet available at that stage.

Expected Behavior

The test should compile and run successfully on Trino/Starburst, correctly grouping the records by the calculated date intervals.

Steps To Reproduce

  1. Configure a dbt project with a Trino/Starburst adapter.
  2. Add the test to a model using a configuration similar to this:
version: 2

models:
  - name: my_generic_model
    data_tests:
      - dbt_expectations.expect_row_values_to_have_data_for_every_n_datepart:
          date_col: event_date
          date_part: day
          interval: 1
  1. Run dbt test.

Relevant log output

TrinoUserError(type=USER_ERROR, name=COLUMN_NOT_FOUND, message="line 150:9: Column 'date_day' cannot be resolved"

Environment

- OS: MacOS 15.6.1
- Python: 3.11.14
- dbt: 1.10.8
- dbt-expectations: 0.10.9

Which database adapter are you using with dbt?

  • Trino

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions