Skip to content

[Bug] v0.209.0 generates incorrect SQL for measures #1975

@grigorjevas

Description

@grigorjevas

Is this a new bug in metricflow?

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

Current Behavior

When querying metrics in MetricFlow v0.209.0, generated SQL references measure name as a column instead of applying the aggregation function to the expr field. This causes "Unrecognized name" errors in BigQuery.

Example generated SQL (v0.209.0)

SELECT SUM(session_count) AS session_count
FROM `product`.`product_stats__sessions`

This treats session_count as an existing column in the table, which doesn't exist.

Expected Behavior

MetricFlow should apply the aggregation function to the expr field defined in the measure configuration.

Expected SQL (as in v0.208.0)

SELECT SUM(CASE WHEN session_id IS NOT NULL THEN 1 ELSE 0 END) AS session_count
FROM .`product`.`product_stats__sessions`

Steps To Reproduce

  1. Define a measure in semantic model:
semantic_models:
  - name: sessions
    model: ref('product_stats__sessions')
    measures:
      - name: session_count
        agg: count
        expr: session_id
  1. Query the metric:
mf query --metrics session_count --explain
  1. Observe the incorrect SQL generation

Relevant log output

google.api_core.exceptions.BadRequest: 400 Unrecognized name: session_count at [9:7]

Location: EU
Job ID: xxx

dbt_common.exceptions.base.DbtDatabaseError: Database Error
  Unrecognized name: session_count at [9:7]

Environment

- OS: Debian 12.12
- Python: 3.12.12
- dbt: 1.10.15
- dbt-metricflow: 0.11.0
- Metricflow: 0.209.0

Which database are you using?

No response

Additional Context

This seems related to the measures to simple metrics migration introduced in PRs #1889, #1892, #1893
Downgrading to MetricFlow 0.208.0 resolves the issue

Is a fix expected in an upcoming release?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions