Skip to content

Commit c8f0380

Browse files
mergify[bot]wyb
andauthored
[BugFix] Surface isolation property in SHOW FUNCTIONS output (backport #75255) (backport #75276) (#75278)
Signed-off-by: wyb <wybb86@gmail.com> Co-authored-by: wyb <wybb86@gmail.com>
1 parent fcfdf39 commit c8f0380

5 files changed

Lines changed: 78 additions & 1 deletion

File tree

fe/fe-core/src/main/java/com/starrocks/catalog/AggregateFunction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ public String getProperties() {
470470
properties.put(CreateFunctionStmt.MD5_CHECKSUM, checksum);
471471
properties.put(CreateFunctionStmt.SYMBOL_KEY, symbolName == null ? "" : symbolName);
472472
properties.put(CreateFunctionStmt.TYPE_KEY, getBinaryType().name());
473+
// isolationType defaults to true (isolated); surface it so users can tell whether the
474+
// function was created with isolation = "shared".
475+
properties.put(CreateFunctionStmt.ISOLATION_KEY,
476+
isolationType ? CreateFunctionStmt.ISOLATION_ISOLATED : CreateFunctionStmt.ISOLATION_SHARED);
473477
return new Gson().toJson(properties);
474478
}
475479

fe/fe-core/src/main/java/com/starrocks/catalog/ScalarFunction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ public String getProperties() {
298298
properties.put(CreateFunctionStmt.MD5_CHECKSUM, checksum);
299299
properties.put(CreateFunctionStmt.SYMBOL_KEY, getSymbolName());
300300
properties.put(CreateFunctionStmt.TYPE_KEY, getBinaryType().name());
301+
// isolationType defaults to true (isolated); surface it so users can tell whether the
302+
// function was created with isolation = "shared".
303+
properties.put(CreateFunctionStmt.ISOLATION_KEY,
304+
isolationType ? CreateFunctionStmt.ISOLATION_ISOLATED : CreateFunctionStmt.ISOLATION_SHARED);
301305
return new Gson().toJson(properties);
302306
}
303307

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ private void analyzePython(CreateFunctionStmt stmt) {
606606
objectFile(objectFile).
607607
inputType(inputType).
608608
symbolName(symbol).
609-
isolation(!"shared".equalsIgnoreCase(isolation)).
609+
isolation(!CreateFunctionStmt.ISOLATION_SHARED.equalsIgnoreCase(isolation)).
610610
content(content);
611611
ScalarFunction function = scalarFunctionBuilder.build();
612612
function.setChecksum(checksum);

fe/fe-core/src/main/java/com/starrocks/sql/ast/CreateFunctionStmt.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class CreateFunctionStmt extends DdlStmt {
3333
public static final String MD5_CHECKSUM = "md5";
3434
public static final String TYPE_KEY = "type";
3535
public static final String ISOLATION_KEY = "isolation";
36+
public static final String ISOLATION_SHARED = "shared";
37+
public static final String ISOLATION_ISOLATED = "isolated";
3638
public static final String TYPE_STARROCKS_JAR = "StarrocksJar";
3739
public static final String TYPE_STARROCKS_PYTHON = "Python";
3840
public static final String EVAL_METHOD_NAME = "evaluate";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2021-present StarRocks, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.starrocks.analysis;
16+
17+
import com.google.common.collect.Lists;
18+
import com.starrocks.catalog.AggregateFunction;
19+
import com.starrocks.catalog.ScalarFunction;
20+
import com.starrocks.catalog.Type;
21+
import com.starrocks.thrift.TFunctionBinaryType;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.Test;
24+
25+
// Regression coverage for the Properties shown by SHOW [FULL] FUNCTIONS (Function#getProperties)
26+
// exposing the "isolation" entry so users can tell whether a UDF/UDAF was created with
27+
// isolation = "shared". isolationType == false means shared; true (default) means isolated.
28+
public class ShowFunctionsIsolationTest {
29+
30+
private static ScalarFunction scalarUdf(boolean isolationType) {
31+
Type[] args = new Type[] {Type.INT};
32+
return ScalarFunction.createUdf(new FunctionName("db", "my_udf"), args, Type.INT,
33+
false, TFunctionBinaryType.SRJAR, "objectFile", "symbol", "", "", isolationType);
34+
}
35+
36+
private static AggregateFunction aggregateUdf(boolean isolationType) {
37+
AggregateFunction fn = new AggregateFunction(new FunctionName("db", "my_agg"),
38+
Lists.newArrayList(Type.INT), Type.INT, Type.INT, false);
39+
fn.setBinaryType(TFunctionBinaryType.SRJAR);
40+
fn.setIsolationType(isolationType);
41+
return fn;
42+
}
43+
44+
@Test
45+
public void testSharedScalarFunctionShowsIsolation() {
46+
String props = scalarUdf(false).getProperties();
47+
Assertions.assertTrue(props.contains("\"isolation\":\"shared\""), props);
48+
}
49+
50+
@Test
51+
public void testIsolatedScalarFunctionShowsIsolation() {
52+
String props = scalarUdf(true).getProperties();
53+
Assertions.assertTrue(props.contains("\"isolation\":\"isolated\""), props);
54+
}
55+
56+
@Test
57+
public void testSharedAggregateFunctionShowsIsolation() {
58+
String props = aggregateUdf(false).getProperties();
59+
Assertions.assertTrue(props.contains("\"isolation\":\"shared\""), props);
60+
}
61+
62+
@Test
63+
public void testIsolatedAggregateFunctionShowsIsolation() {
64+
String props = aggregateUdf(true).getProperties();
65+
Assertions.assertTrue(props.contains("\"isolation\":\"isolated\""), props);
66+
}
67+
}

0 commit comments

Comments
 (0)