Unverified Commit 2056376a authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Feature-2712][cdc] Support Flink CDC pipeline task in FlinkSQL dialect (#2713)

* [Feature-2712][cdc] Support Flink CDC pipeline task in FlinkSQL dialect * fix compile error * fix compile error * optimize the syntax of execute pipeline --------- Co-authored-by: 's avatarwenmo <32723967+wenmo@users.noreply.github.com>
parent 678ead0b
......@@ -33,6 +33,7 @@ import org.apache.doris.flink.cfg.DorisOptions;
import org.apache.doris.flink.cfg.DorisReadOptions;
import org.apache.doris.flink.sink.DorisSink;
import org.apache.doris.flink.sink.writer.JsonDebeziumSchemaSerializer;
import org.apache.doris.flink.sink.writer.serializer.DorisRecordSerializer;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
......@@ -164,7 +165,7 @@ public class DorisSchemaEvolutionSinkBuilder extends AbstractSinkBuilder impleme
builder.setDorisReadOptions(DorisReadOptions.builder().build())
.setDorisExecutionOptions(executionBuilder.build())
.setDorisOptions(dorisOptions)
.setSerializer(JsonDebeziumSchemaSerializer.builder()
.setSerializer((DorisRecordSerializer<String>) JsonDebeziumSchemaSerializer.builder()
.setDorisOptions(dorisOptions)
.build());
......
......@@ -30,6 +30,7 @@ import org.apache.doris.flink.cfg.DorisOptions;
import org.apache.doris.flink.cfg.DorisReadOptions;
import org.apache.doris.flink.sink.DorisSink;
import org.apache.doris.flink.sink.writer.RowDataSerializer;
import org.apache.doris.flink.sink.writer.serializer.DorisRecordSerializer;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.data.RowData;
......@@ -184,7 +185,7 @@ public class DorisSinkBuilder extends AbstractSinkBuilder implements Serializabl
DorisSink.Builder<RowData> builder = DorisSink.builder();
builder.setDorisReadOptions(readOptionBuilder.build())
.setDorisExecutionOptions(executionBuilder.build())
.setSerializer(RowDataSerializer.builder()
.setSerializer((DorisRecordSerializer<RowData>) RowDataSerializer.builder()
.setFieldNames(columnNames)
.setType("json")
.enableDelete(true)
......
org.dinky.cdc.kafka.KafkaSinkBuilder
org.dinky.cdc.kafka.KafkaSinkJsonBuilder
org.dinky.cdc.doris.DorisExtendSinkBuilder
org.dinky.cdc.doris.DorisSinkBuilder
org.dinky.cdc.doris.DorisSchemaEvolutionSinkBuilder
\ No newline at end of file
......@@ -23,12 +23,6 @@
</properties>
<profiles>
<profile>
<id>flink-1.14</id>
<modules>
<module>dinky-cdc-plus</module>
</modules>
</profile>
<profile>
<id>flink-1.15</id>
<modules>
......
......@@ -56,6 +56,7 @@ public enum SqlType {
RESET("RESET", "^RESET.*"),
EXECUTE("EXECUTE", "^EXECUTE.*"),
ADD_JAR("ADD_JAR", "^ADD\\s+JAR\\s+\\S+"),
ADD("ADD", "^ADD\\s+CUSTOMJAR\\s+\\S+"),
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ververica.cdc.composer.flink;
import org.apache.flink.core.execution.JobClient;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import com.ververica.cdc.composer.PipelineExecution;
/**
* A pipeline execution that run the defined pipeline via Flink's {@link
* StreamExecutionEnvironment}.
*/
public class FlinkPipelineExecution implements PipelineExecution {
private final StreamExecutionEnvironment env;
private final String jobName;
private final boolean isBlocking;
public FlinkPipelineExecution(StreamExecutionEnvironment env, String jobName, boolean isBlocking) {
this.env = env;
this.jobName = jobName;
this.isBlocking = isBlocking;
}
public StreamExecutionEnvironment getEnv() {
return env;
}
public String getJobName() {
return jobName;
}
public boolean isBlocking() {
return isBlocking;
}
@Override
public ExecutionInfo execute() throws Exception {
JobClient jobClient = env.executeAsync(jobName);
if (isBlocking) {
jobClient.getJobExecutionResult().get();
}
return new ExecutionInfo(jobClient.getJobID().toString(), jobName);
}
}
......@@ -83,7 +83,7 @@ public abstract class Executor {
protected DinkyClassLoader dinkyClassLoader;
// Flink configuration, such as set rest.port = 8086
protected Map<String, Object> setConfig = new HashMap<>();
protected Map<String, String> setConfig = new HashMap<>();
// Dinky variable manager
protected VariableManager variableManager = new VariableManager();
......@@ -109,6 +109,10 @@ public abstract class Executor {
return environment;
}
public void setStreamExecutionEnvironment(StreamExecutionEnvironment environment) {
this.environment = environment;
}
public CustomTableEnvironment getCustomTableEnvironment() {
return tableEnvironment;
}
......@@ -117,7 +121,7 @@ public abstract class Executor {
return executorConfig;
}
public Map<String, Object> getSetConfig() {
public Map<String, String> getSetConfig() {
return setConfig;
}
......
......@@ -227,12 +227,12 @@ public class JobConfig {
gatewayConfig.setTaskId(getTaskId());
}
public void addGatewayConfig(Map<String, Object> config) {
public void addGatewayConfig(Map<String, String> config) {
if (Asserts.isNull(gatewayConfig)) {
gatewayConfig = new GatewayConfig();
}
for (Map.Entry<String, Object> entry : config.entrySet()) {
gatewayConfig.getFlinkConfig().getConfiguration().put(entry.getKey(), (String) entry.getValue());
for (Map.Entry<String, String> entry : config.entrySet()) {
gatewayConfig.getFlinkConfig().getConfiguration().put(entry.getKey(), entry.getValue());
}
}
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.trans.pipeline;
import org.apache.flink.configuration.DeploymentOptions;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import com.ververica.cdc.common.configuration.Configuration;
import com.ververica.cdc.common.event.Event;
import com.ververica.cdc.common.factories.DataSinkFactory;
import com.ververica.cdc.common.factories.FactoryHelper;
import com.ververica.cdc.common.pipeline.PipelineOptions;
import com.ververica.cdc.common.sink.DataSink;
import com.ververica.cdc.composer.PipelineComposer;
import com.ververica.cdc.composer.definition.PipelineDef;
import com.ververica.cdc.composer.definition.SinkDef;
import com.ververica.cdc.composer.flink.FlinkEnvironmentUtils;
import com.ververica.cdc.composer.flink.coordination.OperatorIDGenerator;
import com.ververica.cdc.composer.flink.translator.DataSinkTranslator;
import com.ververica.cdc.composer.flink.translator.DataSourceTranslator;
import com.ververica.cdc.composer.flink.translator.PartitioningTranslator;
import com.ververica.cdc.composer.flink.translator.RouteTranslator;
import com.ververica.cdc.composer.flink.translator.SchemaOperatorTranslator;
import com.ververica.cdc.composer.utils.FactoryDiscoveryUtils;
import com.ververica.cdc.runtime.serializer.event.EventSerializer;
/**
* DinkyFlinkPipelineComposer
*
* @author wenmo
* @since 2023/12/22 0:16
*/
public class DinkyFlinkPipelineComposer implements PipelineComposer {
private final StreamExecutionEnvironment env;
private final boolean isBlocking;
public static DinkyFlinkPipelineComposer ofRemoteCluster(
org.apache.flink.configuration.Configuration flinkConfig, List<Path> additionalJars) {
org.apache.flink.configuration.Configuration effectiveConfiguration =
new org.apache.flink.configuration.Configuration();
// Use "remote" as the default target
effectiveConfiguration.set(DeploymentOptions.TARGET, "remote");
effectiveConfiguration.addAll(flinkConfig);
StreamExecutionEnvironment env = new StreamExecutionEnvironment(effectiveConfiguration);
additionalJars.forEach(jarPath -> {
try {
FlinkEnvironmentUtils.addJar(env, jarPath.toUri().toURL());
} catch (Exception e) {
throw new RuntimeException(
String.format(
"Unable to convert JAR path \"%s\" to URL when adding JAR to Flink environment",
jarPath),
e);
}
});
return new DinkyFlinkPipelineComposer(env, false);
}
public static DinkyFlinkPipelineComposer ofMiniCluster() {
return new DinkyFlinkPipelineComposer(StreamExecutionEnvironment.getExecutionEnvironment(), true);
}
private DinkyFlinkPipelineComposer(StreamExecutionEnvironment env, boolean isBlocking) {
this.env = env;
this.isBlocking = isBlocking;
}
@Override
public DinkyFlinkPipelineExecution compose(PipelineDef pipelineDef) {
int parallelism = pipelineDef.getConfig().get(PipelineOptions.PIPELINE_PARALLELISM);
env.getConfig().setParallelism(parallelism);
// Source
DataSourceTranslator sourceTranslator = new DataSourceTranslator();
DataStream<Event> stream = sourceTranslator.translate(pipelineDef.getSource(), env, pipelineDef.getConfig());
// Route
RouteTranslator routeTranslator = new RouteTranslator();
stream = routeTranslator.translate(stream, pipelineDef.getRoute());
// Create sink in advance as schema operator requires MetadataApplier
DataSink dataSink = createDataSink(pipelineDef.getSink(), pipelineDef.getConfig());
// Schema operator
SchemaOperatorTranslator schemaOperatorTranslator = new SchemaOperatorTranslator(
pipelineDef.getConfig().get(PipelineOptions.PIPELINE_SCHEMA_CHANGE_BEHAVIOR),
pipelineDef.getConfig().get(PipelineOptions.PIPELINE_SCHEMA_OPERATOR_UID));
stream = schemaOperatorTranslator.translate(stream, parallelism, dataSink.getMetadataApplier());
OperatorIDGenerator schemaOperatorIDGenerator =
new OperatorIDGenerator(schemaOperatorTranslator.getSchemaOperatorUid());
// Add partitioner
PartitioningTranslator partitioningTranslator = new PartitioningTranslator();
stream = partitioningTranslator.translate(
stream, parallelism, parallelism, schemaOperatorIDGenerator.generate());
// Sink
DataSinkTranslator sinkTranslator = new DataSinkTranslator();
sinkTranslator.translate(pipelineDef.getSink(), stream, dataSink, schemaOperatorIDGenerator.generate());
// Add framework JARs
addFrameworkJars();
return new DinkyFlinkPipelineExecution(
env, pipelineDef.getConfig().get(PipelineOptions.PIPELINE_NAME), isBlocking);
}
private DataSink createDataSink(SinkDef sinkDef, Configuration pipelineConfig) {
// Search the data sink factory
DataSinkFactory sinkFactory =
FactoryDiscoveryUtils.getFactoryByIdentifier(sinkDef.getType(), DataSinkFactory.class);
// Include sink connector JAR
FactoryDiscoveryUtils.getJarPathByIdentifier(sinkDef.getType(), DataSinkFactory.class)
.ifPresent(jar -> FlinkEnvironmentUtils.addJar(env, jar));
// Create data sink
return sinkFactory.createDataSink(new FactoryHelper.DefaultContext(
sinkDef.getConfig(), pipelineConfig, Thread.currentThread().getContextClassLoader()));
}
private void addFrameworkJars() {
try {
Set<URI> frameworkJars = new HashSet<>();
// Common JAR
// We use the core interface (Event) to search the JAR
Optional<URL> commonJar = getContainingJar(Event.class);
if (commonJar.isPresent()) {
frameworkJars.add(commonJar.get().toURI());
}
// Runtime JAR
// We use the serializer of the core interface (EventSerializer) to search the JAR
Optional<URL> runtimeJar = getContainingJar(EventSerializer.class);
if (runtimeJar.isPresent()) {
frameworkJars.add(runtimeJar.get().toURI());
}
for (URI jar : frameworkJars) {
FlinkEnvironmentUtils.addJar(env, jar.toURL());
}
} catch (Exception e) {
throw new RuntimeException("Failed to search and add Flink CDC framework JARs", e);
}
}
private Optional<URL> getContainingJar(Class<?> clazz) throws Exception {
URL container = clazz.getProtectionDomain().getCodeSource().getLocation();
if (Files.isDirectory(Paths.get(container.toURI()))) {
return Optional.empty();
}
return Optional.of(container);
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.trans.pipeline;
import org.apache.flink.core.execution.JobClient;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import com.ververica.cdc.composer.PipelineExecution;
/**
* A pipeline execution that run the defined pipeline via Flink's {@link
* StreamExecutionEnvironment}.
*/
public class DinkyFlinkPipelineExecution implements PipelineExecution {
private final StreamExecutionEnvironment env;
private final String jobName;
private final boolean isBlocking;
public DinkyFlinkPipelineExecution(StreamExecutionEnvironment env, String jobName, boolean isBlocking) {
this.env = env;
this.jobName = jobName;
this.isBlocking = isBlocking;
}
public StreamExecutionEnvironment getEnv() {
return env;
}
public String getJobName() {
return jobName;
}
public boolean isBlocking() {
return isBlocking;
}
@Override
public ExecutionInfo execute() throws Exception {
JobClient jobClient = env.executeAsync(jobName);
if (isBlocking) {
jobClient.getJobExecutionResult().get();
}
return new ExecutionInfo(jobClient.getJobID().toString(), jobName);
}
}
......@@ -17,18 +17,18 @@
*
*/
package org.dinky.cdc.doris;
package org.dinky.trans.pipeline;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;
import com.ververica.cdc.composer.PipelineExecution;
import com.ververica.cdc.composer.definition.PipelineDef;
public class DorisExtendSinkOptions extends DorisSinkOptions {
/** Composer for translating a pipeline definition to an execution. */
public interface DinkyPipelineComposer {
public static final ConfigOption<String> AdditionalColumns = ConfigOptions.key("additional-columns")
.stringType()
.noDefaultValue()
.withDescription(
"Additional columns for sink, support meta column and fix value column."
+ "(meta: op_ts,database_name,schema_name,table_name; "
+ "fix value column type:BOOLEAN,INT,TINYINT,BIGINT,DECIMAL,FLOAT,DATE,TIMESTAMP,CHAR,VARCHAR,STRING)");
/**
* Composing pipeline execution from the specified pipeline definition.
*
* @param pipelineDef definition of the pipeline
*/
PipelineExecution compose(PipelineDef pipelineDef);
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.trans.pipeline;
import org.dinky.executor.Executor;
import org.dinky.gateway.enums.GatewayType;
import org.dinky.trans.AbstractOperation;
import org.dinky.trans.Operation;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.api.TableResult;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import com.ververica.cdc.composer.PipelineComposer;
import com.ververica.cdc.composer.definition.PipelineDef;
/**
* FlinkCDCPipelineOperation
*
* ################################################################################
* # Description: Sync MySQL all tables to Doris
* ################################################################################
* source:
* type: mysql
* hostname: localhost
* port: 3306
* username: root
* password: 123456
* tables: app_db.\.*
* server-id: 5400-5404
* server-time-zone: UTC
*
* sink:
* type: doris
* fenodes: 127.0.0.1:8030
* username: root
* password: ""
* table.create.properties.light_schema_change: true
* table.create.properties.replication_num: 1
*
* pipeline:
* name: Sync MySQL Database to Doris
* parallelism: 2
*/
public class FlinkCDCPipelineOperation extends AbstractOperation implements Operation {
private static final String KEY_WORD = "EXECUTE PIPELINE";
public FlinkCDCPipelineOperation() {}
public FlinkCDCPipelineOperation(String statement) {
super(statement);
}
@Override
public String getHandle() {
return KEY_WORD;
}
@Override
public Operation create(String statement) {
return new FlinkCDCPipelineOperation(statement);
}
@Override
public TableResult execute(Executor executor) {
String yamlText = statement.substring(statement.indexOf("(") + 1, statement.lastIndexOf(")"));
com.ververica.cdc.common.configuration.Configuration globalPipelineConfig =
com.ververica.cdc.common.configuration.Configuration.fromMap(executor.getSetConfig());
// Parse pipeline definition file
YamlTextPipelineDefinitionParser pipelineDefinitionParser = new YamlTextPipelineDefinitionParser();
PipelineDef pipelineDef = null;
try {
pipelineDef = pipelineDefinitionParser.parse(yamlText, globalPipelineConfig);
} catch (Exception e) {
e.printStackTrace();
}
boolean useMiniCluster =
GatewayType.get(executor.getExecutorConfig().getType()).isLocalExecute();
Configuration configuration = Configuration.fromMap(executor.getSetConfig());
configuration.addAll(executor.getCustomTableEnvironment().getRootConfiguration());
List<Path> additionalJars = new ArrayList<>();
// Create composer
PipelineComposer composer = createComposer(useMiniCluster, configuration, additionalJars);
// Compose pipeline
DinkyFlinkPipelineExecution execution = (DinkyFlinkPipelineExecution) composer.compose(pipelineDef);
executor.setStreamExecutionEnvironment(execution.getEnv());
return null;
}
public DinkyFlinkPipelineComposer createComposer(
boolean useMiniCluster, Configuration flinkConfig, List<Path> additionalJars) {
if (useMiniCluster) {
return DinkyFlinkPipelineComposer.ofMiniCluster();
}
return DinkyFlinkPipelineComposer.ofRemoteCluster(flinkConfig, additionalJars);
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.trans.pipeline;
import static com.ververica.cdc.common.utils.Preconditions.checkNotNull;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.type.TypeReference;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.ververica.cdc.common.configuration.Configuration;
import com.ververica.cdc.composer.definition.PipelineDef;
import com.ververica.cdc.composer.definition.RouteDef;
import com.ververica.cdc.composer.definition.SinkDef;
import com.ververica.cdc.composer.definition.SourceDef;
/**
* YamlTextPipelineDefinitionParser
*/
/** Parser for converting YAML formatted pipeline definition to {@link PipelineDef}. */
public class YamlTextPipelineDefinitionParser {
// Parent node keys
private static final String SOURCE_KEY = "source";
private static final String SINK_KEY = "sink";
private static final String ROUTE_KEY = "route";
private static final String PIPELINE_KEY = "pipeline";
// Source / sink keys
private static final String TYPE_KEY = "type";
private static final String NAME_KEY = "name";
// Route keys
private static final String ROUTE_SOURCE_TABLE_KEY = "source-table";
private static final String ROUTE_SINK_TABLE_KEY = "sink-table";
private static final String ROUTE_DESCRIPTION_KEY = "description";
private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
/** Parse the specified pipeline definition text. */
public PipelineDef parse(String text, Configuration globalPipelineConfig) throws Exception {
JsonNode root = mapper.readTree(text);
// Source is required
SourceDef sourceDef = toSourceDef(
checkNotNull(root.get(SOURCE_KEY), "Missing required field \"%s\" in pipeline definition", SOURCE_KEY));
// Sink is required
SinkDef sinkDef = toSinkDef(
checkNotNull(root.get(SINK_KEY), "Missing required field \"%s\" in pipeline definition", SINK_KEY));
// Routes are optional
List<RouteDef> routeDefs = new ArrayList<>();
Optional.ofNullable(root.get(ROUTE_KEY))
.ifPresent(node -> node.forEach(route -> routeDefs.add(toRouteDef(route))));
// Pipeline configs are optional
Configuration userPipelineConfig = toPipelineConfig(root.get(PIPELINE_KEY));
// Merge user config into global config
Configuration pipelineConfig = new Configuration();
pipelineConfig.addAll(globalPipelineConfig);
pipelineConfig.addAll(userPipelineConfig);
return new PipelineDef(sourceDef, sinkDef, routeDefs, null, pipelineConfig);
}
private SourceDef toSourceDef(JsonNode sourceNode) {
Map<String, String> sourceMap = mapper.convertValue(sourceNode, new TypeReference<Map<String, String>>() {});
// "type" field is required
String type = checkNotNull(
sourceMap.remove(TYPE_KEY), "Missing required field \"%s\" in source configuration", TYPE_KEY);
// "name" field is optional
String name = sourceMap.remove(NAME_KEY);
return new SourceDef(type, name, Configuration.fromMap(sourceMap));
}
private SinkDef toSinkDef(JsonNode sinkNode) {
Map<String, String> sinkMap = mapper.convertValue(sinkNode, new TypeReference<Map<String, String>>() {});
// "type" field is required
String type =
checkNotNull(sinkMap.remove(TYPE_KEY), "Missing required field \"%s\" in sink configuration", TYPE_KEY);
// "name" field is optional
String name = sinkMap.remove(NAME_KEY);
return new SinkDef(type, name, Configuration.fromMap(sinkMap));
}
private RouteDef toRouteDef(JsonNode routeNode) {
String sourceTable = checkNotNull(
routeNode.get(ROUTE_SOURCE_TABLE_KEY),
"Missing required field \"%s\" in route configuration",
ROUTE_SOURCE_TABLE_KEY)
.asText();
String sinkTable = checkNotNull(
routeNode.get(ROUTE_SINK_TABLE_KEY),
"Missing required field \"%s\" in route configuration",
ROUTE_SINK_TABLE_KEY)
.asText();
String description = Optional.ofNullable(routeNode.get(ROUTE_DESCRIPTION_KEY))
.map(JsonNode::asText)
.orElse(null);
return new RouteDef(sourceTable, sinkTable, description);
}
private Configuration toPipelineConfig(JsonNode pipelineConfigNode) {
if (pipelineConfigNode == null || pipelineConfigNode.isNull()) {
return new Configuration();
}
Map<String, String> pipelineConfigMap =
mapper.convertValue(pipelineConfigNode, new TypeReference<Map<String, String>>() {});
return Configuration.fromMap(pipelineConfigMap);
}
}
......@@ -48,7 +48,7 @@ public class KerberosUtil {
}
}
public static void authenticate(Map<String, Object> configuration) {
public static void authenticate(Map<String, String> configuration) {
configuration.forEach((k, v) -> logger.debug("Flink configuration key: [{}], value: [{}]", k, v));
String krb5ConfPath = (String) configuration.getOrDefault("java.security.krb5.conf", "");
String keytabPath = (String) configuration.getOrDefault("security.kerberos.login.keytab", "");
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.interceptor;
import org.dinky.classloader.DinkyClassLoader;
import org.dinky.executor.Executor;
import org.dinky.executor.ExecutorConfig;
import org.dinky.executor.ExecutorFactory;
import org.junit.Ignore;
import org.junit.Test;
/**
* FlinkCDCPipelineTest
*
*/
public class FlinkCDCPipelineTest {
@Ignore
@Test
public void mysqlTest() throws Exception {
String statement = new StringBuilder()
.append("source:\n" + " type: mysql\n"
+ " hostname: localhost\n"
+ " port: 3306\n"
+ " username: root\n"
+ " password: 123456\n"
+ " tables: app_db.\\.*\n"
+ " server-id: 5400-5404\n"
+ " server-time-zone: UTC\n"
+ "\n"
+ "sink:\n"
+ " type: doris\n"
+ " fenodes: 127.0.0.1:8030\n"
+ " username: root\n"
+ " password: \"\"\n"
+ " table.create.properties.light_schema_change: true\n"
+ " table.create.properties.replication_num: 1\n"
+ "\n"
+ "pipeline:\n"
+ " name: Sync MySQL Database to Doris\n"
+ " parallelism: 2")
.toString();
ExecutorConfig executorConfig = ExecutorConfig.DEFAULT;
Executor executor = ExecutorFactory.buildLocalExecutor(executorConfig, DinkyClassLoader.build());
executor.executeSql(statement);
executor.execute("");
}
}
......@@ -132,6 +132,26 @@
<artifactId>flink-sql-connector-postgres-cdc</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-cli</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-mysql</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-doris</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-starrocks</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-jdbc_${scala.binary.version}</artifactId>
......
......@@ -152,6 +152,26 @@
<artifactId>flink-sql-connector-sqlserver-cdc</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-cli</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-mysql</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-doris</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-starrocks</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
......
......@@ -106,6 +106,26 @@
<artifactId>flink-sql-connector-postgres-cdc</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-cli</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-mysql</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-doris</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-starrocks</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
......@@ -118,7 +138,7 @@
<dependency>
<groupId>org.apache.doris</groupId>
<artifactId>flink-doris-connector-1.16</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
......
......@@ -99,6 +99,26 @@
<artifactId>flink-sql-connector-postgres-cdc</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-cli</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-mysql</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-doris</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-starrocks</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
......@@ -110,8 +130,8 @@
</dependency>
<dependency>
<groupId>org.apache.doris</groupId>
<artifactId>flink-doris-connector-1.16</artifactId>
<version>1.3.0</version>
<artifactId>flink-doris-connector-1.17</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
......
......@@ -99,6 +99,26 @@
<artifactId>flink-sql-connector-postgres-cdc</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-cli</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-mysql</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-doris</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>com.ververica</groupId>
<artifactId>flink-cdc-pipeline-connector-starrocks</artifactId>
<version>${flinkcdc.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment