Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 committed Dec 20, 2024
1 parent db3aff9 commit f754d8e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,9 +257,29 @@ public List<Pair<LogicalPlan, StatementContext>> 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);
}
Expand Down
12 changes: 10 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit f754d8e

Please sign in to comment.