diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java index 34646c1d6579534..3699f26578f9293 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java @@ -24,6 +24,7 @@ import org.apache.doris.nereids.DorisLexer; import org.apache.doris.nereids.DorisParser; import org.apache.doris.nereids.StatementContext; +import org.apache.doris.nereids.analyzer.UnboundSlot; import org.apache.doris.nereids.glue.LogicalPlanAdapter; import org.apache.doris.nereids.parser.plsql.PLSqlLogicalPlanBuilder; import org.apache.doris.nereids.trees.expressions.Expression; @@ -256,9 +257,29 @@ public List> parseMultiple(String sql, } public Expression parseExpression(String expression) { + if (isSimpleIdentifier(expression)) { + return new UnboundSlot(expression); + } return parse(expression, DorisParser::expression); } + private boolean isSimpleIdentifier(String expression) { + if (expression == null || expression.length() == 0) { + return false; + } + + boolean hasLetter = false; + for (int i = 0; i < expression.length(); i++) { + char c = expression.charAt(i); + if ((('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_' || c == '$')) { + hasLetter = true; + } else if (!('0' <= c && c <= '9')) { + return false; + } + } + return hasLetter; + } + public DataType parseDataType(String dataType) { return parse(dataType, DorisParser::dataType); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java index 42b99f6effdb842..c111839fc5093ec 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java @@ -58,8 +58,16 @@ public class Utils { */ public static String quoteIfNeeded(String part) { // We quote strings except the ones which consist of digits only. - return part.matches("\\w*[\\w&&[^\\d]]+\\w*") - ? part : part.replace("`", "``"); + StringBuilder quote = new StringBuilder(part.length()); + for (int i = 0; i < part.length(); i++) { + char c = part.charAt(i); + if (c == '`') { + quote.append("``"); + } else { + quote.append(c); + } + } + return quote.toString(); } /**