Skip to content

Commit 39d521e

Browse files
committed
fix test
1 parent 2bbd937 commit 39d521e

7 files changed

Lines changed: 216 additions & 22 deletions

File tree

fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public void test() throws Exception {
120120
+ "'runtime_version'='3.10.2', 'volatility'='stable');";
121121
createFunction(pythonUdfSql, ctx);
122122
Assert.assertEquals(2, db.getFunctions().size());
123-
Function pythonFn = db.getFunctions().get(1);
123+
Function pythonFn = findFunction(db, "py_stable");
124124
Assert.assertEquals(FunctionVolatility.STABLE, pythonFn.getVolatility());
125125
Assert.assertTrue(FunctionToSqlConverter.toSql(pythonFn, false).contains("\"VOLATILITY\"=\"stable\""));
126126

127127
String defaultVolatileSql = "create function db1.py_default(int) returns int "
128128
+ "properties('type'='PYTHON_UDF', 'symbol'='evaluate', 'runtime_version'='3.10.2');";
129129
createFunction(defaultVolatileSql, ctx);
130-
Assert.assertEquals(FunctionVolatility.VOLATILE, db.getFunctions().get(2).getVolatility());
130+
Assert.assertEquals(FunctionVolatility.VOLATILE, findFunction(db, "py_default").getVolatility());
131131
}
132132

133133
@Test
@@ -218,4 +218,13 @@ private void createFunction(String sql, ConnectContext connectContext) throws Ex
218218
private boolean containsIgnoreCase(String str, String sub) {
219219
return str.toLowerCase().contains(sub.toLowerCase());
220220
}
221+
222+
private Function findFunction(Database db, String functionName) {
223+
for (Function function : db.getFunctions()) {
224+
if (functionName.equals(function.functionName())) {
225+
return function;
226+
}
227+
}
228+
throw new AssertionError("function not found: " + functionName);
229+
}
221230
}

regression-test/conf/regression-conf.groovy

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,21 @@ defaultDb = "regression_test"
2424
// init cmd like: select @@session.tx_read_only
2525
// at each time we connect.
2626
// add allowLoadLocalInfile so that the jdbc can execute mysql load data from client.
27-
jdbcUrl = "jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
28-
targetJdbcUrl = "jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
27+
jdbcUrl = "jdbc:mysql://127.0.0.1:9330/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
28+
targetJdbcUrl = "jdbc:mysql://127.0.0.1:9330/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
2929
jdbcUser = "root"
3030
jdbcPassword = ""
3131

32-
feSourceThriftAddress = "127.0.0.1:9020"
33-
feTargetThriftAddress = "127.0.0.1:9020"
32+
feSourceThriftAddress = "127.0.0.1:9220"
33+
feTargetThriftAddress = "127.0.0.1:9220"
3434
syncerAddress = "127.0.0.1:9190"
3535
feSyncerUser = "root"
3636
feSyncerPassword = ""
3737

38-
feHttpAddress = "127.0.0.1:8030"
38+
feHttpAddress = "127.0.0.1:8330"
3939
feHttpUser = "root"
4040
feHttpPassword = ""
4141

42-
// ccr, need BE enable_feature_binlog=true and FE enable_feature_binlog = true
43-
ccrDownstreamUrl = "jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true"
44-
ccrDownstreamUser = "root"
45-
ccrDownstreamPassword = ""
46-
ccrDownstreamFeThriftAddress = "127.0.0.1:9030"
47-
4842
// set DORIS_HOME by system properties
4943
// e.g. java -DDORIS_HOME=./
5044
suitePath = "${DORIS_HOME}/regression-test/suites"
@@ -96,7 +90,6 @@ excludeDirectories = "000_the_start_sentinel_do_not_touch," + // keep this line
9690
"segcompaction_p2," +
9791
"workload_manager_p1," +
9892
"cloud_p0/cache," +
99-
"load_p0/msk_load," +
10093
"zzz_the_end_sentinel_do_not_touch," +
10194
"dialect_compatible"// keep this line as the last line
10295

@@ -254,7 +247,7 @@ polaris_minio_port=20001
254247
// If the failure suite num exceeds this config
255248
// all following suite will be skipped to fast quit the run.
256249
// <=0 means no limit.
257-
max_failure_num=0
250+
max_failure_num=1
258251

259252
// used for exporting test
260253
s3ExportBucketName = ""
@@ -335,5 +328,4 @@ hudiMinioSecretKey="minio123"
335328

