Skip to content

It is not possible to use the ? symbol in SQL queries #6589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ilya-zlobintsev opened this issue May 12, 2023 · 2 comments
Open

It is not possible to use the ? symbol in SQL queries #6589

ilya-zlobintsev opened this issue May 12, 2023 · 2 comments
Labels
backend:server Issues relating to Cube Core's Server bug Something isn't working help wanted Community contributions are welcome.

Comments

@ilya-zlobintsev
Copy link

Describe the bug
Some Clickhouse functions such as sequenceMatch use question marks in their syntax. Cube.js will always treat the question marks as parameters, and there doesn't seem to be a way to escape them.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Cube that uses the sequenceMatch function with ? in the syntax
  2. Try to use it
  3. The generated SQL is incorrect

Expected behavior
With the example Cube schema, I would expect the following SQL to be generated:

SELECT
      count(CASE WHEN (`sequence_match_example`.matched = 1) THEN `sequence_match_example`."subject_reference_id" END) `sequence_match_example__count`
    FROM
      (SELECT
          subject_reference_id,
          sequenceMatch('(?1)(?t>172800)(?2)')(effectivePeriod_start, code_coding_code = '93018', code_coding_code = '92920') as matched
        FROM ehr.Event
        GROUP BY subject_reference_id) AS `sequence_match_example`  LIMIT 10000;

Actual behaviour
Instead, the generated SQL is this:

SELECT
      count(CASE WHEN (`sequence_match_example`.matched = 1) THEN `sequence_match_example`."subject_reference_id" END) `sequence_match_example__count`
    FROM
      (SELECT
          subject_reference_id,
          sequenceMatch('('93018'1)('92920't>172800)('93018'2)')(effectivePeriod_start, code_coding_code = ''93018'',
            code_coding_code = ''92920'') as matched
        FROM ehr.Event
        GROUP BY subject_reference_id) AS `sequence_match_example`  WHERE ('92920' = ?) AND (? = ?) LIMIT 10000

Minimally reproducible Cube Schema

cube(`SequenceMatchExample`, {
  sql: `SELECT
          subject_reference_id,
          sequenceMatch('(?1)(?t>172800)(?2)')(effectivePeriod_start, code_coding_code = '${FILTER_PARAMS.SequenceMatchExample.firstEventCode.filter((x) => `${x}`)}',
            code_coding_code = '${FILTER_PARAMS.SequenceMatchExample.secondEventCode.filter((x) => `${x}`)}') as matched
        FROM ehr.Event
        GROUP BY subject_reference_id`,

  measures: {
    count: {
      type: `count`,
      sql: `${CUBE}."subject_reference_id"`,
      filters: [{ sql: `${CUBE}.matched = 1` }],
    },
  },

  dimensions: {

    firstEventCode: {
      sql: `${FILTER_PARAMS.SequenceMatchExample.firstEventCode.filter((x) => x)}`,
      type: `string`,
      shown: true,
    },

    secondEventCode: {
      sql: `${FILTER_PARAMS.SequenceMatchExample.secondEventCode.filter((x) => x)}`,
      type: `string`,
      shown: true,
    },

  },

  dataSource: `default`,
});

Query JSON:

{
  "measures": [
    "SequenceMatchExample.count"
  ],
  "filters": [
    {
      "member": "SequenceMatchExample.firstEventCode",
      "operator": "equals",
      "values": [
        "93018"
      ]
    },
    {
      "member": "SequenceMatchExample.secondEventCode",
      "operator": "equals",
      "values": [
        "92920"
      ]
    }
  ]
}

Version:
0.31.32

Additional context
This happens because the Cube Clickhouse driver uses the sqlstring library for escaping SQL queries, which is designed for MySQL and not Clickhouse. The library does not support escaping the question mark.

@paveltiunov paveltiunov added bug Something isn't working help wanted Community contributions are welcome. labels May 15, 2023
@github-actions
Copy link

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.

@gojumprope
Copy link

Same issue here, but I guess it happens for all the drivers if we have ? symbol in the sql statement when we do filter

Example: it will replace ? symbol to the filter

    sql:`
    SELECT 'https://abc.com?id=123' link
`,

@igorlukanin igorlukanin added the backend:server Issues relating to Cube Core's Server label Aug 31, 2023
@igorlukanin igorlukanin added the driver:clickhouse Issues related to the ClickHouse driver label Aug 19, 2024
@igorlukanin igorlukanin removed the driver:clickhouse Issues related to the ClickHouse driver label Oct 8, 2024
@igorlukanin igorlukanin changed the title It is not possible to use the ? symbol in Clickhouse SQL queries It is not possible to use the ? symbol in SQL queries Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:server Issues relating to Cube Core's Server bug Something isn't working help wanted Community contributions are welcome.
Projects
None yet
Development

No branches or pull requests

4 participants