cube-js / cube-js/cube

Clickhouse: incorrect query when filtering on 'string' measure with 'equals' operator

Open
#7,328 4 comments 0 reactions 0 assignees View on GitHub
driver:clickhouse help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Describe the bug**
Cube generates incorrect query when measure of type 'string' is used as a filter with operator 'equals'. This applies to Clickhouse driver. Despite the measure being of type 'string', the generated HAVING clause tries to compare string value to the value of toFloat64(?).

**To Reproduce**
Steps to reproduce the behavior:
1. Use Clickhouse driver
2. Use the Cube schema that I provided below
3. Run the query with a filter on 'string' measure and operator 'equals' (see attached screenshots)

**Expected behavior**
The correct query should be generated. Cube should not use the toFloat64 function.

**Screenshots**
![image](https://github.com/cube-js/cube/assets/54632713/8ff674c7-af33-473e-bfe9-d27633a7ca59)

![image](https://github.com/cube-js/cube/assets/54632713/7696047c-9a3a-4d17-8acc-5e815c3af727)

**Minimally reproducible Cube Schema**

```javascript
cube(`cubeA`, {

sql: `
select 1 as id, 100 as number
`,

dimensions: {
id: {
type: 'number',
sql: 'id',
primary_key: true
},
number: {
type: 'number',
sql: 'number'
}
},

measures: {
high_or_low: {
type: `string`,
sql: `CASE WHEN ${CUBE.number} > 100 THEN 'high' ELSE 'low' END`
},
},
});
```

**Version:**
0.34.10

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.