@@ -148,22 +148,15 @@ private List<SchemaChange> applyAddColumnEventWithPosition(AddColumnEvent event)
148148 switch (columnWithPosition .getPosition ()) {
149149 case FIRST :
150150 tableChange =
151- SchemaChange .addColumn (
152- columnWithPosition .getAddColumn ().getName (),
153- LogicalTypeConversion .toDataType (
154- DataTypeUtils .toFlinkDataType (
155- columnWithPosition
156- .getAddColumn ()
157- .getType ())
158- .getLogicalType ()),
159- columnWithPosition .getAddColumn ().getComment (),
151+ SchemaChangeProvider .add (
152+ columnWithPosition ,
160153 SchemaChange .Move .first (
161154 columnWithPosition .getAddColumn ().getName ()));
162155 tableChangeList .add (tableChange );
163156 break ;
164157 case LAST :
165158 SchemaChange schemaChangeWithLastPosition =
166- applyAddColumnWithLastPosition (columnWithPosition );
159+ SchemaChangeProvider . add (columnWithPosition );
167160 tableChangeList .add (schemaChangeWithLastPosition );
168161 break ;
169162 case BEFORE :
@@ -178,19 +171,11 @@ private List<SchemaChange> applyAddColumnEventWithPosition(AddColumnEvent event)
178171 checkNotNull (
179172 columnWithPosition .getExistedColumnName (),
180173 "Existing column name must be provided for AFTER position" );
181- tableChange =
182- SchemaChange .addColumn (
174+ SchemaChange . Move after =
175+ SchemaChange .Move . after (
183176 columnWithPosition .getAddColumn ().getName (),
184- LogicalTypeConversion .toDataType (
185- DataTypeUtils .toFlinkDataType (
186- columnWithPosition
187- .getAddColumn ()
188- .getType ())
189- .getLogicalType ()),
190- columnWithPosition .getAddColumn ().getComment (),
191- SchemaChange .Move .after (
192- columnWithPosition .getAddColumn ().getName (),
193- columnWithPosition .getExistedColumnName ()));
177+ columnWithPosition .getExistedColumnName ());
178+ tableChange = SchemaChangeProvider .add (columnWithPosition , after );
194179 tableChangeList .add (tableChange );
195180 break ;
196181 default :
@@ -201,16 +186,6 @@ private List<SchemaChange> applyAddColumnEventWithPosition(AddColumnEvent event)
201186 return tableChangeList ;
202187 }
203188
204- private SchemaChange applyAddColumnWithLastPosition (
205- AddColumnEvent .ColumnWithPosition columnWithPosition ) {
206- return SchemaChange .addColumn (
207- columnWithPosition .getAddColumn ().getName (),
208- LogicalTypeConversion .toDataType (
209- DataTypeUtils .toFlinkDataType (columnWithPosition .getAddColumn ().getType ())
210- .getLogicalType ()),
211- columnWithPosition .getAddColumn ().getComment ());
212- }
213-
214189 private SchemaChange applyAddColumnWithBeforePosition (
215190 String schemaName ,
216191 String tableName ,
@@ -220,23 +195,19 @@ private SchemaChange applyAddColumnWithBeforePosition(
220195 Table table = catalog .getTable (new Identifier (schemaName , tableName ));
221196 List <String > columnNames = table .rowType ().getFieldNames ();
222197 int index = checkColumnPosition (existedColumnName , columnNames );
223-
224- return SchemaChange .addColumn (
225- columnWithPosition .getAddColumn ().getName (),
226- LogicalTypeConversion .toDataType (
227- DataTypeUtils .toFlinkDataType (columnWithPosition .getAddColumn ().getType ())
228- .getLogicalType ()),
229- columnWithPosition .getAddColumn ().getComment (),
198+ SchemaChange .Move after =
230199 SchemaChange .Move .after (
231- columnWithPosition .getAddColumn ().getName (), columnNames .get (index - 1 )));
200+ columnWithPosition .getAddColumn ().getName (), columnNames .get (index - 1 ));
201+
202+ return SchemaChangeProvider .add (columnWithPosition , after );
232203 }
233204
234205 private int checkColumnPosition (String existedColumnName , List <String > columnNames ) {
235206 if (existedColumnName == null ) {
236207 return 0 ;
237208 }
238209 int index = columnNames .indexOf (existedColumnName );
239- checkArgument (index = = -1 , "Column %s not found" , existedColumnName );
210+ checkArgument (index ! = -1 , "Column %s not found" , existedColumnName );
240211 return index ;
241212 }
242213
@@ -245,11 +216,7 @@ private void applyDropColumn(DropColumnEvent event)
245216 Catalog .ColumnNotExistException {
246217 List <SchemaChange > tableChangeList = new ArrayList <>();
247218 event .getDroppedColumnNames ()
248- .forEach (
249- (column ) -> {
250- SchemaChange tableChange = SchemaChange .dropColumn (column );
251- tableChangeList .add (tableChange );
252- });
219+ .forEach ((column ) -> tableChangeList .add (SchemaChangeProvider .drop (column )));
253220 catalog .alterTable (
254221 new Identifier (event .tableId ().getSchemaName (), event .tableId ().getTableName ()),
255222 tableChangeList ,
@@ -262,10 +229,8 @@ private void applyRenameColumn(RenameColumnEvent event)
262229 List <SchemaChange > tableChangeList = new ArrayList <>();
263230 event .getNameMapping ()
264231 .forEach (
265- (oldName , newName ) -> {
266- SchemaChange tableChange = SchemaChange .renameColumn (oldName , newName );
267- tableChangeList .add (tableChange );
268- });
232+ (oldName , newName ) ->
233+ tableChangeList .add (SchemaChangeProvider .rename (oldName , newName )));
269234 catalog .alterTable (
270235 new Identifier (event .tableId ().getSchemaName (), event .tableId ().getTableName ()),
271236 tableChangeList ,
@@ -278,15 +243,9 @@ private void applyAlterColumn(AlterColumnTypeEvent event)
278243 List <SchemaChange > tableChangeList = new ArrayList <>();
279244 event .getTypeMapping ()
280245 .forEach (
281- (oldName , newType ) -> {
282- SchemaChange tableChange =
283- SchemaChange .updateColumnType (
284- oldName ,
285- LogicalTypeConversion .toDataType (
286- DataTypeUtils .toFlinkDataType (newType )
287- .getLogicalType ()));
288- tableChangeList .add (tableChange );
289- });
246+ (oldName , newType ) ->
247+ tableChangeList .add (
248+ SchemaChangeProvider .updateColumnType (oldName , newType )));
290249 catalog .alterTable (
291250 new Identifier (event .tableId ().getSchemaName (), event .tableId ().getTableName ()),
292251 tableChangeList ,
0 commit comments