-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Describe the bug
When defining a calculated measure in Cube that divides two measures of type count_distinct_approx, Cube generates invalid SQL. It attempts to divide two HLL sketches, which are of type BYTES, which results in this error:
No matching signature for operator / for argument types: BYTES, BYTES
To Reproduce
See the minimally reproducible schema below. When Cube attempts to generate a pre-aggregation you should see the error above.
Expected behavior
Current Query:
SELECT
`my_cube`.my_dimension `my_cube__my_dimension`,
HLL_COUNT.INIT(CASE WHEN (`my_cube`.viewed) THEN `my_cube`.user_id END) / HLL_COUNT.INIT(`my_cube`.user_id) `my_cube__ctr`
FROM
(
SELECT *
FROM my_table
)
GROUP BY 1, 2Expected Query:
SELECT
`my_cube`.my_dimension `my_cube__my_dimension`,
HLL_COUNT.EXTRACT(HLL_COUNT.INIT(CASE WHEN (`my_cube`.viewed) THEN `my_cube`.user_id END)) /
HLL_COUNT.EXTRACT(HLL_COUNT.INIT(`my_cube`.user_id) ) `my_cube__ctr`
FROM
(
SELECT *
FROM my_table
)
GROUP BY 1, 2Screenshots
If applicable, add screenshots to help explain your problem.
Minimally reproducible Cube Schema
In case your bug report is data modeling related please put your minimally reproducible Cube Schema here.
You can use selects without tables in order to achieve that as follows.
cube(`my_cube`, {
sql: `
select * from my_table
`,
measures: {
clicks: {
sql: `user_id`,
type: `count_distinct_approx`,
filters: [{ sql: `${CUBE.clicked}` }]
},
views: {
sql: `user_id`,
type: `count_distinct_approx`,
filters: [{ sql: `${CUBE.viewed}` }]
},
ctr: {
sql: `${clicks} / ${views}`,
type: `number`
},
},
dimensions: {
my_dimension: {
sql: `my_dimension`,
type: `string`,
},
},
});Version:
0.33.28
Additional context
Add any other context about the problem here.