Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-aggregations doesn't work well with sub-queries #8732

Open
saurabh0402 opened this issue Sep 19, 2024 · 0 comments
Open

Pre-aggregations doesn't work well with sub-queries #8732

saurabh0402 opened this issue Sep 19, 2024 · 0 comments

Comments

@saurabh0402
Copy link

Describe the bug
I have a measure that uses a dimension with sub_query and propagate_filters_to_sub_query set to true. When creating a pre-aggregation in the same cube and querying the measure, it errors out with the following error message

RequestError: Error: Internal: Error during planning: Table or CTE with name '<table name>' not found

To Reproduce
I used the following schema to create the cube

cubes:
  - name: forecasts
    sql: select * from schema.forecasts
    pre_aggregations:
      - name: first
        measures:
          - max_cutoff
        dimensions:
          - product
          - cutoff
        external: true
    measures:
      - name: max_cutoff
        sql: cutoff
        type: max
      - name: mean_absolute_percentage
        sql: abs((y - yhat) / greatest(y, 1e-16))
        type: avg
        filters:
          - sql: "{CUBE}.cutoff >= {tmp_max_cutoff} - INTERVAL '12 Weeks'"
    dimensions:
      - name: product
        sql: product_id
        type: string
        primary_key: true
        shown: true
      - name: cutoff
        sql: cutoff
        type: time
        primary_key: false
      - name: tmp_max_cutoff
        sql: "{max_cutoff}"
        type: number
        sub_query: true
        propagate_filters_to_sub_query: true
      - name: date
        sql: date
        type: time

I am then running the following query

const resultSet = await cubeApi.load({
    measures: ['forecasts.mean_absolute_percentage'],
    dimensions: ['forecasts.product'],
});

This error out with the message given above.
I think this is happening because, Cube is detecting that it can be satisfied via the pre-aggregation and thus runs query on pre-aggregation only. This causes the sub-query to fail.

Expected behavior
Cube should detect the sub-query and not run this specific query on pre-aggregations but use the source database.

Version:
0.36.1

Additional Comments

  • One workaround is to create two different cubes one with the pre-aggregation and one without it and add the measure with sub-query to the one without pre-aggregation. If there's a better workaround, please let me know.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant