From 862753afbad4f27d4884ffde7dbc9d03ddf117f8 Mon Sep 17 00:00:00 2001 From: LiBinfeng Date: Mon, 17 Mar 2025 19:35:57 +0800 Subject: [PATCH] [fix](Nereids) initcap constant folding should upper first character in all words (#49061) --- .../functions/executable/StringArithmetic.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java index e54eb745e2b62d..87b817134e0922 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java @@ -420,12 +420,9 @@ public static Expression characterLength(StringLikeLiteral first) { return new IntegerLiteral(first.getValue().codePointCount(0, first.getValue().length())); } - private static boolean isSeparator(char c) { - if (".$|()[{^?*+\\".indexOf(c) == -1) { - return false; - } else { - return true; - } + private static boolean isAlphabetic(char c) { + Pattern pattern = Pattern.compile("\\p{Alnum}"); + return pattern.matcher(String.valueOf(c)).find(); } /** @@ -437,7 +434,7 @@ public static Expression initCap(StringLikeLiteral first) { boolean capitalizeNext = true; for (char c : first.getValue().toCharArray()) { - if (Character.isWhitespace(c) || isSeparator(c)) { + if (Character.isWhitespace(c) || !isAlphabetic(c)) { result.append(c); capitalizeNext = true; // Next character should be capitalized } else if (capitalizeNext) {