Skip to content

Commit 697ec65

Browse files
authored
[BugFix] Python inline UDF creation failing when file='inline' is omitted (#72359)
1 parent 782d218 commit 697ec65

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

fe/fe-core/src/main/java/com/starrocks/sql/analyzer/CreateFunctionAnalyzer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,11 @@ private void analyzePython(CreateFunctionStmt stmt, ConnectContext context) {
781781
}
782782
String symbol = properties.get(CreateFunctionStmt.SYMBOL_KEY);
783783
String inputType = properties.getOrDefault(CreateFunctionStmt.INPUT_TYPE, "scalar");
784-
String objectFile = stmt.getProperties().get(CreateFunctionStmt.FILE_KEY);
784+
String objectFile = properties.getOrDefault(CreateFunctionStmt.FILE_KEY, "inline");
785785

786786
if (isInline && !StringUtils.equalsIgnoreCase(objectFile, "inline")) {
787787
ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, "inline function file should be 'inline'");
788788
}
789-
if (isInline) {
790-
objectFile = "inline";
791-
}
792789

793790
if (!inputType.equalsIgnoreCase("arrow") && !inputType.equalsIgnoreCase("scalar")) {
794791
ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, "unknown input type:" + inputType);

fe/fe-core/src/test/java/com/starrocks/sql/analyzer/CreateFunctionStmtAnalyzerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ private CreateFunctionStmt createPyStmt(String symbol, String type, String targe
9797
createFunctionSql, 32).get(0);
9898
}
9999

100+
private CreateFunctionStmt createPyInlineStmtNoFile(String symbol) {
101+
Config.enable_udf = true;
102+
String createFunctionSql = String.format("CREATE FUNCTION ABC.MY_UDF_JSON_GET_NOFILE(string, string) \n"
103+
+ "RETURNS string \n"
104+
+ "type = 'Python'\n"
105+
+ "symbol = '%s'\n"
106+
+ "AS $$\n"
107+
+ "def a(b):\n"
108+
+ " return b\n"
109+
+ "$$;", symbol);
110+
return (CreateFunctionStmt) com.starrocks.sql.parser.SqlParser.parse(
111+
createFunctionSql, 32).get(0);
112+
}
113+
100114
@Test
101115
public void testJUDF() {
102116
assertThrows(Throwable.class, () -> {
@@ -1116,6 +1130,14 @@ public void testJScalarUDFArrayOfStruct() {
11161130
});
11171131
}
11181132

1133+
@Test
1134+
public void testPyInlineUDFWithoutFileProperty() {
1135+
CreateFunctionStmt stmt = createPyInlineStmtNoFile("a");
1136+
Assertions.assertNotNull(stmt.getContent(), "Inline body must be parsed into content");
1137+
new CreateFunctionAnalyzer().analyze(stmt, connectContext);
1138+
Assertions.assertEquals("inline", stmt.getFunction().getLocation().toString(),
1139+
"Analyzer must auto-set location to 'inline' when file property is omitted");
1140+
}
11191141
public static class DateEval {
11201142
public java.time.LocalDateTime evaluate(java.time.LocalDate d, java.time.LocalDateTime ts) {
11211143
return ts;

0 commit comments

Comments
 (0)