Repository navigation
fix(trino-driver/prestodb-driver): Сorrect SQL parameter escaping - #11345
Conversation
Add a dialect-aware `SqlEscaper` to `@cubejs-backend/shared` with ANSI (Presto/Trino/Postgres) and MySQL presets, and use `formatAnsi` in the driver. Standard-SQL escaping doubles the quote (`'''...`) so the literal stays closed, while preserving the `\_` / `\%` LIKE-escape sequences the schema compiler emits (backslash is not doubled).
|
Claude finished @ovr's task in 1m 30s —— View job Code ReviewVerdict: Looks good. The change correctly replaces Details — 0 high, 2 medium, 2 lowFindingsMedium — Medium — Nested-array parenthesization semantics differ from Low — Low — Missing CHANGELOG note / driver docs mention Positives
|
|
Claude finished @ovr's task in 42s —— View job Code Review (updated after
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11345 +/- ##
===========================================
+ Coverage 59.57% 79.59% +20.01%
===========================================
Files 216 474 +258
Lines 17526 98300 +80774
Branches 3549 3570 +21
===========================================
+ Hits 10441 78238 +67797
- Misses 6574 19549 +12975
- Partials 511 513 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Claude finished @ovr's task in 51s —— View job Code Review (updated after
|
|
Claude finished @ovr's task in 1m 48s —— View job Code Review (updated after
|
|
Claude finished @ovr's task in 51s —— View job Code Review (updated after
|
|
Claude finished @ovr's task in 41s —— View job Code Review (updated after
|
|
Claude finished @ovr's task in 38s —— View job Code Review (updated after
|
(cherry picked from commit 463e602)
(cherry picked from commit 463e602)
The Tesseract half of #11345 had to be hand-ported for 1.4: upstream put escape_like_pattern in physical_plan/filter/operators/like.rs and covered it from src/tests/filter/to_sql.rs, neither of which exists on this branch. Here the escaping hooks into BaseFilter::like_or_where instead, so add direct unit tests for escape_like_pattern to keep the ported logic covered. Cases mirror the upstream assertion (folder\name_% -> folder\\name\_\%) and add a non-backslash escape character to pin the template-driven escape_char path. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
BaseFilter.escapeWildcardChars started escaping literal backslashes in #11345, but Oracle and SQLite emitted LIKE without an ESCAPE clause and neither engine has a default LIKE escape character, so `\` stayed literal and contains/notContains regressed: a value like `c:\users` matched nothing, and the pre-existing `\%` / `\_` escaping was equally inert. Oracle is a straight backport of the line master already ships from f0569ad (#11177), absent on this branch. SQLite is new — master is still missing it. ESCAPE binds to the whole right operand, so it has to follow COLLATE NOCASE; verified against sqlite3 3.51: | expression | result | | --- | --- | | `'a_b' LIKE '%a\_b%' COLLATE NOCASE ESCAPE '\'` | 1 — escaped `_` is literal | | `'axb' LIKE '%a\_b%' COLLATE NOCASE ESCAPE '\'` | 0 — no longer a wildcard | | `'c:\users\bob' LIKE '%c:\\users%' COLLATE NOCASE ESCAPE '\'` | 1 — backslash matches | | `'ABC' LIKE '%abc%' COLLATE NOCASE ESCAPE '\'` | 1 — COLLATE still applies | | `'axb' LIKE '%a_b%' COLLATE NOCASE ESCAPE '\'` | 1 — unescaped `_` still wildcards | | `'c:\users\bob' LIKE '%c:\\users%' COLLATE NOCASE` (old SQL) | 0 — the regression | Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…rams HiveFilter inherited the base escapeWildcardChars, which started escaping literal backslashes in #11345. HiveQL's LIKE takes no ESCAPE clause and Hive unescapes only `\%` and `\_` when it converts the pattern to a regex, so a doubled backslash stays two literal backslashes and `c:\users` became an unmatchable `c:\\users`. Override it to escape wildcards only, which is the pre-#11345 Hive behaviour. A full no-op override would be wrong in the other direction: `\%` / `\_` do work in Hive, so dropping them would let user-supplied wildcards match. Rewriting through RLIKE would fix the mixed `\` + wildcard edge case too, but that swaps in a different regex engine and is not backport material. Hive `\\` handling is from the LIKE-to-regex conversion, not a cluster run — worth confirming on real Hive. Either way this is no worse than before the PR, which is why it is the conservative choice. MSSQL, raised in the same review thread, turned out not to be affected: MssqlFilter overrides escapeWildcardChars with the T-SQL bracket form and never introduces a backslash. Covered by tests so it stays that way. | dialect | input | bound param | | --- | --- | --- | | Hive (before) | `c:\users` | `c:\\users` | | Hive (after) | `c:\users` | `c:\users` | | Hive | `a_b%` | `a\_b\%` | | MSSQL | `c:\users` | `c:\users` | | MSSQL | `a_b%` | `a[_]b[%]` | Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ects `filters.like_escape_char` was defined only in PrestodbQuery, and `PlanSqlTemplates::like_escape_char()` returns `None` when the template is absent, so `filter_cast_and_allocate_values_escaped` did no escaping at all on every other dialect. The JS planner has always escaped `%`/`_` through `BaseFilter.escapeWildcardChars`, so a `contains: ['100%']` filter behaved differently depending on `CUBEJS_TESSERACT_SQL_PLANNER`. Raised in review of the Tesseract half of #11345; master has the same gap, `PrestodbQuery.ts:180` is still the only definition there. Declare the escape character in the base templates so it mirrors `BaseFilter.escapeWildcardChars`, and emit an ESCAPE clause on the dialects that have no default LIKE escape character. Every dialect now binds exactly what its JS counterpart binds, for `contains`/`notContains`/`startsWith`/ `endsWith` alike, with the filter value `folder\name_%`: | dialect | Tesseract param before | after | clause added |
…values `BaseFilter.isWildcardOperator()` covered only contains/notContains, so startsWith/notStartsWith/endsWith/notEndsWith values reached LIKE raw even though `likeIgnoreCase` renders them under the same ESCAPE clause: Presto's from #11345 (2d9fc6d), Oracle's and SQLite's from 30a2057, and Snowflake's long-standing one. A backslash in the value was then read as an escape character: startsWith: ['C:\temp'] -> source LIKE ? || '%' COLLATE NOCASE ESCAPE '\' with param C:\temp Widen it to all six LIKE-based operators, a backport of the line master ships from 43331cc (#10862) which is absent on this branch. Raised in review of the preceding Tesseract LIKE escaping commit. Verified against sqlite3 3.51 and Oracle Free 23ai, which fail differently: SQLite silently reinterprets the pattern, Oracle rejects it outright. | engine, pattern | `C:\temp\x` | `C:temp\x` | | --- | --- | --- | | SQLite, raw param, `LIKE 'C:\temp' \|\| '%' ESCAPE '\'` (before) | no match | match | | SQLite, escaped param, `LIKE 'C:\\temp' \|\| '%' ESCAPE '\'` (after) | match | no match | | SQLite, raw param, no ESCAPE clause (before 30a2057) | match | no match | | Oracle, raw param (before) | ORA-01424 | ORA-01424 | | Oracle, escaped param (after) | match | no match | A value ending in a backslash behaves the same way: `endsWith: ['temp\']` raised ORA-01424 on Oracle and silently stopped matching on SQLite, while the escaped `temp\\` matches `x\temp\` on both. The same class of bug was already there without any ESCAPE clause on dialects whose LIKE treats a backslash as the default escape character (postgres, redshift, mysql, bigquery, clickhouse, cubestore, vertica, crate): `startsWith: ['C:\temp']` matched `C:temp%` there, independently of 30a2057. The native planner was already correct, `BaseFilter::like_or_where` escapes for contains/startsWith/endsWith alike, so this closes the last planner divergence too: both now bind `C:\\temp` on every dialect except MSSQL, whose bracket form deliberately leaves the backslash alone, and Hive, which opts out of native escaping as of the preceding commit. Worth a release note: wildcards in startsWith/endsWith values are now literal, as they already are for contains and as master behaves. A `startsWith: ['100%']` filter used to match anything starting with `100` and now matches values starting with the literal `100%`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The dialect sweep in 30a2057 and e2f2887 stopped at cubejs-schema-compiler, but `newFilter` is also overridden by query classes that ship inside driver packages. Those inherit the base `escapeWildcardChars` (`\`, `_`, `%` -> `\x`) with nothing on the engine side to consume the escape character: | class | likeIgnoreCase | escape mechanism | | --- | --- | --- | | DruidQuery.ts | `LOWER(c) LIKE CONCAT('%', LOWER(?), '%')` | `x LIKE pattern [ESCAPE esc]`, no default | | KsqlQuery.ts | `c ILIKE CONCAT('%', ?, '%')` | `NOT? LIKE pattern (ESCAPE STRING)?`, no default | | PinotQuery.ts | already carries `ESCAPE '\'` | JS side was fine | `_`/`%` mis-escaping predates #11345 on Druid and ksql, but two things made them worse than before it: the unconditional `\` in `escapeWildcardChars` turned `contains: ['c:\users']` into an unmatchable `c:\\users`, and 81f2bb3 routed startsWith/endsWith through the same path, so `startsWith: ['100%']` now binds `100\%` and matches nothing where it used to match `100...`. Tesseract had the mirror-image gap: e2f2887 declares `filters.like_escape_char` in the base templates, so the native planner escapes on every dialect, but only the schema-compiler dialects got an ESCAPE clause to attach it to. Pinot was therefore correct in the JS planner and inert in the native one. Druid and Pinot also have no ILIKE — Druid's SQL operator reference lists only `x LIKE pattern [ESCAPE esc]` / `x NOT LIKE pattern [ESCAPE esc]`, and both JS filters already stand in for it with `LOWER()` on either side. Their `tesseract.ilike` now mirrors that, the same shape MssqlQuery uses, because the ESCAPE clause binds to the whole right operand and cannot sit inside `LOWER()`. ksqlDB has no ILIKE at all: neither `SqlBase.g4` nor the Confluent operator reference has one, only the LIKE predicate quoted in the table above. So `KsqlFilter`'s `ILIKE` does not parse today, independently of escaping, and this commit does not change that — making it parse means moving to `LIKE` plus case-folding functions, which is a case-insensitivity change rather than an escaping one. The ESCAPE clause is what ksqlDB's LIKE wants either way, and a backslash is plain data inside a ksqlDB string literal, so `'\'` is a single escape character. Verified against the engines' grammars and SQL references, not against running clusters. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Dremio's ILIKE is a function, not an operator, and DremioFilter got two things
wrong about the call. `NOT` was spliced into the argument list, and the optional
third argument — the escape character, without which there is none — was absent,
so the `\` that `BaseFilter.escapeWildcardChars` binds stayed literal data:
| filter | before | after |
| --- | --- | --- |
| `contains: ['demo']` | `ILIKE (c, CONCAT('%', ?, '%'))` | `ILIKE(c, CONCAT('%', ?, '%'), '\')` |
| `notContains: ['demo']` | `ILIKE (c NOT, CONCAT(...))` — cannot parse | `NOT ILIKE(c, CONCAT(...), '\')` |
| `contains: ['c:\users']` | searched for `c:\\users` | searches for `c:\users` |
| `startsWith: ['100%']` | matched anything starting with `100` | matches a literal `100%` |
So notContains/notStartsWith/notEndsWith were dead on Dremio before this, the
`\` regression came from #11345, and the startsWith/endsWith half came from
81f2bb3 widening `isWildcardOperator`.
The native planner had the same hole from the other side: e2f2887 declares
`filters.like_escape_char` in the base templates, but `filters.like_pattern` can
only append an ESCAPE clause, which the function form has no room for — so
`tesseract.ilike` carries the escape argument instead and mirrors the JS filter.
Dremio's `expressions.ilike`, used for SQL API push-down, is still the operator
form and still wrong; that is a separate shape bug, not an escaping one.
Verified against Dremio's ILIKE function reference, not against a running
cluster.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`ElasticSearchQueryFilter` renders `contains` as `MATCH(c, ?, 'fuzziness=...')`, a full-text match where `%` and `_` are not wildcards and a backslash is ordinary data. Escaping the value there is not inert, it corrupts the search term: `contains: ['user_id']` has been searching for `user\_id` since before #11345, and #11345 added the same for `c:\users` -> `c:\\users`. Its `starts`/`ends` branches do render LIKE, and Elasticsearch SQL has no default escape character, so they would need an explicit ESCAPE clause — but the SQL they emit (`${not} WHERE ${column} LIKE ${param}%`) carries a stray `WHERE` and an unquoted `%` and cannot run at all, which is a separate bug and not fixed here. Overriding `escapeWildcardChars` to a no-op and dropping `filters.like_escape_char` is the same reasoning HiveQuery uses in 5ed14f8: nothing expressible to escape with, so don't pretend. AWSElasticSearchQuery deliberately keeps the base escaping. Its Open Distro / OpenSearch dialect is LIKE-based and follows MySQL, where `\` is the default escape character and no ESCAPE clause is needed, so it re-declares the escape char that ElasticSearchQuery drops. OpenSearch's own LIKE escaping is reportedly buggy (opensearch-project/sql#779), but binding `\%` is what that dialect asks for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
QuestQuery was the last unchecked driver-package dialect in the review of the LIKE escaping series: it does not override `likeIgnoreCase`, so it renders the base `ILIKE '%' || $1 || '%'` with no ESCAPE clause, which reads like the Oracle and SQLite regressions fixed in 30a2057. It isn't one. QuestDB has no ESCAPE clause because a backslash is unconditionally its escape character: `AbstractLikeStrFunctionFactory.escapeSpecialChars` converts the pattern to a Java regex and reads `\%`, `\_` and `\\` as the literal character, and raises "LIKE pattern must not end with escape character" for a pattern ending in a lone `\`. So the base `escapeWildcardChars` is already dialect-correct here, and #11345's backslash escaping made `endsWith: ['temp\']` work rather than error out. No behaviour change, just pinning what the base escaping has to keep binding. Read off QuestDB's source, not confirmed against a running instance. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ects `filters.like_escape_char` was defined only in PrestodbQuery, and `PlanSqlTemplates::like_escape_char()` returns `None` when the template is absent, so `filter_cast_and_allocate_values_escaped` did no escaping at all on every other dialect. The JS planner has always escaped `%`/`_` through `BaseFilter.escapeWildcardChars`, so a `contains: ['100%']` filter behaved differently depending on `CUBEJS_TESSERACT_SQL_PLANNER`. Raised in review of the Tesseract half of #11345; master has the same gap, `PrestodbQuery.ts:180` is still the only definition there. Declare the escape character in the base templates so it mirrors `BaseFilter.escapeWildcardChars`, and emit an ESCAPE clause on the dialects that have no default LIKE escape character. Every dialect now binds exactly what its JS counterpart binds, for `contains`/`notContains`/`startsWith`/ `endsWith` alike, with the filter value `folder\name_%`: | dialect | Tesseract param before | after | clause added | fix(schema-compiler): Escape wildcards in startsWith/endsWith filter values `BaseFilter.isWildcardOperator()` covered only contains/notContains, so startsWith/notStartsWith/endsWith/notEndsWith values reached LIKE raw even though `likeIgnoreCase` renders them under the same ESCAPE clause: Presto's from #11345 (2d9fc6d), Oracle's and SQLite's from 30a2057, and Snowflake's long-standing one. A backslash in the value was then read as an escape character: startsWith: ['C:\temp'] -> source LIKE ? || '%' COLLATE NOCASE ESCAPE '\' with param C:\temp Widen it to all six LIKE-based operators, a backport of the line master ships from 43331cc (#10862) which is absent on this branch. Raised in review of the preceding Tesseract LIKE escaping commit. Verified against sqlite3 3.51 and Oracle Free 23ai, which fail differently: SQLite silently reinterprets the pattern, Oracle rejects it outright. | engine, pattern | `C:\temp\x` | `C:temp\x` | | --- | --- | --- | | SQLite, raw param, `LIKE 'C:\temp' \|\| '%' ESCAPE '\'` (before) | no match | match | | SQLite, escaped param, `LIKE 'C:\\temp' \|\| '%' ESCAPE '\'` (after) | match | no match | | SQLite, raw param, no ESCAPE clause (before 30a2057) | match | no match | | Oracle, raw param (before) | ORA-01424 | ORA-01424 | | Oracle, escaped param (after) | match | no match | A value ending in a backslash behaves the same way: `endsWith: ['temp\']` raised ORA-01424 on Oracle and silently stopped matching on SQLite, while the escaped `temp\\` matches `x\temp\` on both. The same class of bug was already there without any ESCAPE clause on dialects whose LIKE treats a backslash as the default escape character (postgres, redshift, mysql, bigquery, clickhouse, cubestore, vertica, crate): `startsWith: ['C:\temp']` matched `C:temp%` there, independently of 30a2057. The native planner was already correct, `BaseFilter::like_or_where` escapes for contains/startsWith/endsWith alike, so this closes the last planner divergence too: both now bind `C:\\temp` on every dialect except MSSQL, whose bracket form deliberately leaves the backslash alone, and Hive, which opts out of native escaping as of the preceding commit. Worth a release note: wildcards in startsWith/endsWith values are now literal, as they already are for contains and as master behaves. A `startsWith: ['100%']` filter used to match anything starting with `100` and now matches values starting with the literal `100%`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> fix(druid/ksql/pinot-driver): Emit ESCAPE for LIKE filters The dialect sweep in 30a2057 and e2f2887 stopped at cubejs-schema-compiler, but `newFilter` is also overridden by query classes that ship inside driver packages. Those inherit the base `escapeWildcardChars` (`\`, `_`, `%` -> `\x`) with nothing on the engine side to consume the escape character: | class | likeIgnoreCase | escape mechanism | | --- | --- | --- | | DruidQuery.ts | `LOWER(c) LIKE CONCAT('%', LOWER(?), '%')` | `x LIKE pattern [ESCAPE esc]`, no default | | KsqlQuery.ts | `c ILIKE CONCAT('%', ?, '%')` | `NOT? LIKE pattern (ESCAPE STRING)?`, no default | | PinotQuery.ts | already carries `ESCAPE '\'` | JS side was fine | `_`/`%` mis-escaping predates #11345 on Druid and ksql, but two things made them worse than before it: the unconditional `\` in `escapeWildcardChars` turned `contains: ['c:\users']` into an unmatchable `c:\\users`, and 81f2bb3 routed startsWith/endsWith through the same path, so `startsWith: ['100%']` now binds `100\%` and matches nothing where it used to match `100...`. Tesseract had the mirror-image gap: e2f2887 declares `filters.like_escape_char` in the base templates, so the native planner escapes on every dialect, but only the schema-compiler dialects got an ESCAPE clause to attach it to. Pinot was therefore correct in the JS planner and inert in the native one. Druid and Pinot also have no ILIKE — Druid's SQL operator reference lists only `x LIKE pattern [ESCAPE esc]` / `x NOT LIKE pattern [ESCAPE esc]`, and both JS filters already stand in for it with `LOWER()` on either side. Their `tesseract.ilike` now mirrors that, the same shape MssqlQuery uses, because the ESCAPE clause binds to the whole right operand and cannot sit inside `LOWER()`. ksqlDB has no ILIKE at all: neither `SqlBase.g4` nor the Confluent operator reference has one, only the LIKE predicate quoted in the table above. So `KsqlFilter`'s `ILIKE` does not parse today, independently of escaping, and this commit does not change that — making it parse means moving to `LIKE` plus case-folding functions, which is a case-insensitivity change rather than an escaping one. The ESCAPE clause is what ksqlDB's LIKE wants either way, and a backslash is plain data inside a ksqlDB string literal, so `'\'` is a single escape character. Verified against the engines' grammars and SQL references, not against running clusters. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> fix(dremio-driver): Correct ILIKE filter rendering Dremio's ILIKE is a function, not an operator, and DremioFilter got two things wrong about the call. `NOT` was spliced into the argument list, and the optional third argument — the escape character, without which there is none — was absent, so the `\` that `BaseFilter.escapeWildcardChars` binds stayed literal data: | filter | before | after | | --- | --- | --- | | `contains: ['demo']` | `ILIKE (c, CONCAT('%', ?, '%'))` | `ILIKE(c, CONCAT('%', ?, '%'), '\')` | | `notContains: ['demo']` | `ILIKE (c NOT, CONCAT(...))` — cannot parse | `NOT ILIKE(c, CONCAT(...), '\')` | | `contains: ['c:\users']` | searched for `c:\\users` | searches for `c:\users` | | `startsWith: ['100%']` | matched anything starting with `100` | matches a literal `100%` | So notContains/notStartsWith/notEndsWith were dead on Dremio before this, the `\` regression came from #11345, and the startsWith/endsWith half came from 81f2bb3 widening `isWildcardOperator`. The native planner had the same hole from the other side: e2f2887 declares `filters.like_escape_char` in the base templates, but `filters.like_pattern` can only append an ESCAPE clause, which the function form has no room for — so `tesseract.ilike` carries the escape argument instead and mirrors the JS filter. Dremio's `expressions.ilike`, used for SQL API push-down, is still the operator form and still wrong; that is a separate shape bug, not an escaping one. Verified against Dremio's ILIKE function reference, not against a running cluster. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> fix(schema-compiler): Don't escape LIKE wildcards for Elasticsearch SQL `ElasticSearchQueryFilter` renders `contains` as `MATCH(c, ?, 'fuzziness=...')`, a full-text match where `%` and `_` are not wildcards and a backslash is ordinary data. Escaping the value there is not inert, it corrupts the search term: `contains: ['user_id']` has been searching for `user\_id` since before #11345, and #11345 added the same for `c:\users` -> `c:\\users`. Its `starts`/`ends` branches do render LIKE, and Elasticsearch SQL has no default escape character, so they would need an explicit ESCAPE clause — but the SQL they emit (`${not} WHERE ${column} LIKE ${param}%`) carries a stray `WHERE` and an unquoted `%` and cannot run at all, which is a separate bug and not fixed here. Overriding `escapeWildcardChars` to a no-op and dropping `filters.like_escape_char` is the same reasoning HiveQuery uses in 5ed14f8: nothing expressible to escape with, so don't pretend. AWSElasticSearchQuery deliberately keeps the base escaping. Its Open Distro / OpenSearch dialect is LIKE-based and follows MySQL, where `\` is the default escape character and no ESCAPE clause is needed, so it re-declares the escape char that ElasticSearchQuery drops. OpenSearch's own LIKE escaping is reportedly buggy (opensearch-project/sql#779), but binding `\%` is what that dialect asks for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> test(questdb-driver): Cover LIKE wildcard escaping in filter values QuestQuery was the last unchecked driver-package dialect in the review of the LIKE escaping series: it does not override `likeIgnoreCase`, so it renders the base `ILIKE '%' || $1 || '%'` with no ESCAPE clause, which reads like the Oracle and SQLite regressions fixed in 30a2057. It isn't one. QuestDB has no ESCAPE clause because a backslash is unconditionally its escape character: `AbstractLikeStrFunctionFactory.escapeSpecialChars` converts the pattern to a Java regex and reads `\%`, `\_` and `\\` as the literal character, and raises "LIKE pattern must not end with escape character" for a pattern ending in a lone `\`. So the base `escapeWildcardChars` is already dialect-correct here, and #11345's backslash escaping made `endsWith: ['temp\']` work rather than error out. No behaviour change, just pinning what the base escaping has to keep binding. Read off QuestDB's source, not confirmed against a running instance. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ects `filters.like_escape_char` was defined only in PrestodbQuery, and `PlanSqlTemplates::like_escape_char()` returns `None` when the template is absent, so `filter_cast_and_allocate_values_escaped` did no escaping at all on every other dialect. The JS planner has always escaped `%`/`_` through `BaseFilter.escapeWildcardChars`, so a `contains: ['100%']` filter behaved differently depending on `CUBEJS_TESSERACT_SQL_PLANNER`. Raised in review of the Tesseract half of #11345; master has the same gap, `PrestodbQuery.ts:180` is still the only definition there. Declare the escape character in the base templates so it mirrors `BaseFilter.escapeWildcardChars`, and emit an ESCAPE clause on the dialects that have no default LIKE escape character. Every dialect now binds exactly what its JS counterpart binds, for `contains`/`notContains`/`startsWith`/ `endsWith` alike, with the filter value `folder\name_%`: | dialect | Tesseract param before | after | clause added | fix(schema-compiler): Escape wildcards in startsWith/endsWith filter values `BaseFilter.isWildcardOperator()` covered only contains/notContains, so startsWith/notStartsWith/endsWith/notEndsWith values reached LIKE raw even though `likeIgnoreCase` renders them under the same ESCAPE clause: Presto's from #11345 (2d9fc6d), Oracle's and SQLite's from 30a2057, and Snowflake's long-standing one. A backslash in the value was then read as an escape character: startsWith: ['C:\temp'] -> source LIKE ? || '%' COLLATE NOCASE ESCAPE '\' with param C:\temp Widen it to all six LIKE-based operators, a backport of the line master ships from 43331cc (#10862) which is absent on this branch. Raised in review of the preceding Tesseract LIKE escaping commit. Verified against sqlite3 3.51 and Oracle Free 23ai, which fail differently: SQLite silently reinterprets the pattern, Oracle rejects it outright. | engine, pattern | `C:\temp\x` | `C:temp\x` | | --- | --- | --- | | SQLite, raw param, `LIKE 'C:\temp' \|\| '%' ESCAPE '\'` (before) | no match | match | | SQLite, escaped param, `LIKE 'C:\\temp' \|\| '%' ESCAPE '\'` (after) | match | no match | | SQLite, raw param, no ESCAPE clause (before 30a2057) | match | no match | | Oracle, raw param (before) | ORA-01424 | ORA-01424 | | Oracle, escaped param (after) | match | no match | A value ending in a backslash behaves the same way: `endsWith: ['temp\']` raised ORA-01424 on Oracle and silently stopped matching on SQLite, while the escaped `temp\\` matches `x\temp\` on both. The same class of bug was already there without any ESCAPE clause on dialects whose LIKE treats a backslash as the default escape character (postgres, redshift, mysql, bigquery, clickhouse, cubestore, vertica, crate): `startsWith: ['C:\temp']` matched `C:temp%` there, independently of 30a2057. The native planner was already correct, `BaseFilter::like_or_where` escapes for contains/startsWith/endsWith alike, so this closes the last planner divergence too: both now bind `C:\\temp` on every dialect except MSSQL, whose bracket form deliberately leaves the backslash alone, and Hive, which opts out of native escaping as of the preceding commit. Worth a release note: wildcards in startsWith/endsWith values are now literal, as they already are for contains and as master behaves. A `startsWith: ['100%']` filter used to match anything starting with `100` and now matches values starting with the literal `100%`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> fix(druid/ksql/pinot-driver): Emit ESCAPE for LIKE filters The dialect sweep in 30a2057 and e2f2887 stopped at cubejs-schema-compiler, but `newFilter` is also overridden by query classes that ship inside driver packages. Those inherit the base `escapeWildcardChars` (`\`, `_`, `%` -> `\x`) with nothing on the engine side to consume the escape character: | class | likeIgnoreCase | escape mechanism | | --- | --- | --- | | DruidQuery.ts | `LOWER(c) LIKE CONCAT('%', LOWER(?), '%')` | `x LIKE pattern [ESCAPE esc]`, no default | | KsqlQuery.ts | `c ILIKE CONCAT('%', ?, '%')` | `NOT? LIKE pattern (ESCAPE STRING)?`, no default | | PinotQuery.ts | already carries `ESCAPE '\'` | JS side was fine | `_`/`%` mis-escaping predates #11345 on Druid and ksql, but two things made them worse than before it: the unconditional `\` in `escapeWildcardChars` turned `contains: ['c:\users']` into an unmatchable `c:\\users`, and 81f2bb3 routed startsWith/endsWith through the same path, so `startsWith: ['100%']` now binds `100\%` and matches nothing where it used to match `100...`. Tesseract had the mirror-image gap: e2f2887 declares `filters.like_escape_char` in the base templates, so the native planner escapes on every dialect, but only the schema-compiler dialects got an ESCAPE clause to attach it to. Pinot was therefore correct in the JS planner and inert in the native one. Druid and Pinot also have no ILIKE — Druid's SQL operator reference lists only `x LIKE pattern [ESCAPE esc]` / `x NOT LIKE pattern [ESCAPE esc]`, and both JS filters already stand in for it with `LOWER()` on either side. Their `tesseract.ilike` now mirrors that, the same shape MssqlQuery uses, because the ESCAPE clause binds to the whole right operand and cannot sit inside `LOWER()`. ksqlDB has no ILIKE at all: neither `SqlBase.g4` nor the Confluent operator reference has one, only the LIKE predicate quoted in the table above. So `KsqlFilter`'s `ILIKE` does not parse today, independently of escaping, and this commit does not change that — making it parse means moving to `LIKE` plus case-folding functions, which is a case-insensitivity change rather than an escaping one. The ESCAPE clause is what ksqlDB's LIKE wants either way, and a backslash is plain data inside a ksqlDB string literal, so `'\'` is a single escape character. Verified against the engines' grammars and SQL references, not against running clusters. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> fix(dremio-driver): Correct ILIKE filter rendering Dremio's ILIKE is a function, not an operator, and DremioFilter got two things wrong about the call. `NOT` was spliced into the argument list, and the optional third argument — the escape character, without which there is none — was absent, so the `\` that `BaseFilter.escapeWildcardChars` binds stayed literal data: | filter | before | after | | --- | --- | --- | | `contains: ['demo']` | `ILIKE (c, CONCAT('%', ?, '%'))` | `ILIKE(c, CONCAT('%', ?, '%'), '\')` | | `notContains: ['demo']` | `ILIKE (c NOT, CONCAT(...))` — cannot parse | `NOT ILIKE(c, CONCAT(...), '\')` | | `contains: ['c:\users']` | searched for `c:\\users` | searches for `c:\users` | | `startsWith: ['100%']` | matched anything starting with `100` | matches a literal `100%` | So notContains/notStartsWith/notEndsWith were dead on Dremio before this, the `\` regression came from #11345, and the startsWith/endsWith half came from 81f2bb3 widening `isWildcardOperator`. The native planner had the same hole from the other side: e2f2887 declares `filters.like_escape_char` in the base templates, but `filters.like_pattern` can only append an ESCAPE clause, which the function form has no room for — so `tesseract.ilike` carries the escape argument instead and mirrors the JS filter. Dremio's `expressions.ilike`, used for SQL API push-down, is still the operator form and still wrong; that is a separate shape bug, not an escaping one. Verified against Dremio's ILIKE function reference, not against a running cluster. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> fix(schema-compiler): Don't escape LIKE wildcards for Elasticsearch SQL `ElasticSearchQueryFilter` renders `contains` as `MATCH(c, ?, 'fuzziness=...')`, a full-text match where `%` and `_` are not wildcards and a backslash is ordinary data. Escaping the value there is not inert, it corrupts the search term: `contains: ['user_id']` has been searching for `user\_id` since before #11345, and #11345 added the same for `c:\users` -> `c:\\users`. Its `starts`/`ends` branches do render LIKE, and Elasticsearch SQL has no default escape character, so they would need an explicit ESCAPE clause — but the SQL they emit (`${not} WHERE ${column} LIKE ${param}%`) carries a stray `WHERE` and an unquoted `%` and cannot run at all, which is a separate bug and not fixed here. Overriding `escapeWildcardChars` to a no-op and dropping `filters.like_escape_char` is the same reasoning HiveQuery uses in 5ed14f8: nothing expressible to escape with, so don't pretend. AWSElasticSearchQuery deliberately keeps the base escaping. Its Open Distro / OpenSearch dialect is LIKE-based and follows MySQL, where `\` is the default escape character and no ESCAPE clause is needed, so it re-declares the escape char that ElasticSearchQuery drops. OpenSearch's own LIKE escaping is reportedly buggy (opensearch-project/sql#779), but binding `\%` is what that dialect asks for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> test(questdb-driver): Cover LIKE wildcard escaping in filter values QuestQuery was the last unchecked driver-package dialect in the review of the LIKE escaping series: it does not override `likeIgnoreCase`, so it renders the base `ILIKE '%' || $1 || '%'` with no ESCAPE clause, which reads like the Oracle and SQLite regressions fixed in 30a2057. It isn't one. QuestDB has no ESCAPE clause because a backslash is unconditionally its escape character: `AbstractLikeStrFunctionFactory.escapeSpecialChars` converts the pattern to a Java regex and reads `\%`, `\_` and `\\` as the literal character, and raises "LIKE pattern must not end with escape character" for a pattern ending in a lone `\`. So the base `escapeWildcardChars` is already dialect-correct here, and #11345's backslash escaping made `endsWith: ['temp\']` work rather than error out. No behaviour change, just pinning what the base escaping has to keep binding. Read off QuestDB's source, not confirmed against a running instance. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
No description provided.