Skip to content

fix: set escape_char when simplifying starts_with to LIKE#21086

Open
jackye1995 wants to merge 2 commits intoapache:mainfrom
jackye1995:fix-starts-with-escape-char
Open

fix: set escape_char when simplifying starts_with to LIKE#21086
jackye1995 wants to merge 2 commits intoapache:mainfrom
jackye1995:fix-starts-with-escape-char

Conversation

@jackye1995
Copy link

Summary

The starts_with simplification escapes special LIKE characters (%, _, \) with backslash but did not set escape_char in the resulting LIKE expression. This caused the escaped characters to be treated as literals instead of escape sequences.

Problem

When starts_with(col, 'test_ns') is simplified to col LIKE 'test\_ns%', the escape_char was set to None. This meant the \_ was not recognized as an escaped underscore, and the underscore was incorrectly interpreted as a LIKE wildcard matching any single character.

Example

-- Input
starts_with(namespace, 'test_ns$')

-- Before fix (incorrect)
namespace LIKE 'test\_ns$%'  -- escape_char: None
-- The `_` is treated as wildcard, matching any char

-- After fix (correct)  
namespace LIKE 'test\_ns$%'  -- escape_char: Some('\\')
-- The `\_` is correctly interpreted as literal underscore

Fix

Set escape_char: Some('\\') when creating the LIKE expression, since the simplification already uses backslash to escape special characters.

Testing

  • Existing starts_with tests pass
  • Verified fix resolves query correctness issues in downstream projects (Lance)

🤖 Generated with Claude Code

The `starts_with` simplification escapes special LIKE characters
(%, _, \) with backslash but did not set escape_char in the
resulting LIKE expression. This caused the escaped characters
to be treated as literals instead of escape sequences.

For example, `starts_with(col, 'test_ns')` was simplified to:
`col LIKE 'test\_ns%'` with `escape_char: None`

This meant the `\_` was not recognized as an escaped underscore,
causing incorrect query results when the prefix contained
special LIKE pattern characters.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added the functions Changes to functions implementation label Mar 20, 2026
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant