Skip to content

[WIP][SQL] Return zero for instr with zero start and empty substring - #59346

Draft
zhangxinyao88 wants to merge 1 commit into
apache:masterfrom
zhangxinyao88:fix-instr-zero-start
Draft

zhangxinyao88 wants to merge 1 commit into
apache:masterfrom
zhangxinyao88:fix-instr-zero-start

Conversation

@zhangxinyao88

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Check start = 0 before handling an empty search pattern in the binary, lowercase, and ICU implementations of instr.

Why are the changes needed?

The documented behavior of instr is to return zero when the start position is zero. The empty-pattern handling currently runs first and returns 1 instead.

Does this PR introduce any user-facing change?

Yes. Before this fix, instr('abc', '', 0, 1) returns 1. After this fix, it returns 0, matching the documented behavior.

How was this patch tested?

Added regression tests covering four collation groups, empty and nonempty input, ASCII and Unicode input, and multiple occurrences, including interpreted and generated SQL execution.

The regressions failed before the fix. After the fix, all 58 focused Java tests and all 74 StringExpressionsSuite tests passed, and the Maven reactor succeeded.

Commit: 6b95d5517b9f4dc0f1d69a790aa3abef39b71c47.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-6)

This branch has not been deployed

No deployments
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