[
https://issues.apache.org/jira/browse/FLINK-39402?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Qilong Wang updated FLINK-39402:
--------------------------------
Description:
The LIKE expression uses \ as the default escape character when no ESCAPE
clause is specified(FLINK-36100). However, the quick path for 2-operand LIKE
did not apply escape handling at all. Only \_ happened to produce correct
results, while all other escape sequences were broken:
{code:java}
– \ escapes '' to match a literal '' — correct
SELECT 'TE_ST' LIKE 'TE_ST'
– \ escapes % to match a literal % — should be TRUE, but returns FALSE
SELECT 'TE%ST' LIKE 'TE\%ST'
– \ followed by invalid character S — should throw RuntimeException, but
returns FALSE
SELECT 'TEST' LIKE '%E\S%'
– \ at the end of pattern — should throw RuntimeException, but returns FALSE
SELECT 'TEST' LIKE '%E-S%\'{code}
The fix unifies escape handling for both 2-operand (no ESCAPE clause) and
3-operand LIKE expressions, ensuring the default escape character \ is properly
applied in the quick path.
was:
The LIKE expression uses \ as the default escape character when no ESCAPE
clause is specified(FLINK-36100). However, the escaped _ and % behave
inconsistently:
{code:java}
– '\' escapes '' to match a literal '' — correct
SELECT 'TE_ST' LIKE 'TE_ST' – TRUE
– '\' escapes '%' to match a literal '%' — should be TRUE, but returns FALSE
SELECT 'TE%ST' LIKE 'TE%ST' – FALSE {code}
Both _ and % should be treated as escaped literals under the default escape
character \. The fix unifies escape handling so that % is correctly recognized
as a literal %, consistent with _.
> Fix LIKE quick path ignoring default escape character '\'
> ---------------------------------------------------------
>
> Key: FLINK-39402
> URL: https://issues.apache.org/jira/browse/FLINK-39402
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Affects Versions: 2.3.0
> Reporter: Qilong Wang
> Priority: Major
> Labels: pull-request-available
> Fix For: 2.3.0
>
>
> The LIKE expression uses \ as the default escape character when no ESCAPE
> clause is specified(FLINK-36100). However, the quick path for 2-operand LIKE
> did not apply escape handling at all. Only \_ happened to produce correct
> results, while all other escape sequences were broken:
> {code:java}
> – \ escapes '' to match a literal '' — correct
> SELECT 'TE_ST' LIKE 'TE_ST'
> – \ escapes % to match a literal % — should be TRUE, but returns FALSE
> SELECT 'TE%ST' LIKE 'TE\%ST'
> – \ followed by invalid character S — should throw RuntimeException, but
> returns FALSE
> SELECT 'TEST' LIKE '%E\S%'
> – \ at the end of pattern — should throw RuntimeException, but returns FALSE
> SELECT 'TEST' LIKE '%E-S%\'{code}
> The fix unifies escape handling for both 2-operand (no ESCAPE clause) and
> 3-operand LIKE expressions, ensuring the default escape character \ is
> properly applied in the quick path.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)