336329
icebergDlfRestCatalog="'type' = 'iceberg', 'warehouse' = 'new_dlf_iceberg_catalog', 'iceberg.catalog.type' = 'rest', 'iceberg.rest.uri' = 'http://cn-beijing-vpc.dlf.aliyuncs.com/iceberg', 'iceberg.rest.sigv4-enabled' = 'true', 'iceberg.rest.signing-name' = 'DlfNext', 'iceberg.rest.access-key-id' = 'ak', 'iceberg.rest.secret-access-key' = 'sk', 'iceberg.rest.signing-region' = 'cn-beijing', 'iceberg.rest.vended-credentials-enabled' = 'true', 'io-impl' = 'org.apache.iceberg.rest.DlfFileIO', 'fs.oss.support' = 'true'"
337330

338-
// For python UDF test, set the runtime version of python, default: 3.8.10
339-
// pythonUdfRuntimeVersion = ""
331+
pythonUdfRuntimeVersion = "3.12.11"

regression-test/suites/javaudf_p0/test_javaudf_float.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ suite("test_javaudf_float") {
5656
sql """ CREATE FUNCTION java_udf_float_test(FLOAT,FLOAT) RETURNS FLOAT PROPERTIES (
5757
"file"="file://${jarPath}",
5858
"symbol"="org.apache.doris.udf.FloatTest",
59-
"type"="JAVA_UDF"
59+
"type"="JAVA_UDF",
60+
"volatility"="immutable"
6061
); """
6162

6263
qt_select """ SELECT java_udf_float_test(cast(2.83645 as float),cast(111.1111111 as float)) as result; """

regression-test/suites/mtmv_p0/test_expand_star_mtmv.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ suite("test_expand_star_mtmv","mtmv") {
6262
sql """ CREATE FUNCTION ${functionName}(date, date) RETURNS boolean PROPERTIES (
6363
"file"="file://${jarPath}",
6464
"symbol"="org.apache.doris.udf.DateTest1",
65-
"type"="JAVA_UDF"
65+
"type"="JAVA_UDF",
66+
"volatility"="immutable"
6667
); """
6768

6869
sql """

regression-test/suites/pythonudf_p0/test_pythonudf_aggregate.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ suite("test_pythonudf_aggregate") {
2828
PROPERTIES (
2929
"type" = "PYTHON_UDF",
3030
"symbol" = "evaluate",
31-
"runtime_version" = "${runtime_version}"
31+
"runtime_version" = "${runtime_version}",
32+
"volatility" = "immutable"
3233
)
3334
AS \$\$
3435
def evaluate(score):
@@ -120,7 +121,8 @@ def evaluate(score):
120121
PROPERTIES (
121122
"type" = "PYTHON_UDF",
122123
"symbol" = "evaluate",
123-
"runtime_version" = "${runtime_version}"
124+
"runtime_version" = "${runtime_version}",
125+
"volatility" = "immutable"
124126
)
125127
AS \$\$
126128
def evaluate(age):

regression-test/suites/pythonudf_p0/test_pythonudf_float.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ suite("test_pythonudf_float") {
5353
"symbol"="float_test.evaluate",
5454
"type"="PYTHON_UDF",
5555
"runtime_version" = "${runtime_version}",
56-
"always_nullable" = "true"
56+
"always_nullable" = "true",
57+
"volatility" = "immutable"
5758
); """
5859

5960
qt_select """ SELECT python_udf_float_test(cast(2.83645 as float),cast(111.1111111 as float)) as result; """
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import org.junit.Assert
19+
20+
suite("test_pythonudf_volatility") {
21+
def runtimeVersion = getPythonUdfRuntimeVersion()
22+
def functions = [
23+
"py_vol_immutable",
24+
"py_vol_stable",
25+
"py_vol_volatile",
26+
"py_vol_default"
27+
]
28+
def materializedViews = [
29+
"py_vol_immutable_mv",
30+
"py_vol_stable_mv",
31+
"py_vol_volatile_mv",
32+
"py_vol_default_mv"
33+
]
34+
35+
materializedViews.each { mv ->
36+
sql """ DROP MATERIALIZED VIEW IF EXISTS ${mv}; """
37+
}
38+
sql """ DROP TABLE IF EXISTS py_vol_tbl; """
39+
functions.each { fn ->
40+
sql """ DROP FUNCTION IF EXISTS ${fn}(INT); """
41+
}
42+
43+
sql """
44+
CREATE TABLE py_vol_tbl (
45+
k INT
46+
)
47+
DISTRIBUTED BY HASH(k) BUCKETS 1
48+
PROPERTIES("replication_num" = "1");
49+
"""
50+
sql """ INSERT INTO py_vol_tbl VALUES (1), (2); """
51+
52+
sql """
53+
CREATE FUNCTION py_vol_immutable(INT)
54+
RETURNS INT
55+
PROPERTIES (
56+
"type" = "PYTHON_UDF",
57+
"symbol" = "evaluate",
58+
"runtime_version" = "${runtimeVersion}",
59+
"volatility" = "immutable"
60+
)
61+
AS \$\$
62+
def evaluate(x):
63+
if x is None:
64+
return None
65+
return x + 1
66+
\$\$;
67+
"""
68+
69+
sql """
70+
CREATE FUNCTION py_vol_stable(INT)
71+
RETURNS INT
72+
PROPERTIES (
73+
"type" = "PYTHON_UDF",
74+
"symbol" = "evaluate",
75+
"runtime_version" = "${runtimeVersion}",
76+
"volatility" = "stable"
77+
)
78+
AS \$\$
79+
def evaluate(x):
80+
if x is None:
81+
return None
82+
return x + 2
83+
\$\$;
84+
"""
85+
86+
sql """
87+
CREATE FUNCTION py_vol_volatile(INT)
88+
RETURNS INT
89+
PROPERTIES (
90+
"type" = "PYTHON_UDF",
91+
"symbol" = "evaluate",
92+
"runtime_version" = "${runtimeVersion}",
93+
"volatility" = "volatile"
94+
)
95+
AS \$\$
96+
def evaluate(x):
97+
if x is None:
98+
return None
99+
return x + 3
100+
\$\$;
101+
"""
102+
103+
sql """
104+
CREATE FUNCTION py_vol_default(INT)
105+
RETURNS INT
106+
PROPERTIES (
107+
"type" = "PYTHON_UDF",
108+
"symbol" = "evaluate",
109+
"runtime_version" = "${runtimeVersion}"
110+
)
111+
AS \$\$
112+
def evaluate(x):
113+
if x is None:
114+
return None
115+
return x + 4
116+
\$\$;
117+
"""
118+
119+
def result = sql """
120+
SELECT
121+
py_vol_immutable(1),
122+
py_vol_stable(1),
123+
py_vol_volatile(1),
124+
py_vol_default(1);
125+
"""
126+
Assert.assertEquals([[2, 3, 4, 5]], result)
127+
128+
explain {
129+
sql "logical plan SELECT * FROM py_vol_tbl WHERE py_vol_immutable(k) IN (1, k + 1)"
130+
contains "OR["
131+
notContains " IN "
132+
}
133+
134+
explain {
135+
sql "logical plan SELECT * FROM py_vol_tbl WHERE py_vol_stable(k) IN (1, k + 2)"
136+
contains "OR["
137+
notContains " IN "
138+
}
139+
140+
explain {
141+
sql "logical plan SELECT * FROM py_vol_tbl WHERE py_vol_volatile(k) IN (1, k + 3)"
142+
contains " IN "
143+
notContains "OR["
144+
}
145+
146+
explain {
147+
sql "logical plan SELECT * FROM py_vol_tbl WHERE py_vol_default(k) IN (1, k + 4)"
148+
contains " IN "
149+
notContains "OR["
150+
}
151+
152+
result = sql """
153+
SELECT py_vol_volatile(k), COUNT(*)
154+
FROM py_vol_tbl
155+
GROUP BY py_vol_volatile(k)
156+
ORDER BY 1;
157+
"""
158+
Assert.assertEquals("[[4, 1], [5, 1]]", result.toString())
159+
160+
createMV("""
161+
CREATE MATERIALIZED VIEW py_vol_immutable_mv
162+
AS SELECT py_vol_immutable(k) AS v FROM py_vol_tbl;
163+
""")
164+
165+
test {
166+
sql """
167+
CREATE MATERIALIZED VIEW py_vol_stable_mv
168+
AS SELECT py_vol_stable(k) AS v_stable FROM py_vol_tbl;
169+
"""
170+
exception "can not contain nonDeterministic expression or unnest"
171+
}
172+
173+
test {
174+
sql """
175+
CREATE MATERIALIZED VIEW py_vol_volatile_mv
176+
AS SELECT py_vol_volatile(k) AS v_volatile FROM py_vol_tbl;
177+
"""
178+
exception "can not contain nonDeterministic expression or unnest"
179+
}
180+
181+
test {
182+
sql """
183+
CREATE MATERIALIZED VIEW py_vol_default_mv
184+
AS SELECT py_vol_default(k) AS v_default FROM py_vol_tbl;
185+
"""
186+
exception "can not contain nonDeterministic expression or unnest"
187+
}
188+
}

0 commit comments

Comments
 (0)