forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_javaudaf_mysum_float_double.groovy
90 lines (75 loc) · 3.53 KB
/
test_javaudaf_mysum_float_double.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import org.codehaus.groovy.runtime.IOGroovyMethods
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
suite("test_javaudaf_mysum_float_double") {
def tableName = "test_javaudaf_mysum_float_double"
def jarPath = """${context.file.parent}/jars/java-udf-case-jar-with-dependencies.jar"""
log.info("Jar path: ${jarPath}".toString())
try {
sql """ DROP TABLE IF EXISTS ${tableName} """
sql """
CREATE TABLE IF NOT EXISTS ${tableName} (
`user_id` INT NOT NULL COMMENT "用户id",
`float_col` float NOT NULL COMMENT "",
`double_col` double NOT NULL COMMENT "",
`string_col` STRING NOT NULL COMMENT ""
)
DISTRIBUTED BY HASH(user_id) PROPERTIES("replication_num" = "1");
"""
StringBuilder sb = new StringBuilder()
int i = 1
for (; i < 9; i ++) {
sb.append("""
(${i % 3}, '${i*111/10}','${i*111/100+i/1000}','poiuytre${i}abcdefg'),
""")
}
sb.append("""
(${i}, '${i*111/10}','${i*111/100+i/10}','poiuytre${i}abcdefg')
""")
sql """ INSERT INTO ${tableName} VALUES
${sb.toString()}
"""
qt_select_default """ SELECT * FROM ${tableName} t ORDER BY float_col; """
File path = new File(jarPath)
if (!path.exists()) {
throw new IllegalStateException("""${jarPath} doesn't exist! """)
}
sql """ CREATE AGGREGATE FUNCTION udaf_my_sum_double(double,double) RETURNS double PROPERTIES (
"file"="file://${jarPath}",
"symbol"="org.apache.doris.udf.MySumDouble",
"always_nullable"="false",
"type"="JAVA_UDF"
); """
qt_select1 """ SELECT udaf_my_sum_double(double_col,double_col) result FROM ${tableName}; """
qt_select2 """ select user_id, udaf_my_sum_double(double_col,double_col) from ${tableName} group by user_id order by user_id; """
sql """ CREATE AGGREGATE FUNCTION udaf_my_sum_float(float) RETURNS float PROPERTIES (
"file"="file://${jarPath}",
"symbol"="org.apache.doris.udf.MySumFloat",
"always_nullable"="false",
"type"="JAVA_UDF"
); """
qt_select3 """ SELECT udaf_my_sum_float(float_col) result FROM ${tableName}; """
qt_select4 """ select user_id, udaf_my_sum_float(float_col) from ${tableName} group by user_id order by user_id; """
} finally {
try_sql("DROP FUNCTION IF EXISTS udaf_my_sum_float(float);")
try_sql("DROP FUNCTION IF EXISTS udaf_my_sum_double(double,double);")
try_sql("DROP TABLE IF EXISTS ${tableName}")
}
}