Skip to content

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

Open
snuyanzin wants to merge 1 commit into
apache:mainfrom
snuyanzin:calcite7578
Open

[CALCITE-7578] LIKE with empty ESCAPE might fail with StringIndexOutOfBoundsException#4989
snuyanzin wants to merge 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

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