Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/data/sql_functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ comparison:
description: By default (or with the ASYMMETRIC keyword), returns TRUE if value1 is less than value2 or greater than value3. With the SYMMETRIC keyword, returns TRUE if value1 is not inclusively between value2 and value3. When either value2 or value3 is NULL, returns TRUE or UNKNOWN. E.g., 12 NOT BETWEEN 15 AND 12 returns TRUE; 12 NOT BETWEEN SYMMETRIC 15 AND 12 returns FALSE; 12 NOT BETWEEN NULL AND 15 returns UNKNOWN; 12 NOT BETWEEN 15 AND NULL returns TRUE; 12 NOT BETWEEN SYMMETRIC 12 AND NULL returns UNKNOWN.
- sql: string1 LIKE string2 [ ESCAPE char ]
table: string1.like(string2[, char])
description: Returns TRUE if string1 matches pattern string2; returns UNKNOWN if string1 or string2 is NULL. An escape character consisting of a single char can be defined if necessary, `\` by default.
description: Returns TRUE if string1 matches pattern string2; returns UNKNOWN if string1 or string2 is NULL. An escape character consisting of a single char can be defined using the ESCAPE clause if necessary. There is no default escape character.
- sql: string1 NOT LIKE string2 [ ESCAPE char ]
description: Returns TRUE if string1 does not match pattern string2; returns UNKNOWN if string1 or string2 is NULL. An escape character consisting of a single char can be defined if necessary, `\` by default.
description: Returns TRUE if string1 does not match pattern string2; returns UNKNOWN if string1 or string2 is NULL. An escape character consisting of a single char can be defined using the ESCAPE clause if necessary. There is no default escape character.
- sql: string1 SIMILAR TO string2 [ ESCAPE char ]
table: string1.similar(string2)
description: Returns TRUE if string1 matches SQL regular expression string2; returns UNKNOWN if string1 or string2 is NULL. An escape character can be defined if necessary. The escape character has not been supported yet.
Expand Down
4 changes: 2 additions & 2 deletions docs/data/sql_functions_zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ comparison:
table: string1.like(string2[, char])
description: |
如果 string1 匹配 string2 返回 `TRUE`;如果 string1 或 string2 为 `NULL` 返回 `UNKNOWN`。
如果需要可以定义包含单个字符的转义字符,默认为 `\`
如果需要,可以通过 ESCAPE 子句定义包含单个字符的转义字符。默认没有转义字符
- sql: string1 NOT LIKE string2 [ ESCAPE char ]
description: |
如果 string1 与 string2 不匹配返回 `TRUE`;如果 string1 或 string2 为 `NULL` 返回 `UNKNOWN`。
如果需要可以定义包含单个字符的转义字符,默认为 `\`
如果需要,可以通过 ESCAPE 子句定义包含单个字符的转义字符。默认没有转义字符
- sql: string1 SIMILAR TO string2 [ ESCAPE char ]
table: string1.similar(string2)
description: |
Expand Down
6 changes: 3 additions & 3 deletions flink-python/pyflink/table/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,10 +1219,10 @@ def like(self,
pattern: Union[str, 'Expression[str]'] = None,
escape=None) -> 'Expression[bool]':
"""
Returns true, if a string matches the specified LIKE pattern
Returns true, if a string matches the specified LIKE pattern.
e.g. 'Jo_n%' matches all strings that start with 'Jo(arbitrary letter)n'.
An escape character consisting of a single char can be defined if necessary,
'\\' by default.
An escape character consisting of a single char can be defined if necessary.
There is no default escape character.
"""
if escape is None:
return _binary_op("like")(self, pattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,8 @@ public OutType initCap() {
}

/**
* Returns true, if a string matches the specified LIKE pattern with default escape character
* '/'.
* Returns true, if a string matches the specified LIKE pattern. There is no default escape
* character.
*
* <p>e.g. "Jo_n%" matches all strings that start with "Jo(arbitrary letter)n"
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static String sqlToRegexLike(String sqlPattern, CharSequence escapeStr) {
}
escapeChar = escapeStr.charAt(0);
} else {
escapeChar = '\\';
Copy link
Copy Markdown
Contributor

@twalthr twalthr Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Au-Miner Could you double check all changes made in ae4eb7d#diff-b2e1701d6c7cae434d495536a397325850d12a59023d320cbad9389aa7d17b2d Don't we also need to restore the other lines SqlLikeUtils. If a character (doesn't need to be the escape charater) is a special regex character, we need to escape it.

escapeChar = 0;
}
return sqlToRegexLike(sqlPattern, escapeChar);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void testSqlLike() {
assertThat(SqlLikeUtils.like("abcd", "a.*d", "\\")).isEqualTo(false);
assertThat(SqlLikeUtils.like("abcde", "%c.e", "\\")).isEqualTo(false);

// default escape character
// no default escape character - backslash is treated as a literal character
assertThat(SqlLikeUtils.like("a-c", "a\\_c")).isEqualTo(false);
assertThat(SqlLikeUtils.like("a_c", "a\\_c")).isEqualTo(true);
assertThat(SqlLikeUtils.like("a_c", "a\\_c")).isEqualTo(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add
assertThat(SqlLikeUtils.like("a\\_c", "a\\_c")).isEqualTo(true);


// -------------------------------- sqlToRegexLike ----------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {
testAllApis("abcxxxdef".like("%abc%qef%"), "'abcxxxdef' LIKE '%abc%qef%'", "FALSE")
testAllApis("abcxxxdef".like("abc%qef"), "'abcxxxdef' LIKE 'abc%qef'", "FALSE")

// reported in FLINK-36100
// reported in FLINK-36100 - without ESCAPE clause, '\' is a literal character
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if we have an escape character defined as _ or % or * . Can we test that these will be rejected?

testAllApis("TE_ST".like("%E_S%"), "'TE_ST' LIKE '%E_S%'", "TRUE")
testAllApis("TE-ST".like("%E_S%"), "'TE-ST' LIKE '%E_S%'", "TRUE")
testAllApis("TE_ST".like("%E\\_S%"), "'TE_ST' LIKE '%E\\_S%'", "TRUE")
testAllApis("TE_ST".like("%E\\_S%"), "'TE_ST' LIKE '%E\\_S%'", "FALSE")
testAllApis("TE-ST".like("%E\\_S%"), "'TE-ST' LIKE '%E\\_S%'", "FALSE")
}

Expand All @@ -420,10 +420,10 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {
testAllApis(!'f0.like("Th_s%"), "f0 NOT LIKE 'Th_s%'", "FALSE")
testAllApis(!'f0.like("%is a%"), "f0 NOT LIKE '%is a%'", "FALSE")

// reported in FLINK-36100
// reported in FLINK-36100 - without ESCAPE clause, '\' is a literal character
testSqlApi("'TE_ST' NOT LIKE '%E_S%'", "FALSE")
testSqlApi("'TE-ST' NOT LIKE '%E_S%'", "FALSE")
testSqlApi("'TE_ST' NOT LIKE '%E\\_S%'", "FALSE")
testSqlApi("'TE_ST' NOT LIKE '%E\\_S%'", "TRUE")
testSqlApi("'TE-ST' NOT LIKE '%E\\_S%'", "TRUE")
}

Expand Down