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

Incomplete data model validation: strings are accepted in the list of dimensions in a pre-aggregation definition #9137

Open
igorlukanin opened this issue Jan 24, 2025 · 0 comments
Labels
bug Something isn't working data modeling

Comments

@igorlukanin
Copy link
Member

igorlukanin commented Jan 24, 2025

Describe the bug
In JavaScript-based data models, strings are accepted in the list of dimensions in a pre-aggregation definition. This data model compiles but fails at runtime, when the query comes.

Removing the backticks around w_merchant_id fixes it:

        dimensions: [
          `w_merchant_id`
        ],

To Reproduce
Steps to reproduce the behavior:

  1. Use the following data model.
  2. Run a query.
{
  "dimensions": [
    "my_stores.account_id"
  ],
  "order": {
    "my_stores.account_id": "asc"
  }
}
  1. See the error.
Typepath.join is not a function
TypeError: path.join is not a function
    at CubeEvaluator.byPathAnyType (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/CubeEvaluator.ts:356:55)
    at CubeEvaluator.parsePathAnyType (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/CubeEvaluator.ts:392:10)
    at /cube/node_modules/@cubejs-backend/schema-compiler/src/adapter/PreAggregations.js:909:75
    at Array.map (<anonymous>)
    at PreAggregations.cubesFromPreAggregation (/cube/node_modules/@cubejs-backend/schema-compiler/src/adapter/PreAggregations.js:909:41)
...

Expected behavior
This data model should fail at compile time with a clear error message.

Minimally reproducible Cube Schema

cube(`my_orders`, {
    sql_table: `public.my_orders`,
    dimensions: {
      w_merchant_id: {
        sql: `w_merchant_id`,
        type: `number`,
        primary_key: true, 
        public: true,
      },
    },
    pre_aggregations: {
      orders_rollup: {
        type: `rollup`, 
        dimensions: [
          `w_merchant_id`
        ],
    },
  }});
cube(`my_stores`, 
  {
    sql_table: `public.my_stores`,
    dimensions: {
      account_id: {
        sql: `account_id`,
        type: `string`,
      },
    },
    joins: {
      my_orders: {
        sql: `${account_id} = ${my_orders.w_merchant_id}`,
        relationship: `one_to_many`,
      }
    },
    pre_aggregations: {
      stores_rollup: {
        type: `rollup`,
        dimensions: [
          account_id, 
        ],
      },
      combined_rollup: {
        type: `rollup_join`,
        dimensions: [
          account_id,
          my_orders.w_merchant_id,
        ],
        rollups: [
          my_orders.orders_rollup, 
          stores_rollup
        ]
      },
    },
  }
);

Version:
v1.1.16

Additional context
Reported by Embeddable in Slack: https://cube-js.slack.com/archives/C04KDTE2EF7/p1737652681703019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data modeling
Projects
None yet
Development

No branches or pull requests

1 participant