This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 0b96ec9551e branch-4.2: [fix](udf) Check UDF enablement before
fetching file checksum (#71259)
0b96ec9551e is described below
commit 0b96ec9551eca242e2385a15e19bd53ecb5460bb
Author: linrrarity <[email protected]>
AuthorDate: Sat Dec 5 22:22:36 2026 +0800
branch-4.2: [fix](udf) Check UDF enablement before fetching file checksum
(#71259)
pickļ¼ https://github.com/apache/doris/pull/71206
---
.../plans/commands/CreateFunctionCommand.java | 32 +++++++--------
.../apache/doris/catalog/CreateFunctionTest.java | 47 ++++++++++++++++++++++
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateFunctionCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateFunctionCommand.java
index 7a1c291ae05..f24a25fc3c9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateFunctionCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateFunctionCommand.java
@@ -326,22 +326,6 @@ public class CreateFunctionCommand extends Command
implements ForwardWithSync {
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));
- originalUserFile = userFile; // Keep original jar name for BE
- // Inline Python code is authoritative. Keep FILE in metadata for
replay, but do not load or validate it here.
- if (Strings.isNullOrEmpty(functionCode) &&
!Strings.isNullOrEmpty(userFile)
- && binaryType != TFunctionBinaryType.RPC) {
- userFile = getRealUrl(userFile);
- try {
- computeObjectChecksum();
- } catch (IOException | NoSuchAlgorithmException e) {
- throw new AnalysisException("cannot to compute object's
checksum. err: " + e.getMessage());
- }
- String md5sum = properties.get(MD5_CHECKSUM);
- if (md5sum != null && !md5sum.equalsIgnoreCase(checksum)) {
- throw new AnalysisException("library's checksum is not equal
with input, checksum=" + checksum);
- }
- }
if (binaryType == TFunctionBinaryType.JAVA_UDF) {
FunctionUtil.checkEnableJavaUdf();
checkUdfSupportedTypes();
@@ -381,6 +365,22 @@ public class CreateFunctionCommand extends Command
implements ForwardWithSync {
} else if (properties.containsKey(VOLATILITY)) {
throw new AnalysisException("volatility property only supports
JAVA_UDF and PYTHON_UDF");
}
+ userFile = properties.getOrDefault(FILE_KEY,
properties.get(OBJECT_FILE_KEY));
+ originalUserFile = userFile; // Keep original jar name for BE
+ // Inline Python code is authoritative. Keep FILE in metadata for
replay, but do not load or validate it here.
+ if (Strings.isNullOrEmpty(functionCode) &&
!Strings.isNullOrEmpty(userFile)
+ && (binaryType == TFunctionBinaryType.JAVA_UDF || binaryType
== TFunctionBinaryType.PYTHON_UDF)) {
+ userFile = getRealUrl(userFile);
+ try {
+ computeObjectChecksum();
+ } catch (IOException | NoSuchAlgorithmException e) {
+ throw new AnalysisException("cannot to compute object's
checksum. err: " + e.getMessage());
+ }
+ String md5sum = properties.get(MD5_CHECKSUM);
+ if (md5sum != null && !md5sum.equalsIgnoreCase(checksum)) {
+ throw new AnalysisException("library's checksum is not equal
with input, checksum=" + checksum);
+ }
+ }
}
private FunctionVolatility defaultVolatility() {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
index 91cfc9a8fe4..b561231878d 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
@@ -21,6 +21,7 @@ import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.FunctionCallExpr;
import org.apache.doris.analysis.FunctionName;
import org.apache.doris.analysis.StringLiteral;
+import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.jmockit.Deencapsulation;
import org.apache.doris.common.util.URI;
@@ -44,6 +45,7 @@ import org.apache.doris.utframe.DorisAssert;
import org.apache.doris.utframe.UtFrameUtils;
import com.google.common.collect.ImmutableList;
+import com.sun.net.httpserver.HttpServer;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
@@ -54,8 +56,10 @@ import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import java.io.File;
+import java.net.InetSocketAddress;
import java.util.List;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
/*
@@ -283,6 +287,49 @@ public class CreateFunctionTest {
+ " right(CAST(CAST(k1 AS BIGINT) AS VARCHAR(65533)),
4))"));
}
+ @Test
+ public void testDisabledUdfDoesNotFetchFile() throws Exception {
+ ConnectContext ctx = UtFrameUtils.createDefaultCtx();
+ createDatabase(ctx, "create database disabled_udf_db;");
+
+ AtomicInteger requestCount = new AtomicInteger(0);
+ HttpServer server = HttpServer.create(new
InetSocketAddress("127.0.0.1", 0), 0);
+ server.createContext("/", exchange -> {
+ requestCount.incrementAndGet();
+ exchange.sendResponseHeaders(404, -1);
+ exchange.close();
+ });
+ server.start();
+
+ boolean oldRunningUnitTest = FeConstants.runningUnitTest;
+ boolean oldEnableJavaUdf = Config.enable_java_udf;
+ boolean oldEnablePythonUdf = Config.enable_python_udf;
+ try {
+ FeConstants.runningUnitTest = false;
+ String url = "http://127.0.0.1:" + server.getAddress().getPort() +
"/test.jar";
+
+ Config.enable_java_udf = false;
+ assertCreateFunctionAnalysisException(ctx,
+ "create function disabled_udf_db.java_disabled(int)
returns int properties("
+ + "'symbol'='evaluate', 'file'='" + url + "');",
+ "java_udf has been disabled.");
+ Assertions.assertEquals(0, requestCount.get());
+
+ Config.enable_python_udf = false;
+ assertCreateFunctionAnalysisException(ctx,
+ "create function disabled_udf_db.python_disabled(int)
returns int properties("
+ + "'type'='PYTHON_UDF', 'symbol'='evaluate',
'runtime_version'='3.10.2', "
+ + "'file'='" + url + "');",
+ "python_udf has been disabled.");
+ Assertions.assertEquals(0, requestCount.get());
+ } finally {
+ FeConstants.runningUnitTest = oldRunningUnitTest;
+ Config.enable_java_udf = oldEnableJavaUdf;
+ Config.enable_python_udf = oldEnablePythonUdf;
+ server.stop(0);
+ }
+ }
+
private void testFunctionQuery(ConnectContext ctx, String queryStr,
Boolean isStringLiteral) throws Exception {
ctx.getState().reset();
StmtExecutor stmtExecutor = new StmtExecutor(ctx, queryStr);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]