-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Describe the bug
I think this is a bug based on the error message but if this isn't supported would love to hear workaround suggestions as this is currently preventing us from using pre aggregations.
I'm expecting to create a pre aggregation with column A. I then want to query column B, which is a measure based on a window function on A but get the following error:
Internal: Internal error: unsupported operation. This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
The use case for this is to get a "totals" row, so my window function is just sum(sum(A)) over ()
To Reproduce
Steps to reproduce the behavior:
- Create cube with columns A and B, where B is a measure defined as:
total: {
sql: (CUBE) => `sum(${CUBE[`A`]}) over ()`,
type: `number`,
title: `A Total`,
}- Create a rollup pre aggregation with A as the only measure, no dimensions
- Try querying B, and it generates the following SQL:
SELECT
sum(`my_cube__A`) `my_cube__A`,
sum(sum(`my_cube__A`)) over () `my_cube__B`
FROM
prod_pre_aggregations.my_cube_rollup AS `my_cube__rollup`This is correct but throws the error above.
Expected behavior
I expected it to run the SQL query above and give me a total column as column B.
Example expected output:
A | B
1 | 12
3 | 12
8 | 12
Where B is the total of everything in column A. We should assume filters have been applied, which is why this needs to be calculated after pre aggregations created.
Screenshots
Error on playground:
Minimally reproducible Cube Schema
cube(`Orders`, {
sql: `
select 1 as id, 100 as amount, 'new' status
UNION ALL
select 2 as id, 200 as amount, 'new' status
UNION ALL
select 3 as id, 300 as amount, 'processed' status
UNION ALL
select 4 as id, 500 as amount, 'processed' status
UNION ALL
select 5 as id, 600 as amount, 'shipped' status
`,
measures: {
totalAmount: {
sql: `amount`,
type: `sum`,
},
grandTotalAmount: {
sql: `sum(${CUBE[`totalAmount`]}) over ()`,
type: `number`,
},
},
dimensions: {
status: {
sql: `status`,
type: `string`,
},
},
});Version:
0.36.7
Additional context
If there are any other suggestions as to how to do totals (and sub totals) we would love to hear these too!
