18
18
package org .apache .flink .cdc .cli .parser ;
19
19
20
20
import org .apache .flink .cdc .common .configuration .Configuration ;
21
+ import org .apache .flink .cdc .common .event .SchemaChangeEventType ;
21
22
import org .apache .flink .cdc .common .utils .StringUtils ;
22
23
import org .apache .flink .cdc .composer .definition .PipelineDef ;
23
24
import org .apache .flink .cdc .composer .definition .RouteDef ;
28
29
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .core .type .TypeReference ;
29
30
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .JsonNode ;
30
31
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .ObjectMapper ;
32
+ import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .node .ObjectNode ;
31
33
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
32
34
33
35
import java .nio .file .Path ;
34
36
import java .util .ArrayList ;
35
37
import java .util .List ;
36
38
import java .util .Map ;
37
39
import java .util .Optional ;
40
+ import java .util .Set ;
38
41
42
+ import static org .apache .flink .cdc .common .utils .ChangeEventUtils .resolveSchemaEvolutionOptions ;
39
43
import static org .apache .flink .cdc .common .utils .Preconditions .checkNotNull ;
40
44
41
45
/** Parser for converting YAML formatted pipeline definition to {@link PipelineDef}. */
@@ -51,6 +55,8 @@ public class YamlPipelineDefinitionParser implements PipelineDefinitionParser {
51
55
// Source / sink keys
52
56
private static final String TYPE_KEY = "type" ;
53
57
private static final String NAME_KEY = "name" ;
58
+ private static final String INCLUDE_SCHEMA_EVOLUTION_TYPES = "include.schema.changes" ;
59
+ private static final String EXCLUDE_SCHEMA_EVOLUTION_TYPES = "exclude.schema.changes" ;
54
60
55
61
// Route keys
56
62
private static final String ROUTE_SOURCE_TABLE_KEY = "source-table" ;
@@ -135,6 +141,23 @@ private SourceDef toSourceDef(JsonNode sourceNode) {
135
141
}
136
142
137
143
private SinkDef toSinkDef (JsonNode sinkNode ) {
144
+ List <String > includedSETypes = new ArrayList <>();
145
+ List <String > excludedSETypes = new ArrayList <>();
146
+
147
+ Optional .ofNullable (sinkNode .get (INCLUDE_SCHEMA_EVOLUTION_TYPES ))
148
+ .ifPresent (e -> e .forEach (tag -> includedSETypes .add (tag .asText ())));
149
+
150
+ Optional .ofNullable (sinkNode .get (EXCLUDE_SCHEMA_EVOLUTION_TYPES ))
151
+ .ifPresent (e -> e .forEach (tag -> excludedSETypes .add (tag .asText ())));
152
+
153
+ Set <SchemaChangeEventType > declaredSETypes =
154
+ resolveSchemaEvolutionOptions (includedSETypes , excludedSETypes );
155
+
156
+ if (sinkNode instanceof ObjectNode ) {
157
+ ((ObjectNode ) sinkNode ).remove (INCLUDE_SCHEMA_EVOLUTION_TYPES );
158
+ ((ObjectNode ) sinkNode ).remove (EXCLUDE_SCHEMA_EVOLUTION_TYPES );
159
+ }
160
+
138
161
Map <String , String > sinkMap =
139
162
mapper .convertValue (sinkNode , new TypeReference <Map <String , String >>() {});
140
163
@@ -148,7 +171,7 @@ private SinkDef toSinkDef(JsonNode sinkNode) {
148
171
// "name" field is optional
149
172
String name = sinkMap .remove (NAME_KEY );
150
173
151
- return new SinkDef (type , name , Configuration .fromMap (sinkMap ));
174
+ return new SinkDef (type , name , Configuration .fromMap (sinkMap ), declaredSETypes );
152
175
}
153
176
154
177
private RouteDef toRouteDef (JsonNode routeNode ) {
0 commit comments