Skip to content

[FLINK-39424][table] Setting LIKE does not support default escape characters#27920

Open
Au-Miner wants to merge 1 commit intoapache:masterfrom
Au-Miner:FLINK-39424
Open

[FLINK-39424][table] Setting LIKE does not support default escape characters#27920
Au-Miner wants to merge 1 commit intoapache:masterfrom
Au-Miner:FLINK-39424

Conversation

@Au-Miner
Copy link
Copy Markdown
Contributor

What is the purpose of the change

Remove the default escape character \ in LIKE when no ESCAPE clause is specified. Since Flink's string literal also does not support backslashes, the default escape character causes confusion.

Brief change log

  • Removed default escape \ in LikeCallGen, unified escape handling for 2-operand and 3-operand cases using Option[Char]
  • Added test cases for no-default-escape and explicit ESCAPE scenarios in ScalarFunctionsTest

Verifying this change

This change is verified by FlinkSqlLikeUtilsTest.java and ScalarFunctionsTest.scala (#testLike / #testLikeWithEscape).

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): yes
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? not applicable

@flinkbot
Copy link
Copy Markdown
Collaborator

flinkbot commented Apr 12, 2026

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

}
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.

// 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);

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants