[Feature] Support KeepUnicodeEscape feature to fix Hive regex parsing…#6578
Open
aoeiuvb wants to merge 1 commit intoalibaba:masterfrom
Open
[Feature] Support KeepUnicodeEscape feature to fix Hive regex parsing…#6578aoeiuvb wants to merge 1 commit intoalibaba:masterfrom
aoeiuvb wants to merge 1 commit intoalibaba:masterfrom
Conversation
Member
|
The escape handling changes should be conditional. The fix should look something like: switch (ch) {
case 'u':
if ((features & SQLParserFeature.KeepUnicodeEscape.mask) != 0) {
putChar('\\');
putChar('u');
} else if ((features & SQLParserFeature.SupportUnicodeCodePoint.mask) != 0) {
// existing unicode decode logic
}
break;
// KEEP all existing cases: '0', '\'', '"', 'b', 'n', 'r', 't', '\\', 'Z', '%', '_'
case '0':
putChar('\0');
break;
// ... etc
default:
putChar(ch);
break;
}The HiveOutputVisitor change should similarly be conditional — only change backslash handling when KeepUnicodeEscape is active. |
Member
|
Unconditional removal of all escape sequence handling (HiveLexer.java) The PR removes the case branches for \0, ', ", \b, \n, \r, \t, \, \Z, %, _ and replaces them with a blanket default that does putChar('\'); putChar(ch). This change is not gated behind KeepUnicodeEscape — it applies to all Hive SQL parsing unconditionally. This means:
This is a breaking behavioral change that goes far beyond the stated goal of preserving Unicode escapes. Strings containing standard escape sequences will parse differently than before. |
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.
1. Problem Description
In Hive SQL, regular expressions often use Unicode escape sequences to match specific character ranges, for example:
Current Issue:
When formatting this SQL, the parser currently converts Unicode escapes (starting with
\u) into actual characters (e.g., converting\u4e00to一).However, SQL formatting should only beautify the layout (such as newlines and indentation) and should not alter the original content or literal values of the SQL. Converting these escapes can break the semantics of regular expressions or cause encoding issues.
2. Changes
I have introduced a new feature
SQLParserFeature.KeepUnicodeEscapeto address this issue.KeepUnicodeEscape.\uinto specific characters (overriding the behavior ofSupportUnicodeCodePoint).3. Verification
I have added a new unit test class
HiveRegContainUnicodeTestto verify the fix.KeepUnicodeEscape, the parser follows the defaultSupportUnicodeCodePointbehavior (legacy behavior).KeepUnicodeEscapeis enabled, the Unicode escapes (e.g.,\u4e00) are not escaped/decoded and are output exactly as the original input string.