cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.87k stars 1.77k forks source link

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

Open elqx opened 11 months ago

elqx commented 11 months ago

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

image

Minimally reproducible Cube Schema

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

github-actions[bot] commented 11 months ago

If you are interested in working on this issue, please leave a comment below and we will be happy to assign the issue to you. If this is the first time you are contributing a Pull Request to Cube.js, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube.js Slack.

paveltiunov commented 11 months ago

@elqx Yep. I guess we need to revisit measure string filters.

igorlukanin commented 1 week ago

I was able to reproduce this with Cube v0.36.3 (latest), same behavior as reported:

Screenshot 2024-10-08 at 23 18 25