cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.8k stars 1.76k forks source link

Internal: Error during planning: Coercion from [Int64Decimal(5), Int64] #6881

Open kal1f opened 1 year ago

kal1f commented 1 year ago

Describe the bug I'm trying to query a cube from from playground and get an error.

The interesting point is that when i change granularity all works(added screenshots for comparison).

Works

{
  "measures": [
    "backoffice.in_out"
  ],
  "timeDimensions": [
    {
      "dimension": "backoffice.as_of_date",
      "granularity": "day",
      "dateRange": "Yesterday"
    }
  ],
  "order": {
    "backoffice.as_of_date": "asc"
  }
} 

Does not work

  "measures": [
    "backoffice.in_out"
  ],
  "timeDimensions": [
    {
      "dimension": "backoffice.as_of_date",
      "granularity": "hour",
      "dateRange": "Yesterday"
    }
  ],
  "order": {
    "backoffice.as_of_date": "asc"
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Go to playground
  2. select measures and time

Expected behavior

Screenshots

Screenshot 2023-07-13 at 13 20 15 Screenshot 2023-07-13 at 13 23 18

Minimally reproducible Cube Schema my cube:

cube(`backoffice`,
    {
        public: isPublic(`backoffice`, COMPILE_CONTEXT),
        sql_table: `aggregate.backoffice`,
        measures: {
            deposit_amount_eur: {
                sql: `deposit_amount_eur`,
                type: `sum`
            },
            withdrawal_amount_eur: {
                sql: `withdrawal_amount_eur`,
                type: `sum`
            },
            in_out: {
                sql: `1.0 * ${withdrawal_amount_eur} / NULLIF(${deposit_amount_eur}, 0)`,
                type: `number`
            },
        },
        dimensions: {
            as_of_date: {
                sql: `as_of_date`,
                type: `time`
            },
            brand: {
                sql: `brand`,
                type: `string`
            },
            channel: {
                sql: `channel`,
                type: `string`
            },
            operator_id: {
                sql: `operator_id`,
                type: `string`
            },
            currency: {
                sql: `currency`,
                type: `string`,
                format: `currency`
            },
            risk_business_segment: {
                sql: `risk_business_segment`,
                type: `string`,
            },
            player_uid: {
                sql: `player_uid`,
                type: `string`,
            },
            traffic: {
                sql: `traffic`,
                type: `string`,
            },
        },
        dataSource: `default`
    }
);

Version: [e.g. 0.33.30]

svdimchenko commented 1 year ago

I'm facing the same problem. And it can be reproduced only when pre-aggregation is enabled. Once it's disabled, everything works good.

svdimchenko commented 1 year ago

however the following hack fixes the issue

${withdrawal_amount_eur} / NULLIF(CAST(${deposit_amount_eur} AS REAL), 0))

is it a problem on datafusion or cubestore level ?

paveltiunov commented 1 year ago

@svdimchenko Yep. If you're using calculations on the Cube Store side, you should make sure types will match there.

anshjain18 commented 6 months ago

@paveltiunov Something has been surely broken on Cube lately. I am getting this error on the new table when I am trying to create a ratio metric of two metrics of type sum. I have around 100 other cubes where I use the same syntax to add the ratio metric and they work fine. Can u please point me in the right direction as to what could have been broken here?

igorlukanin commented 6 months ago

@anshjain18 It would help us track down this issue if you'd provide more info.

Which Cube and Cube Store versions do you run? What is the data source? What is the data model for the cube in question? Do you use pre-aggregations? What is the exact error message? Does it reproduce consistently? Can you reproduce it with a cube that has its sql property defined as SELECT "some_value" AS column_1, "some_value" AS column_2, ...?

igorlukanin commented 4 months ago

@anshjain18 Is your issue still relevant? Would be great to get more info then.