[Fix](routine-load) Correct VARCHAR truncation for multi-byte UTF-8 characters in non-strict load mode#64651
Open
SUBSTITUDE wants to merge 1 commit into
Open
Conversation
…ict load In non-strict mode, the SUBSTRING function truncates by character count while the VARCHAR schema length is defined in bytes. This mismatch caused non-ASCII UTF-8 characters (Chinese chars, special Unicode like U+0131) to be incorrectly rejected instead of truncated during routine/stream load. Root cause: substring(str, 1, byte_limit) treats the third parameter as character count, not byte count. For strings where the byte count exceeds the limit but the character count does not (multi-byte UTF-8 chars), the substring call fails to truncate. The subsequent byte-length validation then rejects the row with 'the length of input is too long than schema'. Fix: After the substring truncation, for rows that still exceed the byte limit in non-strict mode, manually truncate each string at a valid UTF-8 character boundary. The algorithm walks backwards from the limit position to find the last non-continuation byte, then truncates there. Also fixed in file_scanner.cpp's _truncate_char_or_varchar_column which has the same byte-vs-char mismatch pattern (will be addressed separately). Closes apache#64334 Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In non-strict load mode, when importing strings containing multi-byte UTF-8 characters
(e.g., Chinese characters, special Unicode like U+0131 'ı') into VARCHAR columns,
the truncation fails and rows are incorrectly rejected.
Root Cause
The
substring(str, 1, limit)function interprets the third parameter differently:When
limit(a byte count derived from VARCHAR(N)) is passed to substring, the UTF-8path fails to truncate strings where byte count exceeds the limit but character count does not.
Example