trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.24k stars 2.95k forks source link

LIKE predicate does not fail when the escape character is '' (empty) #7273

Open kasiafi opened 3 years ago

kasiafi commented 3 years ago
trino:tiny> SELECT 'some_string' LIKE 'abc' ESCAPE '';
 _col0
-------
 false
(1 row)
trino:tiny> SELECT x LIKE y ESCAPE z FROM (VALUES ('some_string', 'abc', '')) t(x, y, z);
 _col0
-------
 false
(1 row)

There is a check in LikeFunctions.getEscapeCharacter(Optional<Slice> escape) that is supposed to catch it, but it is only accessed through certain paths.

martint commented 3 years ago

This should be validated during analysis for the case of a literal escape string.

kasiafi commented 3 years ago

It will not fix the issue:

trino:tiny> SELECT x, 'some_string' LIKE 'abc' ESCAPE x FROM (SELECT IF(name > 'B', '#', '') FROM region) t(x);
 x | _col1
---+-------
   | false
   | false
   | false
 # | false
 # | false
(5 rows)