Skip to content

[CALCITE-7578] LIKE with empty ESCAPE might fail with StringIndexOutOfBoundsException#4989

Merged
snuyanzin merged 1 commit into
apache:mainfrom
snuyanzin:calcite7578
Jun 5, 2026
Merged

[CALCITE-7578] LIKE with empty ESCAPE might fail with StringIndexOutOfBoundsException#4989
snuyanzin merged 1 commit into
apache:mainfrom
snuyanzin:calcite7578

Conversation

@snuyanzin
Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7578

Changes Proposed

The PR improves RexSimplify for the case of LIKE with empty ESCAPE to make it not failing with StringIndexOutOfBoundsException

rexBuilder.makeLiteral(simplifyLikeString(likeStr, escape, '%'),
e.operands.get(1).getType(), true, true), escapeLiteral);
final String escapeStr = requireNonNull(escapeLiteral.getValueAs(String.class));
if (escapeStr.length() == 1) {
Copy link
Copy Markdown
Contributor Author

@snuyanzin snuyanzin Jun 4, 2026

Choose a reason for hiding this comment

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

if it not equals to 1 it will fail further with a nicer message at

static String sqlToRegexLike(
String sqlPattern,
@Nullable CharSequence escapeStr) {
final char escapeChar;
if (escapeStr != null) {
if (escapeStr.length() != 1) {
throw invalidEscapeCharacter(escapeStr.toString());
}
escapeChar = escapeStr.charAt(0);
} else {
escapeChar = 0;
}
return sqlToRegexLike(sqlPattern, escapeChar);
}

Copy link
Copy Markdown
Member

@xuzifu666 xuzifu666 left a comment

Choose a reason for hiding this comment

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

LGTM, after the CI passed.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 4, 2026

@snuyanzin
Copy link
Copy Markdown
Contributor Author

rebasing to the recent main before merging

@snuyanzin snuyanzin merged commit be06443 into apache:main Jun 5, 2026
16 checks passed
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.

2 participants