|
23 | 23 | import org.apache.flink.cdc.common.event.Event;
|
24 | 24 | import org.apache.flink.cdc.common.factories.DataSourceFactory;
|
25 | 25 | import org.apache.flink.cdc.common.factories.FactoryHelper;
|
| 26 | +import org.apache.flink.cdc.common.route.RouteRule; |
26 | 27 | import org.apache.flink.cdc.common.source.DataSource;
|
27 | 28 | import org.apache.flink.cdc.common.source.EventSourceProvider;
|
28 | 29 | import org.apache.flink.cdc.common.source.FlinkSourceFunctionProvider;
|
29 | 30 | import org.apache.flink.cdc.common.source.FlinkSourceProvider;
|
| 31 | +import org.apache.flink.cdc.composer.definition.RouteDef; |
30 | 32 | import org.apache.flink.cdc.composer.definition.SourceDef;
|
31 | 33 | import org.apache.flink.cdc.composer.flink.FlinkEnvironmentUtils;
|
32 | 34 | import org.apache.flink.cdc.composer.utils.FactoryDiscoveryUtils;
|
|
35 | 37 | import org.apache.flink.streaming.api.datastream.DataStreamSource;
|
36 | 38 | import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
|
37 | 39 |
|
| 40 | +import java.util.List; |
| 41 | +import java.util.stream.Collectors; |
| 42 | + |
38 | 43 | /** Translator used to build {@link DataSource} which will generate a {@link DataStream}. */
|
39 | 44 | @Internal
|
40 | 45 | public class DataSourceTranslator {
|
@@ -76,14 +81,37 @@ public DataStreamSource<Event> translate(
|
76 | 81 | }
|
77 | 82 |
|
78 | 83 | public DataSource createDataSource(
|
79 |
| - SourceDef sourceDef, Configuration pipelineConfig, StreamExecutionEnvironment env) { |
| 84 | + SourceDef sourceDef, |
| 85 | + List<RouteDef> routes, |
| 86 | + Configuration pipelineConfig, |
| 87 | + StreamExecutionEnvironment env) { |
80 | 88 | // Search the data source factory
|
81 | 89 | DataSourceFactory sourceFactory =
|
82 | 90 | FactoryDiscoveryUtils.getFactoryByIdentifier(
|
83 | 91 | sourceDef.getType(), DataSourceFactory.class);
|
84 | 92 | // Add source JAR to environment
|
85 | 93 | FactoryDiscoveryUtils.getJarPathByIdentifier(sourceFactory)
|
86 | 94 | .ifPresent(jar -> FlinkEnvironmentUtils.addJar(env, jar));
|
| 95 | + |
| 96 | + if (routes != null && !routes.isEmpty()) { |
| 97 | + List<RouteRule> routeRules = |
| 98 | + routes.stream() |
| 99 | + .map( |
| 100 | + routeDef -> |
| 101 | + new RouteRule( |
| 102 | + routeDef.getSourceTable(), |
| 103 | + routeDef.getSinkTable(), |
| 104 | + routeDef.getReplaceSymbol().isPresent() |
| 105 | + ? routeDef.getReplaceSymbol().get() |
| 106 | + : null)) |
| 107 | + .collect(Collectors.toList()); |
| 108 | + return sourceFactory.createDataSource( |
| 109 | + new FactoryHelper.DefaultContext( |
| 110 | + sourceDef.getConfig(), |
| 111 | + pipelineConfig, |
| 112 | + routeRules, |
| 113 | + Thread.currentThread().getContextClassLoader())); |
| 114 | + } |
87 | 115 | return sourceFactory.createDataSource(
|
88 | 116 | new FactoryHelper.DefaultContext(
|
89 | 117 | sourceDef.getConfig(),
|
|
0 commit comments