Skip to content

Commit d688810

Browse files
committed
[improve](udf) let create udf function error msg more clear (apache#54202)
Problem Summary: sometimes user create function maybe have mistake of parameter so need more clear error msg to know what happend. ``` ERROR 1105 (HY000): errCode = 2, detailMessage = UDF class 'org.apache.doris.udf.AddOne' method 'evaluate' return[java.lang.Integer] type is not supported! before and after of error msg ERROR 1105 (HY000): errCode = 2, detailMessage = UDF class 'org.apache.doris.udf.AddOne' of method 'evaluate' return is [java.lang.Integer] type, but create function command type is STRING ```
1 parent 7a194ef commit d688810

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

fe/fe-core/src/main/java/org/apache/doris/analysis/CreateFunctionStmt.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,10 @@ private void checkUdfClass(String clazz, ClassLoader cl) throws ClassNotFoundExc
657657
m -> m.getParameters().length == argsDef.getArgTypes().length).collect(Collectors.toList());
658658
if (evalArgLengthMatchList.size() == 0) {
659659
throw new AnalysisException(
660-
String.format("The number of parameters for method '%s' in class '%s' should be %d",
661-
EVAL_METHOD_KEY, udfClass.getCanonicalName(), argsDef.getArgTypes().length));
660+
String.format(
661+
"The arguments number udf provided and create function command is not equal,"
662+
+ " the parameters of '%s' method in class '%s' maybe should %d.",
663+
EVAL_METHOD_KEY, udfClass.getCanonicalName(), argsDef.getArgTypes().length));
662664
} else if (evalArgLengthMatchList.size() == 1) {
663665
Method method = evalArgLengthMatchList.get(0);
664666
checkUdfType(udfClass, method, returnType.getType(), method.getReturnType(), "return");
@@ -708,19 +710,21 @@ private void checkUdfType(Class clazz, Method method, Type expType, Class pType,
708710
javaTypes = Type.PrimitiveTypeToJavaClassType.get(structType.getPrimitiveType());
709711
} else {
710712
throw new AnalysisException(
711-
String.format("Method '%s' in class '%s' does not support type '%s'",
713+
String.format("Method '%s' in class '%s' does not support type '%s'.",
712714
method.getName(), clazz.getCanonicalName(), expType));
713715
}
714716

715717
if (javaTypes == null) {
716718
throw new AnalysisException(
717-
String.format("Method '%s' in class '%s' does not support type '%s'",
718-
method.getName(), clazz.getCanonicalName(), expType.toString()));
719+
String.format("Method '%s' in class '%s' does not support type '%s'.",
720+
method.getName(), clazz.getCanonicalName(), expType.getPrimitiveType().toString()));
719721
}
720722
if (!javaTypes.contains(pType)) {
721723
throw new AnalysisException(
722-
String.format("UDF class '%s' method '%s' %s[%s] type is not supported!",
723-
clazz.getCanonicalName(), method.getName(), pname, pType.getCanonicalName()));
724+
String.format(
725+
"UDF class '%s' of method '%s' %s is [%s] type, but create function command type is %s.",
726+
clazz.getCanonicalName(), method.getName(), pname, pType.getCanonicalName(),
727+
expType.getPrimitiveType().toString()));
724728
}
725729
}
726730

regression-test/suites/javaudf_p0/test_javaudf_int.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ suite("test_javaudf_int") {
147147
exception "but the return type is not nullable"
148148
}
149149

150+
test {
151+
sql """ CREATE FUNCTION java_udf_largeint_test_not_nullable(largeint) RETURNS string PROPERTIES (
152+
"file"="file://${jarPath}",
153+
"symbol"="org.apache.doris.udf.LargeintTest",
154+
"always_nullable"="false",
155+
"type"="JAVA_UDF"
156+
); """
157+
exception "but create function command type is STRING"
158+
}
159+
150160
} finally {
151161
try_sql("DROP GLOBAL FUNCTION IF EXISTS java_udf_int_test_global(int);")
152162
try_sql("DROP FUNCTION IF EXISTS java_udf_tinyint_test(tinyint);")

0 commit comments

Comments
 (0)