18
18
package org .apache .seatunnel .connectors .seatunnel .jdbc .utils ;
19
19
20
20
import org .apache .seatunnel .api .table .catalog .CatalogTable ;
21
+ import org .apache .seatunnel .api .table .catalog .Column ;
21
22
import org .apache .seatunnel .api .table .catalog .ConstraintKey ;
22
23
import org .apache .seatunnel .api .table .catalog .PhysicalColumn ;
23
24
import org .apache .seatunnel .api .table .catalog .PrimaryKey ;
30
31
31
32
import java .util .Arrays ;
32
33
import java .util .Collections ;
34
+ import java .util .List ;
35
+ import java .util .Map ;
33
36
import java .util .stream .Collectors ;
34
37
35
38
public class JdbcCatalogUtilsTest {
@@ -103,9 +106,9 @@ public void testColumnEqualsMerge() {
103
106
TableSchema .builder ()
104
107
.column (
105
108
PhysicalColumn .of (
106
- "f1 " ,
107
- BasicType .LONG_TYPE ,
108
- null ,
109
+ "f2 " ,
110
+ BasicType .STRING_TYPE ,
111
+ 10 ,
109
112
true ,
110
113
null ,
111
114
null ,
@@ -117,10 +120,10 @@ public void testColumnEqualsMerge() {
117
120
null ))
118
121
.column (
119
122
PhysicalColumn .of (
120
- "f2 " ,
123
+ "f3 " ,
121
124
BasicType .STRING_TYPE ,
122
- 10 ,
123
- true ,
125
+ 20 ,
126
+ false ,
124
127
null ,
125
128
null ,
126
129
null ,
@@ -131,10 +134,10 @@ public void testColumnEqualsMerge() {
131
134
null ))
132
135
.column (
133
136
PhysicalColumn .of (
134
- "f3 " ,
135
- BasicType .STRING_TYPE ,
136
- 20 ,
137
- false ,
137
+ "f1 " ,
138
+ BasicType .LONG_TYPE ,
139
+ null ,
140
+ true ,
138
141
null ,
139
142
null ,
140
143
null ,
@@ -149,7 +152,26 @@ public void testColumnEqualsMerge() {
149
152
null );
150
153
151
154
CatalogTable mergeTable = JdbcCatalogUtils .mergeCatalogTable (DEFAULT_TABLE , tableOfQuery );
152
- Assertions .assertEquals (DEFAULT_TABLE , mergeTable );
155
+ Assertions .assertEquals (DEFAULT_TABLE .getTableId (), mergeTable .getTableId ());
156
+ Assertions .assertEquals (DEFAULT_TABLE .getOptions (), mergeTable .getOptions ());
157
+ Assertions .assertEquals (DEFAULT_TABLE .getComment (), mergeTable .getComment ());
158
+ Assertions .assertEquals (DEFAULT_TABLE .getCatalogName (), mergeTable .getCatalogName ());
159
+ Assertions .assertNotEquals (DEFAULT_TABLE .getTableSchema (), mergeTable .getTableSchema ());
160
+ Assertions .assertEquals (
161
+ DEFAULT_TABLE .getTableSchema ().getPrimaryKey (),
162
+ mergeTable .getTableSchema ().getPrimaryKey ());
163
+ Assertions .assertEquals (
164
+ DEFAULT_TABLE .getTableSchema ().getConstraintKeys (),
165
+ mergeTable .getTableSchema ().getConstraintKeys ());
166
+
167
+ Map <String , Column > columnMap =
168
+ DEFAULT_TABLE .getTableSchema ().getColumns ().stream ()
169
+ .collect (Collectors .toMap (e -> e .getName (), e -> e ));
170
+ List <Column > sortByQueryColumns =
171
+ tableOfQuery .getTableSchema ().getColumns ().stream ()
172
+ .map (e -> columnMap .get (e .getName ()))
173
+ .collect (Collectors .toList ());
174
+ Assertions .assertEquals (sortByQueryColumns , mergeTable .getTableSchema ().getColumns ());
153
175
}
154
176
155
177
@ Test
0 commit comments