Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,11 @@ private void analyzePython(CreateFunctionStmt stmt, ConnectContext context) {
}
String symbol = properties.get(CreateFunctionStmt.SYMBOL_KEY);
String inputType = properties.getOrDefault(CreateFunctionStmt.INPUT_TYPE, "scalar");
String objectFile = stmt.getProperties().get(CreateFunctionStmt.FILE_KEY);
String objectFile = properties.getOrDefault(CreateFunctionStmt.FILE_KEY, "inline");

if (isInline && !StringUtils.equalsIgnoreCase(objectFile, "inline")) {
ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, "inline function file should be 'inline'");
Comment thread
stdpain marked this conversation as resolved.
}
if (isInline) {
objectFile = "inline";
}

if (!inputType.equalsIgnoreCase("arrow") && !inputType.equalsIgnoreCase("scalar")) {
ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, "unknown input type:" + inputType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ private CreateFunctionStmt createPyStmt(String symbol, String type, String targe
createFunctionSql, 32).get(0);
}

private CreateFunctionStmt createPyInlineStmtNoFile(String symbol) {
Config.enable_udf = true;
String createFunctionSql = String.format("CREATE FUNCTION ABC.MY_UDF_JSON_GET_NOFILE(string, string) \n"
+ "RETURNS string \n"
+ "type = 'Python'\n"
+ "symbol = '%s'\n"
+ "AS $$\n"
+ "def a(b):\n"
+ " return b\n"
+ "$$;", symbol);
return (CreateFunctionStmt) com.starrocks.sql.parser.SqlParser.parse(
createFunctionSql, 32).get(0);
}

@Test
public void testJUDF() {
assertThrows(Throwable.class, () -> {
Expand Down Expand Up @@ -1116,6 +1130,14 @@ public void testJScalarUDFArrayOfStruct() {
});
}

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