(udf) create native function return error (#17021)
after 1.2.0, doris does not support native udf, return error when create native function
This commit is contained in:
@ -105,7 +105,7 @@ public class CreateFunctionStmt extends DdlStmt {
|
||||
private final Map<String, String> properties;
|
||||
private final List<String> parameters;
|
||||
private final Expr originFunction;
|
||||
TFunctionBinaryType binaryType = TFunctionBinaryType.NATIVE;
|
||||
TFunctionBinaryType binaryType = TFunctionBinaryType.JAVA_UDF;
|
||||
|
||||
// needed item set after analyzed
|
||||
private String userFile;
|
||||
@ -209,11 +209,15 @@ public class CreateFunctionStmt extends DdlStmt {
|
||||
intermediateType = returnType;
|
||||
}
|
||||
|
||||
String type = properties.getOrDefault(BINARY_TYPE, "NATIVE");
|
||||
String type = properties.getOrDefault(BINARY_TYPE, "JAVA_UDF");
|
||||
binaryType = getFunctionBinaryType(type);
|
||||
if (binaryType == null) {
|
||||
throw new AnalysisException("unknown function type");
|
||||
}
|
||||
if (type.equals("NATIVE")) {
|
||||
throw new AnalysisException("do not support 'NATIVE' udf type after doris version 1.2.0,"
|
||||
+ "please use JAVA_UDF or RPC instead");
|
||||
}
|
||||
|
||||
userFile = properties.getOrDefault(FILE_KEY, properties.get(OBJECT_FILE_KEY));
|
||||
if (Strings.isNullOrEmpty(userFile)) {
|
||||
|
||||
@ -366,7 +366,7 @@ public class AggregateFunction extends Function {
|
||||
}
|
||||
|
||||
public static AggregateFunctionBuilder createUdfBuilder() {
|
||||
return new AggregateFunctionBuilder(TFunctionBinaryType.NATIVE);
|
||||
return new AggregateFunctionBuilder(TFunctionBinaryType.JAVA_UDF);
|
||||
}
|
||||
|
||||
public AggregateFunctionBuilder name(FunctionName name) {
|
||||
|
||||
@ -74,7 +74,7 @@ public class AliasFunction extends Function {
|
||||
public static AliasFunction createFunction(FunctionName functionName, Type[] argTypes, Type retType,
|
||||
boolean hasVarArgs, List<String> parameters, Expr originFunction) {
|
||||
AliasFunction aliasFunction = new AliasFunction(functionName, Arrays.asList(argTypes), retType, hasVarArgs);
|
||||
aliasFunction.setBinaryType(TFunctionBinaryType.NATIVE);
|
||||
aliasFunction.setBinaryType(TFunctionBinaryType.JAVA_UDF);
|
||||
aliasFunction.setUserVisible(true);
|
||||
aliasFunction.originFunction = originFunction;
|
||||
aliasFunction.parameters = parameters;
|
||||
|
||||
@ -90,22 +90,15 @@ public class CreateFunctionTest {
|
||||
Database db = Env.getCurrentInternalCatalog().getDbNullable("default_cluster:db1");
|
||||
Assert.assertNotNull(db);
|
||||
|
||||
String createFuncStr = "create function db1.my_add(VARCHAR(1024)) RETURNS BOOLEAN properties\n"
|
||||
+ "(\n"
|
||||
+ "\"symbol\" = \"_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_9StringValE\",\n"
|
||||
+ "\"prepare_fn\" = \"_ZN9doris_udf13AddUdfPrepareEPNS_15FunctionContextENS0_18FunctionStateScopeE\",\n"
|
||||
+ "\"close_fn\" = \"_ZN9doris_udf11AddUdfCloseEPNS_15FunctionContextENS0_18FunctionStateScopeE\",\n"
|
||||
+ "\"object_file\" = \"http://127.0.0.1:8008/libcmy_udf.so\"\n"
|
||||
+ ");";
|
||||
|
||||
// create alias function
|
||||
String createFuncStr = "create alias function db1.id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));";
|
||||
CreateFunctionStmt createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx);
|
||||
Env.getCurrentEnv().createFunction(createFunctionStmt);
|
||||
|
||||
List<Function> functions = db.getFunctions();
|
||||
Assert.assertEquals(1, functions.size());
|
||||
Assert.assertTrue(functions.get(0).isUdf());
|
||||
|
||||
String queryStr = "select db1.my_add(null)";
|
||||
String queryStr = "select db1.id_masking(13888888888);";
|
||||
ctx.getState().reset();
|
||||
StmtExecutor stmtExecutor = new StmtExecutor(ctx, queryStr);
|
||||
stmtExecutor.execute();
|
||||
@ -120,29 +113,6 @@ public class CreateFunctionTest {
|
||||
Assert.assertEquals(1, constExprLists.get(0).size());
|
||||
Assert.assertTrue(constExprLists.get(0).get(0) instanceof FunctionCallExpr);
|
||||
|
||||
// create alias function
|
||||
createFuncStr = "create alias function db1.id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));";
|
||||
createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx);
|
||||
Env.getCurrentEnv().createFunction(createFunctionStmt);
|
||||
|
||||
functions = db.getFunctions();
|
||||
Assert.assertEquals(2, functions.size());
|
||||
|
||||
queryStr = "select db1.id_masking(13888888888);";
|
||||
ctx.getState().reset();
|
||||
stmtExecutor = new StmtExecutor(ctx, queryStr);
|
||||
stmtExecutor.execute();
|
||||
Assert.assertNotEquals(QueryState.MysqlStateType.ERR, ctx.getState().getStateType());
|
||||
planner = stmtExecutor.planner();
|
||||
Assert.assertEquals(1, planner.getFragments().size());
|
||||
fragment = planner.getFragments().get(0);
|
||||
Assert.assertTrue(fragment.getPlanRoot() instanceof UnionNode);
|
||||
unionNode = (UnionNode) fragment.getPlanRoot();
|
||||
constExprLists = Deencapsulation.getField(unionNode, "constExprLists");
|
||||
Assert.assertEquals(1, constExprLists.size());
|
||||
Assert.assertEquals(1, constExprLists.get(0).size());
|
||||
Assert.assertTrue(constExprLists.get(0).get(0) instanceof FunctionCallExpr);
|
||||
|
||||
queryStr = "select db1.id_masking(k1) from db1.tbl1";
|
||||
Assert.assertTrue(dorisAssert.query(queryStr).explainQuery().contains("concat(left(`k1`, 3), '****', right(`k1`, 4))"));
|
||||
|
||||
@ -154,7 +124,7 @@ public class CreateFunctionTest {
|
||||
Env.getCurrentEnv().createFunction(createFunctionStmt);
|
||||
|
||||
functions = db.getFunctions();
|
||||
Assert.assertEquals(3, functions.size());
|
||||
Assert.assertEquals(2, functions.size());
|
||||
|
||||
queryStr = "select db1.decimal(333, 4, 1);";
|
||||
ctx.getState().reset();
|
||||
@ -184,7 +154,7 @@ public class CreateFunctionTest {
|
||||
Env.getCurrentEnv().createFunction(createFunctionStmt);
|
||||
|
||||
functions = db.getFunctions();
|
||||
Assert.assertEquals(4, functions.size());
|
||||
Assert.assertEquals(3, functions.size());
|
||||
|
||||
queryStr = "select db1.varchar(333, 4);";
|
||||
ctx.getState().reset();
|
||||
@ -211,7 +181,7 @@ public class CreateFunctionTest {
|
||||
Env.getCurrentEnv().createFunction(createFunctionStmt);
|
||||
|
||||
functions = db.getFunctions();
|
||||
Assert.assertEquals(5, functions.size());
|
||||
Assert.assertEquals(4, functions.size());
|
||||
|
||||
queryStr = "select db1.char(333, 4);";
|
||||
ctx.getState().reset();
|
||||
|
||||
Reference in New Issue
Block a user