25
25
import org .apache .flink .cdc .common .event .SchemaChangeEvent ;
26
26
import org .apache .flink .cdc .common .event .SchemaChangeEventType ;
27
27
import org .apache .flink .cdc .common .event .TableId ;
28
+ import org .apache .flink .cdc .common .exceptions .SchemaEvolveException ;
29
+ import org .apache .flink .cdc .common .exceptions .UnsupportedSchemaChangeEventException ;
28
30
import org .apache .flink .cdc .common .schema .Column ;
29
31
import org .apache .flink .cdc .common .sink .MetadataApplier ;
30
32
@@ -91,7 +93,8 @@ public Set<SchemaChangeEventType> getSupportedSchemaEvolutionTypes() {
91
93
}
92
94
93
95
@ Override
94
- public void applySchemaChange (SchemaChangeEvent schemaChangeEvent ) {
96
+ public void applySchemaChange (SchemaChangeEvent schemaChangeEvent )
97
+ throws SchemaEvolveException {
95
98
if (!isOpened ) {
96
99
isOpened = true ;
97
100
catalog .open ();
@@ -108,12 +111,11 @@ public void applySchemaChange(SchemaChangeEvent schemaChangeEvent) {
108
111
} else if (schemaChangeEvent instanceof AlterColumnTypeEvent ) {
109
112
applyAlterColumn ((AlterColumnTypeEvent ) schemaChangeEvent );
110
113
} else {
111
- throw new UnsupportedOperationException (
112
- "StarRocksDataSink doesn't support schema change event " + schemaChangeEvent );
114
+ throw new UnsupportedSchemaChangeEventException (schemaChangeEvent );
113
115
}
114
116
}
115
117
116
- private void applyCreateTable (CreateTableEvent createTableEvent ) {
118
+ private void applyCreateTable (CreateTableEvent createTableEvent ) throws SchemaEvolveException {
117
119
StarRocksTable starRocksTable =
118
120
StarRocksUtils .toStarRocksTable (
119
121
createTableEvent .tableId (),
@@ -128,11 +130,11 @@ private void applyCreateTable(CreateTableEvent createTableEvent) {
128
130
LOG .info ("Successful to create table, event: {}" , createTableEvent );
129
131
} catch (StarRocksCatalogException e ) {
130
132
LOG .error ("Failed to create table, event: {}" , createTableEvent .tableId (), e );
131
- throw new RuntimeException ( "Failed to create table, event: " + createTableEvent , e );
133
+ throw new SchemaEvolveException ( createTableEvent , "Failed to create table" , e );
132
134
}
133
135
}
134
136
135
- private void applyAddColumn (AddColumnEvent addColumnEvent ) {
137
+ private void applyAddColumn (AddColumnEvent addColumnEvent ) throws SchemaEvolveException {
136
138
List <StarRocksColumn > addColumns = new ArrayList <>();
137
139
for (AddColumnEvent .ColumnWithPosition columnWithPosition :
138
140
addColumnEvent .getAddedColumns ()) {
@@ -202,21 +204,21 @@ private void applyAddColumn(AddColumnEvent addColumnEvent) {
202
204
"Failed to apply add column because of alter exception, event: {}" ,
203
205
addColumnEvent ,
204
206
alterException );
205
- throw new RuntimeException (
206
- "Failed to apply add column because of alter exception, event: "
207
- + addColumnEvent ,
207
+ throw new SchemaEvolveException (
208
+ addColumnEvent ,
209
+ "Failed to apply add column because of alter exception, event: " ,
208
210
alterException );
209
211
} else {
210
212
String errorMsg =
211
213
String .format (
212
214
"Failed to apply add column because of validation failure, event: %s, table: %s" ,
213
215
addColumnEvent , table );
214
216
LOG .error (errorMsg );
215
- throw new RuntimeException ( errorMsg );
217
+ throw new SchemaEvolveException ( addColumnEvent , errorMsg , null );
216
218
}
217
219
}
218
220
219
- private void applyDropColumn (DropColumnEvent dropColumnEvent ) {
221
+ private void applyDropColumn (DropColumnEvent dropColumnEvent ) throws SchemaEvolveException {
220
222
List <String > dropColumns = dropColumnEvent .getDroppedColumnNames ();
221
223
TableId tableId = dropColumnEvent .tableId ();
222
224
StarRocksCatalogException alterException = null ;
@@ -268,33 +270,35 @@ private void applyDropColumn(DropColumnEvent dropColumnEvent) {
268
270
"Failed to apply drop column because of alter exception, event: {}" ,
269
271
dropColumnEvent ,
270
272
alterException );
271
- throw new RuntimeException (
272
- "Failed to apply drop column because of alter exception, event: "
273
- + dropColumnEvent ,
273
+ throw new SchemaEvolveException (
274
+ dropColumnEvent ,
275
+ "Failed to apply drop column because of alter exception" ,
274
276
alterException );
275
277
} else {
276
278
String errorMsg =
277
279
String .format (
278
280
"Failed to apply drop column because of validation failure, event: %s, table: %s" ,
279
281
dropColumnEvent , table );
280
282
LOG .error (errorMsg );
281
- throw new RuntimeException ( errorMsg );
283
+ throw new SchemaEvolveException ( dropColumnEvent , errorMsg , null );
282
284
}
283
285
}
284
286
285
- private void applyRenameColumn (RenameColumnEvent renameColumnEvent ) {
287
+ private void applyRenameColumn (RenameColumnEvent renameColumnEvent )
288
+ throws SchemaEvolveException {
286
289
// TODO StarRocks plans to support column rename since 3.3 which has not been released.
287
290
// Support it later.
288
- throw new UnsupportedOperationException ( "Rename column is not supported currently" );
291
+ throw new UnsupportedSchemaChangeEventException ( renameColumnEvent );
289
292
}
290
293
291
- private void applyAlterColumn (AlterColumnTypeEvent alterColumnTypeEvent ) {
294
+ private void applyAlterColumn (AlterColumnTypeEvent alterColumnTypeEvent )
295
+ throws SchemaEvolveException {
292
296
// TODO There are limitations for data type conversions. We should know the data types
293
297
// before and after changing so that we can make a validation. But the event only contains
294
298
// data
295
299
// types after changing. One way is that the framework delivers the old schema. We can
296
300
// support
297
301
// the alter after a discussion.
298
- throw new UnsupportedOperationException ( "Alter column is not supported currently" );
302
+ throw new UnsupportedSchemaChangeEventException ( alterColumnTypeEvent );
299
303
}
300
304
}
0 commit comments