cube-js / cube-js/cube

Pre-aggregations would not build if they only contain `count_distinct_approx` measures

Open
#8,916 0 comments 0 reactions 1 assignee Claimed by @paveltiunov View on GitHub
pre-aggregations
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Describe the bug**
If a pre-aggregation contains only `count_distinct_approx` measures (one, two, etc.) and no other dimensions or measures, it will not build. Instead, the an error is shown.

**To Reproduce**
Steps to reproduce the behavior:
1. Take the data model below.
2. Run a query to the `mes` measure in Playground so that a p-reaggregation build is triggered.
3. See the following error:
```
Error during create table:
CREATE TABLE prod_pre_aggregations.my_cube_test_main_qilx5vis_ieu50pzh_1jimlbg (`my_cube_test__mes` BYTES) LOCATION ?:
Sort key size can't be 0 for default, columns: [Column { name: "my_cube_test__mes", column_type: Bytes, column_index: 0 }]
```

**Expected behavior**
The pre-aggregation builds.

**Screenshots**
Screenshot 2024-11-06 at 12 39 45

**Minimally reproducible Cube data model**
```javascript
cube(`my_cube_test`, {
sql: `
SELECT 123 AS abc UNION ALL
SELECT 234 AS abc UNION ALL
SELECT 345 AS abc
`,

measures: {
mes: {
sql: `abc`,
type: `count_distinct_approx`
}
},

pre_aggregations: {
main: {
measures: [ mes ]
}
}
})
```

**Version:**
v1.1.2

**Additional context**
Adding a `count` measure or a dimension to the pre-aggregation definition makes the error go away.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.