cube-js / cube-js/cube

ORDER BY is not working for preaggregations queries

Open
#8,255 4 comments 1 reaction 0 assignees View on GitHub
question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Describe the bug**
Using BigQuery and matching a preaggregation, a query with `order` parameter on a `measure` returns **unsorted results**.
The generated SQL query that I can inspect in the playground does not use any ORDER BY clause.

**Example of a query:**
```
{
"measures": [
"Cube.count"
],
"dimensions": [
"Cube.status"
],
"order": [
[
"Cube.count",
"desc"
]
]
}
```

**The generated SQL is:**

```
SELECT
`cube__status`,
sum(`cube__count`) `cube__count`
FROM
(
SELECT
`cube__status` `cube__status`,
sum(`cube__count`) `cube__count`
FROM
pre_aggregations_xxxxxxxxxxxxxxx.cube AS `cube__main`
GROUP BY
1
) `base`
GROUP BY
1
```

**Expected behavior**
order should be working when a preaggregation is matched.

**Version:**
"@cubejs-backend/bigquery-driver": "0.35.30",
"@cubejs-backend/server": "0.35.30"

**Other question:**
Also I noticed the count measure is returned by preaggregations (from BigQuery) as a string instead of a number.
Is there any reason for this to happen?

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.