This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new fbab935e85d [clean](planner)alias function removes dependency on the
old optimizer (#51509)
fbab935e85d is described below
commit fbab935e85dd06d768795bab1b11b8844cfd0aca
Author: zhangdong <[email protected]>
AuthorDate: Fri Jun 13 14:30:52 2025 +0800
[clean](planner)alias function removes dependency on the old optimizer
(#51509)
Manually spell function expr, no longer parse SQL
---
.../org/apache/doris/catalog/AliasFunction.java | 65 +++++++---------------
1 file changed, 19 insertions(+), 46 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/AliasFunction.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/AliasFunction.java
index 6ee9e2a4fec..4b3ab644ffc 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/AliasFunction.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/AliasFunction.java
@@ -21,15 +21,13 @@ import org.apache.doris.analysis.CastExpr;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.FunctionCallExpr;
import org.apache.doris.analysis.FunctionName;
-import org.apache.doris.analysis.SelectStmt;
+import org.apache.doris.analysis.FunctionParams;
+import org.apache.doris.analysis.IntLiteral;
import org.apache.doris.analysis.SlotRef;
-import org.apache.doris.analysis.SqlParser;
-import org.apache.doris.analysis.SqlScanner;
+import org.apache.doris.analysis.StringLiteral;
import org.apache.doris.analysis.TypeDef;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.io.Text;
-import org.apache.doris.common.util.SqlParserUtils;
-import org.apache.doris.qe.SqlModeHelper;
import org.apache.doris.thrift.TFunctionBinaryType;
import com.google.common.base.Strings;
@@ -41,7 +39,6 @@ import org.apache.logging.log4j.Logger;
import java.io.DataInput;
import java.io.IOException;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -84,50 +81,26 @@ public class AliasFunction extends Function {
}
public static void initBuiltins(FunctionSet functionSet) {
- String oriStmt = "select concat(left(id,3),'****',right(id,4));";
- try {
- /**
- * Please ensure that the condition checks in {@link #analyze} are
satisfied
- */
- functionSet.addBuiltin(createBuiltin(DIGITAL_MASKING,
Lists.newArrayList(Type.BIGINT), Type.VARCHAR,
- false, Lists.newArrayList("id"), getExpr(oriStmt), true,
false));
- functionSet.addBuiltin(createBuiltin(DIGITAL_MASKING,
Lists.newArrayList(Type.BIGINT), Type.VARCHAR,
- false, Lists.newArrayList("id"), getExpr(oriStmt), true,
true));
+ /**
+ * Please ensure that the condition checks in {@link #analyze} are
satisfied
+ */
+ functionSet.addBuiltin(createBuiltin(DIGITAL_MASKING,
Lists.newArrayList(Type.BIGINT), Type.VARCHAR,
+ false, Lists.newArrayList("id"), getConcatFunctionExpr(),
true, false));
- } catch (AnalysisException e) {
- LOG.error("Add builtin alias function error {}", e);
- }
- }
+ functionSet.addBuiltin(createBuiltin(DIGITAL_MASKING,
Lists.newArrayList(Type.BIGINT), Type.VARCHAR,
+ false, Lists.newArrayList("id"), getConcatFunctionExpr(),
true, true));
- public static Expr getExpr(String sql) throws AnalysisException {
- SelectStmt parsedStmt;
- // Parse statement with parser generated by CUP&FLEX
- SqlScanner input = new SqlScanner(new StringReader(sql),
SqlModeHelper.MODE_DEFAULT);
- SqlParser parser = new SqlParser(input);
- try {
- parsedStmt = (SelectStmt) SqlParserUtils.getFirstStmt(parser);
- } catch (Error e) {
- LOG.info("error happened when parsing stmt {}", sql, e);
- throw new AnalysisException("sql parsing error, please check your
sql");
- } catch (AnalysisException e) {
- String syntaxError = parser.getErrorMsg(sql);
- LOG.info("analysis exception happened when parsing stmt {}, error:
{}",
- sql, syntaxError, e);
- if (syntaxError == null) {
- throw e;
- } else {
- throw new AnalysisException(syntaxError, e);
- }
- } catch (Exception e) {
- // TODO(lingbin): we catch 'Exception' to prevent unexpected error,
- // should be removed this try-catch clause future.
- LOG.info("unexpected exception happened when parsing stmt {},
error: {}",
- sql, parser.getErrorMsg(sql), e);
- throw new AnalysisException("Unexpected exception: " +
e.getMessage());
- }
+ }
- return parsedStmt.getSelectList().getItems().get(0).getExpr();
+ public static Expr getConcatFunctionExpr() {
+ // "concat(left(id,3),'****',right(id,4));";
+ FunctionCallExpr left = new FunctionCallExpr("left",
+ new FunctionParams(Lists.newArrayList(new SlotRef(null, "id"),
new IntLiteral(3))));
+ FunctionCallExpr right = new FunctionCallExpr("right",
+ new FunctionParams(Lists.newArrayList(new SlotRef(null, "id"),
new IntLiteral(4))));
+ return new FunctionCallExpr("concat",
+ new FunctionParams(Lists.newArrayList(left, new
StringLiteral("****"), right)));
}
private static AliasFunction createBuiltin(String name, ArrayList<Type>
argTypes, Type retType,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]