1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
1
19
package com .hw .lineage .flink .aggregatefunction ;
2
20
3
21
import com .hw .lineage .flink .basic .AbstractBasicTest ;
22
+
4
23
import org .junit .Before ;
5
24
import org .junit .Test ;
6
25
@@ -15,9 +34,14 @@ public void createTable() {
15
34
16
35
createTableOfOdsMysqlUsersDetail ();
17
36
18
- context .execute ("create function test_aggregate as 'com.hw.lineage.flink.aggregatefunction.TestAggregateFunction'" );
37
+ createPrintTable ();
38
+
39
+ createFunction ();
19
40
}
20
41
42
+ /**
43
+ * #125 issue
44
+ */
21
45
@ Test
22
46
public void testAggregateFunction () {
23
47
String sql = "INSERT INTO dwd_hudi_users " +
@@ -34,7 +58,8 @@ public void testAggregateFunction() {
34
58
String [][] expectedArray = {
35
59
{"ods_mysql_users" , "id" , "dwd_hudi_users" , "id" },
36
60
{"ods_mysql_users" , "name" , "dwd_hudi_users" , "name" },
37
- {"ods_mysql_users" , "name" , "dwd_hudi_users" , "company_name" , "test_aggregate(CONCAT_WS('_', name, 'test'), name, _UTF-16LE'test')" },
61
+ {"ods_mysql_users" , "name" , "dwd_hudi_users" , "company_name" ,
62
+ "test_aggregate(CONCAT_WS('_', name, 'test'), name, 'test')" },
38
63
{"ods_mysql_users" , "birthday" , "dwd_hudi_users" , "birthday" },
39
64
{"ods_mysql_users" , "ts" , "dwd_hudi_users" , "ts" },
40
65
{"ods_mysql_users" , "birthday" , "dwd_hudi_users" , "partition" , "DATE_FORMAT(birthday, 'yyyyMMdd')" }
@@ -43,6 +68,28 @@ public void testAggregateFunction() {
43
68
analyzeLineage (sql , expectedArray );
44
69
}
45
70
71
+ /**
72
+ * #128 issue
73
+ */
74
+ @ Test
75
+ public void testMultiTierUdf () {
76
+ String sql = "INSERT INTO print_table " +
77
+ "SELECT " +
78
+ " round( COUNT(*) / COUNT( DISTINCT name ) , 2 )" +
79
+ "FROM" +
80
+ " ods_mysql_users group by ts " ;
81
+
82
+ String [][] expectedArray = {
83
+ {"ods_mysql_users" , "name" , "print_table" , "num" , "ROUND(/(COUNT(DISTINCT name), $2), 2)" },
84
+
85
+ };
86
+
87
+ analyzeLineage (sql , expectedArray );
88
+ }
89
+
90
+ /**
91
+ * #126 issue
92
+ */
46
93
@ Test
47
94
public void testAggregateFunctionInputArgument () {
48
95
String sql = "INSERT INTO dwd_hudi_users " +
@@ -59,17 +106,25 @@ public void testAggregateFunctionInputArgument() {
59
106
String [][] expectedArray = {
60
107
{"ods_mysql_user_detail" , "id" , "dwd_hudi_users" , "id" },
61
108
{"ods_mysql_user_detail" , "name" , "dwd_hudi_users" , "name" },
62
- {"ods_mysql_user_detail" , "name" , "dwd_hudi_users" , "company_name" , "test_aggregate(CONCAT_WS('_', name, email), address, _UTF-16LE'test')" },
63
- {"ods_mysql_user_detail" , "email" , "dwd_hudi_users" , "company_name" , "test_aggregate(CONCAT_WS('_', name, email), address, _UTF-16LE'test')" },
64
- {"ods_mysql_user_detail" , "address" , "dwd_hudi_users" , "company_name" , "test_aggregate(CONCAT_WS('_', name, email), address, _UTF-16LE'test')" },
109
+ {"ods_mysql_user_detail" , "name" , "dwd_hudi_users" , "company_name" ,
110
+ "test_aggregate(CONCAT_WS('_', name, email), address, 'test')" },
111
+ {"ods_mysql_user_detail" , "email" , "dwd_hudi_users" , "company_name" ,
112
+ "test_aggregate(CONCAT_WS('_', name, email), address, 'test')" },
113
+ {"ods_mysql_user_detail" , "address" , "dwd_hudi_users" , "company_name" ,
114
+ "test_aggregate(CONCAT_WS('_', name, email), address, 'test')" },
65
115
{"ods_mysql_user_detail" , "birthday" , "dwd_hudi_users" , "birthday" },
66
116
{"ods_mysql_user_detail" , "ts" , "dwd_hudi_users" , "ts" },
67
- {"ods_mysql_user_detail" , "birthday" , "dwd_hudi_users" , "partition" , "DATE_FORMAT(birthday, 'yyyyMMdd')" }
117
+ {"ods_mysql_user_detail" , "birthday" , "dwd_hudi_users" , "partition" ,
118
+ "DATE_FORMAT(birthday, 'yyyyMMdd')" }
68
119
};
69
120
70
121
analyzeLineage (sql , expectedArray );
71
122
}
72
123
124
+ private void createPrintTable () {
125
+ context .execute ("drop table if exists print_table" );
126
+ context .execute ("create table print_table (num double) with ('connector'='print')" );
127
+ }
73
128
protected void createTableOfOdsMysqlUsersDetail () {
74
129
context .execute ("DROP TABLE IF EXISTS ods_mysql_user_detail " );
75
130
@@ -92,4 +147,11 @@ protected void createTableOfOdsMysqlUsersDetail() {
92
147
" 'table-name' = 'users' " +
93
148
")" );
94
149
}
150
+
151
+ private void createFunction () {
152
+ context .execute ("drop function if exists test_aggregate" );
153
+ context .execute (
154
+ "create function test_aggregate as 'com.hw.lineage.flink.aggregatefunction.TestAggregateFunction'" );
155
+ }
156
+
95
157
}
0 commit comments