Unverified Commit 58a2aca4 authored by Licho's avatar Licho Committed by GitHub

feat: remove flink1.12 (#1929)

* feat: remove flink1.12 * Spotless Apply * feat: remove 1.12 from script assembly and doc Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> --------- Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent a509055e
......@@ -157,16 +157,12 @@ jobs:
fail-fast: true
matrix:
url: [ registry.cn-hangzhou.aliyuncs.com ,docker.io ]
FLINK_VERSION: [1.11.6 , 1.12.7 , 1.13.6 , 1.14.6 , 1.15.2 , 1.16.0]
FLINK_VERSION: [1.13.6 , 1.14.6 , 1.15.2 , 1.16.0]
include:
- url: registry.cn-hangzhou.aliyuncs.com
namespace: dinky
- url: docker.io
namespace: dinkydocker
- FLINK_VERSION: 1.11.6
FLINK_BIG_VERSION: 1.11
- FLINK_VERSION: 1.12.7
FLINK_BIG_VERSION: 1.12
- FLINK_VERSION: 1.13.6
FLINK_BIG_VERSION: 1.13
- FLINK_VERSION: 1.14.6
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.dinky</groupId>
<artifactId>dinky-app</artifactId>
<version>0.8.0</version>
</parent>
<artifactId>dinky-app-1.12</artifactId>
<packaging>jar</packaging>
<name>Dinky : App 1.12</name>
<properties>
<mainClass>org.dinky.app.MainApp</mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-app-base</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-client-1.12</artifactId>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-flink-1.12</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-client-base</artifactId>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-executor</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 可以设置jar包的入口类(可选) -->
<mainClass>org.dinky.app.MainApp</mainClass>
</manifest>
</archive>
<outputDirectory>${project.parent.parent.basedir}/build/extends</outputDirectory>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
*
* 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.app;
import org.dinky.app.db.DBConfig;
import org.dinky.app.flinksql.Submitter;
import org.dinky.assertion.Asserts;
import org.dinky.constant.FlinkParamConstant;
import org.dinky.utils.FlinkBaseUtil;
import java.io.IOException;
import java.util.Map;
/**
* MainApp
*
* @since 2021/10/27
*/
public class MainApp {
public static void main(String[] args) throws IOException {
Map<String, String> params = FlinkBaseUtil.getParamsFromArgs(args);
String id = params.get(FlinkParamConstant.ID);
Asserts.checkNullString(id, "请配置入参 id ");
DBConfig dbConfig = DBConfig.build(params);
Submitter.submit(Integer.valueOf(id), dbConfig, params.get(FlinkParamConstant.DINKY_ADDR));
}
}
......@@ -64,17 +64,6 @@
<profile>
<id>flink-all</id>
<dependencies>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-client-1.12</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-flink-1.12</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-client-1.13</artifactId>
......
......@@ -26,7 +26,6 @@
<profile>
<id>flink-all</id>
<modules>
<module>dinky-app-1.12</module>
<module>dinky-app-1.13</module>
<module>dinky-app-1.14</module>
<module>dinky-app-1.15</module>
......
......@@ -58,22 +58,6 @@
<include>upgrade/*/*/*.sql</include>
</includes>
</fileSet>
<!--<fileSet>-->
<!-- <directory>${project.parent.basedir}/build/extends/</directory>-->
<!-- <outputDirectory>plugins</outputDirectory>-->
<!-- <includes>-->
<!-- <include>%regex[dinky-catalog-mysql-1.\d+-${project.version}.jar]</include>-->
<!-- <include>%regex[dinky-client-1.\d+-${project.version}.jar]</include>-->
<!-- </includes>-->
<!--</fileSet>-->
<fileSet>
<directory>${project.parent.basedir}/build/extends/</directory>
<outputDirectory>plugins/flink1.12</outputDirectory>
<includes>
<include>dinky-client-1.12-${project.version}.jar</include>
<include>dinky-connector-jdbc-1.12-${project.version}.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/build/extends/</directory>
<outputDirectory>plugins/flink1.13</outputDirectory>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.dinky</groupId>
<artifactId>dinky-client</artifactId>
<version>0.8.0</version>
</parent>
<artifactId>dinky-client-1.12</artifactId>
<packaging>jar</packaging>
<name>Dinky : Client 1.12</name>
<dependencies>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-client-base</artifactId>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-common</artifactId>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-flink-1.12</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- 指定打包的jar包输出路径 -->
<outputDirectory>${project.parent.parent.basedir}/build/extends</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
/*
*
* 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.apache.flink.client.python;
import static org.apache.flink.client.python.PythonEnvUtils.getGatewayServer;
import static org.apache.flink.client.python.PythonEnvUtils.launchPy4jPythonClient;
import static org.apache.flink.client.python.PythonEnvUtils.setGatewayServer;
import static org.apache.flink.client.python.PythonEnvUtils.startGatewayServer;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.python.shaded.py4j.GatewayServer;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.python.util.PythonDependencyUtils;
import org.apache.flink.table.functions.python.PythonFunction;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
/** The factory which creates the PythonFunction objects from given module name and object name. */
public interface PythonFunctionFactory {
long CHECK_INTERVAL = 100;
long TIMEOUT_MILLIS = 10000;
AtomicReference<PythonFunctionFactory> PYTHON_FUNCTION_FACTORY_REF = new AtomicReference<>();
/**
* Returns PythonFunction according to moduleName and objectName.
*
* @param moduleName The module name of the Python UDF.
* @param objectName The function name / class name of the Python UDF.
* @return The PythonFunction object which represents the Python UDF.
*/
PythonFunction getPythonFunction(String moduleName, String objectName);
/**
* Returns PythonFunction according to the fully qualified name of the Python UDF i.e
* ${moduleName}.${functionName} or ${moduleName}.${className}.
*
* @param fullyQualifiedName The fully qualified name of the Python UDF.
* @param config The configuration of python dependencies.
* @return The PythonFunction object which represents the Python UDF.
*/
static PythonFunction getPythonFunction(String fullyQualifiedName, ReadableConfig config)
throws IOException, ExecutionException, InterruptedException {
int splitIndex = fullyQualifiedName.lastIndexOf(".");
if (splitIndex <= 0) {
throw new IllegalArgumentException(
String.format("The fully qualified name is invalid: '%s'", fullyQualifiedName));
}
String moduleName = fullyQualifiedName.substring(0, splitIndex);
String objectName = fullyQualifiedName.substring(splitIndex + 1);
Configuration mergedConfig =
new Configuration(
ExecutionEnvironment.getExecutionEnvironment().getConfiguration());
PythonDependencyUtils.merge(mergedConfig, (Configuration) config);
PythonFunctionFactory pythonFunctionFactory = getPythonFunctionFactory(mergedConfig);
return pythonFunctionFactory.getPythonFunction(moduleName, objectName);
}
static PythonFunction getPythonFunction(
String fullyQualifiedName, ReadableConfig config, ClassLoader classLoader)
throws ExecutionException, IOException, InterruptedException {
return getPythonFunction(fullyQualifiedName, config);
}
static PythonFunctionFactory getPythonFunctionFactory(ReadableConfig config)
throws ExecutionException, InterruptedException, IOException {
synchronized (PythonFunctionFactory.class) {
if (PYTHON_FUNCTION_FACTORY_REF.get() != null) {
return PYTHON_FUNCTION_FACTORY_REF.get();
} else {
Map<String, Object> entryPoint;
if (getGatewayServer() == null) {
GatewayServer gatewayServer = null;
Process pythonProcess = null;
try {
gatewayServer = startGatewayServer();
setGatewayServer(gatewayServer);
List<String> commands = new ArrayList<>();
commands.add("-m");
commands.add("pyflink.pyflink_callback_server");
String tmpDir =
System.getProperty("java.io.tmpdir")
+ File.separator
+ "pyflink"
+ File.separator
+ UUID.randomUUID();
pythonProcess =
launchPy4jPythonClient(
gatewayServer, config, commands, null, tmpDir, false);
entryPoint =
(Map<String, Object>) gatewayServer.getGateway().getEntryPoint();
int i = 0;
while (!entryPoint.containsKey("PythonFunctionFactory")) {
if (!pythonProcess.isAlive()) {
throw new RuntimeException("Python callback server start failed!");
}
try {
Thread.sleep(CHECK_INTERVAL);
} catch (InterruptedException e) {
throw new RuntimeException(
"Interrupted while waiting for the python process to start.",
e);
}
i++;
if (i > TIMEOUT_MILLIS / CHECK_INTERVAL) {
throw new RuntimeException("Python callback server start failed!");
}
}
} catch (Throwable e) {
try {
setGatewayServer(null);
if (gatewayServer != null) {
gatewayServer.shutdown();
}
} catch (Throwable e2) {
// ignore, do not swallow the origin exception.
}
try {
if (pythonProcess != null) {
shutdownPythonProcess(pythonProcess, TIMEOUT_MILLIS);
}
} catch (Throwable e3) {
// ignore, do not swallow the origin exception.
}
throw e;
}
Runtime.getRuntime()
.addShutdownHook(new PythonProcessShutdownHook(pythonProcess));
} else {
entryPoint =
(Map<String, Object>) getGatewayServer().getGateway().getEntryPoint();
}
PythonFunctionFactory pythonFunctionFactory =
(PythonFunctionFactory) entryPoint.get("PythonFunctionFactory");
PYTHON_FUNCTION_FACTORY_REF.set(pythonFunctionFactory);
return pythonFunctionFactory;
}
}
}
static void shutdownPythonProcess(Process pythonProcess, long timeoutMillis) {
pythonProcess.destroy();
try {
pythonProcess.waitFor(timeoutMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(
"Interrupt while waiting for the python process to stop.", e);
}
if (pythonProcess.isAlive()) {
pythonProcess.destroyForcibly();
}
}
/** The shutdown hook used to destroy the Python process. */
class PythonProcessShutdownHook extends Thread {
private Process process;
public PythonProcessShutdownHook(Process process) {
this.process = process;
}
@Override
public void run() {
shutdownPythonProcess(process, TIMEOUT_MILLIS);
}
}
}
/*
*
* 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.cdc;
import org.dinky.assertion.Asserts;
import org.dinky.constant.FlinkParamConstant;
import org.dinky.model.FlinkCDCConfig;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* AbstractCDCBuilder
*
* @since 2022/4/12 21:28
*/
public abstract class AbstractCDCBuilder {
protected FlinkCDCConfig config;
public AbstractCDCBuilder() {}
public AbstractCDCBuilder(FlinkCDCConfig config) {
this.config = config;
}
public FlinkCDCConfig getConfig() {
return config;
}
public void setConfig(FlinkCDCConfig config) {
this.config = config;
}
public List<String> getSchemaList() {
List<String> schemaList = new ArrayList<>();
String schema = getSchema();
if (Asserts.isNotNullString(schema)) {
String[] schemas = schema.split(FlinkParamConstant.SPLIT);
Collections.addAll(schemaList, schemas);
}
List<String> tableList = getTableList();
for (String tableName : tableList) {
tableName = tableName.trim();
if (Asserts.isNotNullString(tableName) && tableName.contains(".")) {
String[] names = tableName.split("\\\\.");
if (!schemaList.contains(names[0])) {
schemaList.add(names[0]);
}
}
}
return schemaList;
}
public List<String> getTableList() {
List<String> tableList = new ArrayList<>();
String table = config.getTable();
if (Asserts.isNullString(table)) {
return tableList;
}
String[] tables = table.split(FlinkParamConstant.SPLIT);
Collections.addAll(tableList, tables);
return tableList;
}
public String getSchemaFieldName() {
return "schema";
}
public abstract String getSchema();
}
/*
*
* 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.cdc;
import org.dinky.exception.SplitTableException;
import org.dinky.model.FlinkCDCConfig;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import java.util.List;
import java.util.Map;
/**
* CDCBuilder
*
* @since 2022/4/12 21:09
*/
public interface CDCBuilder {
String getHandle();
CDCBuilder create(FlinkCDCConfig config);
DataStreamSource<String> build(StreamExecutionEnvironment env);
List<String> getSchemaList();
List<String> getTableList();
Map<String, Map<String, String>> parseMetaDataConfigs();
String getSchemaFieldName();
default Map<String, String> parseMetaDataConfig() {
throw new SplitTableException("此数据源并未实现分库分表");
}
}
/*
*
* 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.cdc;
import org.dinky.assertion.Asserts;
import org.dinky.cdc.mysql.MysqlCDCBuilder;
import org.dinky.exception.FlinkClientException;
import org.dinky.model.FlinkCDCConfig;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
/**
* CDCBuilderFactory
*
* @since 2022/4/12 21:12
*/
public class CDCBuilderFactory {
private static final Map<String, Supplier<CDCBuilder>> CDC_BUILDER_MAP =
new HashMap<String, Supplier<CDCBuilder>>() {
{
put(MysqlCDCBuilder.KEY_WORD, () -> new MysqlCDCBuilder());
}
};
public static CDCBuilder buildCDCBuilder(FlinkCDCConfig config) {
if (Asserts.isNull(config) || Asserts.isNullString(config.getType())) {
throw new FlinkClientException("请指定 CDC Source 类型。");
}
return CDC_BUILDER_MAP
.getOrDefault(
config.getType(),
() -> {
throw new FlinkClientException(
"未匹配到对应 CDC Source 类型的【" + config.getType() + "】。");
})
.get()
.create(config);
}
}
/*
*
* 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.cdc;
import org.dinky.executor.CustomTableEnvironment;
import org.dinky.model.FlinkCDCConfig;
import org.dinky.model.Table;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
/**
* SinkBuilder
*
* @since 2022/4/12 21:09
*/
public interface SinkBuilder {
String getHandle();
SinkBuilder create(FlinkCDCConfig config);
DataStreamSource build(
CDCBuilder cdcBuilder,
StreamExecutionEnvironment env,
CustomTableEnvironment customTableEnvironment,
DataStreamSource<String> dataStreamSource);
String getSinkSchemaName(Table table);
String getSinkTableName(Table table);
}
/*
*
* 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.cdc;
import org.dinky.assertion.Asserts;
import org.dinky.cdc.doris.DorisSinkBuilder;
import org.dinky.cdc.kafka.KafkaSinkBuilder;
import org.dinky.cdc.sql.SQLSinkBuilder;
import org.dinky.exception.FlinkClientException;
import org.dinky.model.FlinkCDCConfig;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
/**
* SinkBuilderFactory
*
* @since 2022/4/12 21:12
*/
public class SinkBuilderFactory {
private static final Map<String, Supplier<SinkBuilder>> SINK_BUILDER_MAP =
new HashMap<String, Supplier<SinkBuilder>>() {
{
put(KafkaSinkBuilder.KEY_WORD, () -> new KafkaSinkBuilder());
put(DorisSinkBuilder.KEY_WORD, () -> new DorisSinkBuilder());
put(SQLSinkBuilder.KEY_WORD, () -> new SQLSinkBuilder());
}
};
public static SinkBuilder buildSinkBuilder(FlinkCDCConfig config) {
if (Asserts.isNull(config) || Asserts.isNullString(config.getSink().get("connector"))) {
throw new FlinkClientException("请指定 Sink connector。");
}
return SINK_BUILDER_MAP
.getOrDefault(config.getSink().get("connector"), () -> new SQLSinkBuilder())
.get()
.create(config);
}
}
/*
*
* 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.cdc.doris;
import org.dinky.assertion.Asserts;
import org.dinky.cdc.AbstractSinkBuilder;
import org.dinky.cdc.SinkBuilder;
import org.dinky.model.FlinkCDCConfig;
import org.dinky.model.Table;
import org.apache.doris.flink.cfg.DorisExecutionOptions;
import org.apache.doris.flink.cfg.DorisOptions;
import org.apache.doris.flink.cfg.DorisReadOptions;
import org.apache.doris.flink.cfg.DorisSink;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.types.logical.LogicalType;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* DorisSinkBuilder
*
* @since 2022/4/20 19:20
*/
public class DorisSinkBuilder extends AbstractSinkBuilder implements Serializable {
public static final String KEY_WORD = "datastream-doris";
private static final long serialVersionUID = 8330362249137471854L;
public DorisSinkBuilder() {}
public DorisSinkBuilder(FlinkCDCConfig config) {
super(config);
}
@Override
public String getHandle() {
return KEY_WORD;
}
@Override
public SinkBuilder create(FlinkCDCConfig config) {
return new DorisSinkBuilder(config);
}
@Override
public void addSink(
StreamExecutionEnvironment env,
DataStream<RowData> rowDataDataStream,
Table table,
List<String> columnNameList,
List<LogicalType> columnTypeList) {
DorisExecutionOptions.Builder dorisExecutionOptionsBuilder =
DorisExecutionOptions.builder();
Map<String, String> sink = config.getSink();
if (sink.containsKey("sink.batch.size")) {
dorisExecutionOptionsBuilder.setBatchSize(Integer.valueOf(sink.get("sink.batch.size")));
}
if (sink.containsKey("sink.batch.interval")) {
dorisExecutionOptionsBuilder.setBatchIntervalMs(
Long.valueOf(sink.get("sink.batch.interval")));
}
if (sink.containsKey("sink.max-retries")) {
dorisExecutionOptionsBuilder.setMaxRetries(
Integer.valueOf(sink.get("sink.max-retries")));
}
if (sink.containsKey("sink.enable-delete")) {
dorisExecutionOptionsBuilder.setEnableDelete(
Boolean.valueOf(sink.get("sink.enable-delete")));
}
dorisExecutionOptionsBuilder.setStreamLoadProp(getProperties());
final String[] columnNames = columnNameList.toArray(new String[columnNameList.size()]);
final LogicalType[] columnTypes =
columnTypeList.toArray(new LogicalType[columnTypeList.size()]);
rowDataDataStream.addSink(
DorisSink.sink(
columnNames,
columnTypes,
DorisReadOptions.builder().build(),
dorisExecutionOptionsBuilder.build(),
DorisOptions.builder()
.setFenodes(config.getSink().get("fenodes"))
.setTableIdentifier(
getSinkSchemaName(table) + "." + getSinkTableName(table))
.setUsername(config.getSink().get("username"))
.setPassword(config.getSink().get("password"))
.build()));
}
@Override
protected Properties getProperties() {
Properties properties = new Properties();
Map<String, String> sink = config.getSink();
for (Map.Entry<String, String> entry : sink.entrySet()) {
if (Asserts.isNotNullString(entry.getKey())
&& entry.getKey().startsWith("sink.properties")
&& Asserts.isNotNullString(entry.getValue())) {
properties.setProperty(
entry.getKey().replace("sink.properties.", ""), entry.getValue());
}
}
return properties;
}
}
/*
*
* 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.cdc.kafka;
import org.dinky.assertion.Asserts;
import org.dinky.cdc.AbstractSinkBuilder;
import org.dinky.cdc.CDCBuilder;
import org.dinky.cdc.SinkBuilder;
import org.dinky.executor.CustomTableEnvironment;
import org.dinky.model.FlinkCDCConfig;
import org.dinky.model.Schema;
import org.dinky.model.Table;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.types.logical.LogicalType;
import org.apache.flink.util.Collector;
import org.apache.flink.util.NetUtils;
import org.apache.flink.util.OutputTag;
import org.apache.kafka.clients.producer.ProducerConfig;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* MysqlCDCBuilder
*
* @since 2022/4/12 21:29
*/
public class KafkaSinkBuilder extends AbstractSinkBuilder implements SinkBuilder, Serializable {
public static final String KEY_WORD = "datastream-kafka";
public KafkaSinkBuilder() {}
public KafkaSinkBuilder(FlinkCDCConfig config) {
super(config);
}
@Override
public void addSink(
StreamExecutionEnvironment env,
DataStream<RowData> rowDataDataStream,
Table table,
List<String> columnNameList,
List<LogicalType> columnTypeList) {}
@Override
public String getHandle() {
return KEY_WORD;
}
@Override
public SinkBuilder create(FlinkCDCConfig config) {
return new KafkaSinkBuilder(config);
}
@Override
public DataStreamSource build(
CDCBuilder cdcBuilder,
StreamExecutionEnvironment env,
CustomTableEnvironment customTableEnvironment,
DataStreamSource<String> dataStreamSource) {
Properties kafkaProducerConfig = getProperties();
getPropertiesFromBrokerList(kafkaProducerConfig, config.getSink().get("brokers"));
if (Asserts.isNotNullString(config.getSink().get("topic"))) {
dataStreamSource.addSink(
new FlinkKafkaProducer<>(
config.getSink().get("topic"),
new SimpleStringSchema(),
kafkaProducerConfig));
} else {
Map<Table, OutputTag<String>> tagMap = new HashMap<>();
Map<String, Table> tableMap = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();
SingleOutputStreamOperator<Map> mapOperator =
dataStreamSource
.map(x -> objectMapper.readValue(x, Map.class))
.returns(Map.class);
final List<Schema> schemaList = config.getSchemaList();
final String schemaFieldName = config.getSchemaFieldName();
if (Asserts.isNotNullCollection(schemaList)) {
for (Schema schema : schemaList) {
for (Table table : schema.getTables()) {
String sinkTableName = getSinkTableName(table);
OutputTag<String> outputTag = new OutputTag<String>(sinkTableName) {};
tagMap.put(table, outputTag);
tableMap.put(table.getSchemaTableName(), table);
}
}
SingleOutputStreamOperator<String> process =
mapOperator.process(
new ProcessFunction<Map, String>() {
@Override
public void processElement(
Map map,
ProcessFunction<Map, String>.Context ctx,
Collector<String> out)
throws Exception {
LinkedHashMap source = (LinkedHashMap) map.get("source");
try {
String result = objectMapper.writeValueAsString(map);
Table table =
tableMap.get(
source.get(schemaFieldName).toString()
+ "."
+ source.get("table")
.toString());
OutputTag<String> outputTag = tagMap.get(table);
ctx.output(outputTag, result);
} catch (Exception e) {
out.collect(objectMapper.writeValueAsString(map));
}
}
});
tagMap.forEach(
(k, v) -> {
String topic = getSinkTableName(k);
process.getSideOutput(v)
.rebalance()
.addSink(
new FlinkKafkaProducer<>(
topic,
new SimpleStringSchema(),
kafkaProducerConfig))
.name(topic);
});
}
}
return dataStreamSource;
}
private void getPropertiesFromBrokerList(Properties props, String brokerList) {
String[] elements = brokerList.split(",");
// validate the broker addresses
for (String broker : elements) {
NetUtils.getCorrectHostnamePort(broker);
}
props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
}
}
/*
*
* 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.cdc.mysql;
import org.dinky.assertion.Asserts;
import org.dinky.cdc.AbstractCDCBuilder;
import org.dinky.cdc.CDCBuilder;
import org.dinky.constant.ClientConstant;
import org.dinky.constant.FlinkParamConstant;
import org.dinky.model.FlinkCDCConfig;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;
import com.alibaba.ververica.cdc.connectors.mysql.table.StartupOptions;
/**
* MysqlCDCBuilder
*
* @since 2022/4/12 21:29
*/
public class MysqlCDCBuilder extends AbstractCDCBuilder implements CDCBuilder {
public static final String KEY_WORD = "mysql-cdc";
private static final String METADATA_TYPE = "MySql";
public MysqlCDCBuilder() {}
public MysqlCDCBuilder(FlinkCDCConfig config) {
super(config);
}
@Override
public String getHandle() {
return KEY_WORD;
}
@Override
public CDCBuilder create(FlinkCDCConfig config) {
return new MysqlCDCBuilder(config);
}
@Override
public DataStreamSource<String> build(StreamExecutionEnvironment env) {
Properties properties = new Properties();
for (Map.Entry<String, String> entry : config.getDebezium().entrySet()) {
if (Asserts.isNotNullString(entry.getKey())
&& Asserts.isNotNullString(entry.getValue())) {
properties.setProperty(entry.getKey(), entry.getValue());
}
}
MySQLSource.Builder<String> sourceBuilder =
MySQLSource.<String>builder()
.hostname(config.getHostname())
.port(config.getPort())
.username(config.getUsername())
.password(config.getPassword());
String database = config.getDatabase();
if (Asserts.isNotNullString(database)) {
String[] databases = database.split(FlinkParamConstant.SPLIT);
sourceBuilder.databaseList(databases);
} else {
sourceBuilder.databaseList(new String[0]);
}
List<String> schemaTableNameList = config.getSchemaTableNameList();
if (Asserts.isNotNullCollection(schemaTableNameList)) {
sourceBuilder.tableList(
schemaTableNameList.toArray(new String[schemaTableNameList.size()]));
} else {
sourceBuilder.tableList(new String[0]);
}
sourceBuilder.deserializer(new MysqlJsonDebeziumDeserializationSchema());
sourceBuilder.debeziumProperties(properties);
if (Asserts.isNotNullString(config.getStartupMode())) {
switch (config.getStartupMode().toLowerCase()) {
case "initial":
sourceBuilder.startupOptions(StartupOptions.initial());
break;
case "latest-offset":
sourceBuilder.startupOptions(StartupOptions.latest());
break;
default:
}
} else {
sourceBuilder.startupOptions(StartupOptions.latest());
}
return env.addSource(sourceBuilder.build(), "MySQL CDC Source");
}
public Map<String, Map<String, String>> parseMetaDataConfigs() {
Map<String, Map<String, String>> allConfigMap = new HashMap<>();
List<String> schemaList = getSchemaList();
for (String schema : schemaList) {
Map<String, String> configMap = new HashMap<>();
configMap.put(ClientConstant.METADATA_TYPE, METADATA_TYPE);
StringBuilder sb = new StringBuilder("jdbc:mysql://");
sb.append(config.getHostname());
sb.append(":");
sb.append(config.getPort());
sb.append("/");
sb.append(schema);
configMap.put(ClientConstant.METADATA_NAME, sb.toString());
configMap.put(ClientConstant.METADATA_URL, sb.toString());
configMap.put(ClientConstant.METADATA_USERNAME, config.getUsername());
configMap.put(ClientConstant.METADATA_PASSWORD, config.getPassword());
allConfigMap.put(schema, configMap);
}
return allConfigMap;
}
@Override
public String getSchema() {
return config.getDatabase();
}
}
/*
*
* 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.cdc.mysql;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.util.Collector;
import org.apache.kafka.connect.json.JsonConverter;
import org.apache.kafka.connect.source.SourceRecord;
import org.apache.kafka.connect.storage.ConverterType;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.ververica.cdc.debezium.DebeziumDeserializationSchema;
/**
* @version 1.0
* @className: org.dinky.cdc.mysql.MysqlJsonDebeziumDeserializationSchema @Description:
*/
public class MysqlJsonDebeziumDeserializationSchema
implements DebeziumDeserializationSchema<String> {
private static final long serialVersionUID = 1L;
private transient JsonConverter jsonConverter;
private final Boolean includeSchema;
private Map<String, Object> customConverterConfigs;
public MysqlJsonDebeziumDeserializationSchema() {
this(false);
}
public MysqlJsonDebeziumDeserializationSchema(Boolean includeSchema) {
this.includeSchema = includeSchema;
}
public MysqlJsonDebeziumDeserializationSchema(
Boolean includeSchema, Map<String, Object> customConverterConfigs) {
this.includeSchema = includeSchema;
this.customConverterConfigs = customConverterConfigs;
}
public void deserialize(SourceRecord record, Collector<String> out) throws Exception {
if (this.jsonConverter == null) {
this.initializeJsonConverter();
}
byte[] bytes =
this.jsonConverter.fromConnectData(
record.topic(), record.valueSchema(), record.value());
out.collect(new String(bytes, StandardCharsets.UTF_8));
}
private void initializeJsonConverter() {
this.jsonConverter = new JsonConverter();
HashMap<String, Object> configs = new HashMap(2);
configs.put("converter.type", ConverterType.VALUE.getName());
configs.put("schemas.enable", this.includeSchema);
if (this.customConverterConfigs != null) {
configs.putAll(this.customConverterConfigs);
}
this.jsonConverter.configure(configs);
}
public TypeInformation<String> getProducedType() {
return BasicTypeInfo.STRING_TYPE_INFO;
}
}
/*
*
* 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.executor;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
import org.apache.flink.table.delegation.Executor;
import org.apache.flink.table.delegation.Planner;
/** */
public abstract class AbstractCustomTableEnvironment
implements CustomTableEnvironment,
DefaultTableEnvironmentInternal,
DefaultStreamTableEnvironment {
protected StreamTableEnvironment streamTableEnvironment;
protected Executor executor;
protected AbstractCustomTableEnvironment() {}
protected AbstractCustomTableEnvironment(StreamTableEnvironment streamTableEnvironment) {
this.streamTableEnvironment = streamTableEnvironment;
}
@Override
public TableEnvironment getTableEnvironment() {
return streamTableEnvironment;
}
public StreamExecutionEnvironment getStreamExecutionEnvironment() {
return ((StreamTableEnvironmentImpl) streamTableEnvironment).execEnv();
}
public Planner getPlanner() {
return ((StreamTableEnvironmentImpl) streamTableEnvironment).getPlanner();
}
}
/*
*
* 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.executor;
import org.apache.flink.api.common.JobExecutionResult;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.descriptors.ConnectorDescriptor;
import org.apache.flink.table.descriptors.StreamTableDescriptor;
import org.apache.flink.table.expressions.Expression;
import org.apache.flink.table.functions.AggregateFunction;
import org.apache.flink.table.functions.TableAggregateFunction;
import org.apache.flink.table.functions.TableFunction;
/** */
public interface DefaultStreamTableEnvironment
extends StreamTableEnvironment, DefaultTableEnvironment, TableEnvironmentInstance {
default StreamTableEnvironment getStreamTableEnvironment() {
return (StreamTableEnvironment) getTableEnvironment();
}
@Override // region StreamTableEnvironment interface
default <T> void registerFunction(String s, TableFunction<T> tableFunction) {
getStreamTableEnvironment().registerFunction(s, tableFunction);
}
@Override
default <T, A> void registerFunction(String s, AggregateFunction<T, A> aggregateFunction) {
getStreamTableEnvironment().registerFunction(s, aggregateFunction);
}
@Override
default <T, A> void registerFunction(
String s, TableAggregateFunction<T, A> tableAggregateFunction) {
getStreamTableEnvironment().registerFunction(s, tableAggregateFunction);
}
@Override
default <T> Table fromDataStream(DataStream<T> dataStream) {
return getStreamTableEnvironment().fromDataStream(dataStream);
}
@Override
default <T> void createTemporaryView(String s, DataStream<T> dataStream) {
getStreamTableEnvironment().createTemporaryView(s, dataStream);
}
@Override
default <T> Table fromDataStream(DataStream<T> dataStream, String s) {
return getStreamTableEnvironment().fromDataStream(dataStream, s);
}
@Override
default <T> Table fromDataStream(DataStream<T> dataStream, Expression... expressions) {
return getStreamTableEnvironment().fromDataStream(dataStream, expressions);
}
@Override
default <T> void registerDataStream(String s, DataStream<T> dataStream) {
getStreamTableEnvironment().registerDataStream(s, dataStream);
}
@Override
default <T> void registerDataStream(String s, DataStream<T> dataStream, String s1) {
getStreamTableEnvironment().registerDataStream(s, dataStream, s1);
}
@Override
default <T> void createTemporaryView(String s, DataStream<T> dataStream, String s1) {
getStreamTableEnvironment().createTemporaryView(s, dataStream, s1);
}
@Override
default <T> void createTemporaryView(
String s, DataStream<T> dataStream, Expression... expressions) {
getStreamTableEnvironment().createTemporaryView(s, dataStream, expressions);
}
@Override
default <T> DataStream<T> toAppendStream(Table table, Class<T> aClass) {
return getStreamTableEnvironment().toAppendStream(table, aClass);
}
@Override
default <T> DataStream<T> toAppendStream(Table table, TypeInformation<T> typeInformation) {
return getStreamTableEnvironment().toAppendStream(table, typeInformation);
}
@Override
default <T> DataStream<Tuple2<Boolean, T>> toRetractStream(Table table, Class<T> aClass) {
return getStreamTableEnvironment().toRetractStream(table, aClass);
}
@Override
default <T> DataStream<Tuple2<Boolean, T>> toRetractStream(
Table table, TypeInformation<T> typeInformation) {
return getStreamTableEnvironment().toRetractStream(table, typeInformation);
}
@Override
default JobExecutionResult execute(String s) throws Exception {
return getStreamTableEnvironment().execute(s);
}
@Override
default StreamTableDescriptor connect(ConnectorDescriptor connectorDescriptor) {
return getStreamTableEnvironment().connect(connectorDescriptor);
}
// endregion
}
/*
*
* 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.executor;
import org.apache.flink.api.common.JobExecutionResult;
import org.apache.flink.table.api.ExplainDetail;
import org.apache.flink.table.api.StatementSet;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableConfig;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.TableResult;
import org.apache.flink.table.catalog.Catalog;
import org.apache.flink.table.descriptors.ConnectTableDescriptor;
import org.apache.flink.table.descriptors.ConnectorDescriptor;
import org.apache.flink.table.expressions.Expression;
import org.apache.flink.table.functions.ScalarFunction;
import org.apache.flink.table.functions.UserDefinedFunction;
import org.apache.flink.table.module.Module;
import org.apache.flink.table.sources.TableSource;
import org.apache.flink.table.types.AbstractDataType;
import java.util.Optional;
/** */
public interface DefaultTableEnvironment extends TableEnvironment, TableEnvironmentInstance {
@Override
default Table fromValues(Expression... expressions) {
return getTableEnvironment().fromValues(expressions);
}
@Override
default Table fromValues(AbstractDataType<?> abstractDataType, Expression... expressions) {
return getTableEnvironment().fromValues(abstractDataType, expressions);
}
@Override
default Table fromValues(Iterable<?> iterable) {
return getTableEnvironment().fromValues(iterable);
}
@Override
default Table fromValues(AbstractDataType<?> abstractDataType, Iterable<?> iterable) {
return getTableEnvironment().fromValues(abstractDataType, iterable);
}
@Override
default Table fromTableSource(TableSource<?> tableSource) {
return getTableEnvironment().fromTableSource(tableSource);
}
@Override
default void registerCatalog(String s, Catalog catalog) {
getTableEnvironment().registerCatalog(s, catalog);
}
@Override
default Optional<Catalog> getCatalog(String s) {
return getTableEnvironment().getCatalog(s);
}
@Override
default void loadModule(String s, Module module) {
getTableEnvironment().loadModule(s, module);
}
@Override
default void unloadModule(String s) {
getTableEnvironment().unloadModule(s);
}
@Override
default void registerFunction(String s, ScalarFunction scalarFunction) {
getTableEnvironment().registerFunction(s, scalarFunction);
}
@Override
default void createTemporarySystemFunction(
String s, Class<? extends UserDefinedFunction> aClass) {
getTableEnvironment().createTemporarySystemFunction(s, aClass);
}
@Override
default void createTemporarySystemFunction(String s, UserDefinedFunction userDefinedFunction) {
getTableEnvironment().createTemporarySystemFunction(s, userDefinedFunction);
}
@Override
default boolean dropTemporarySystemFunction(String s) {
return getTableEnvironment().dropTemporarySystemFunction(s);
}
@Override
default void createFunction(String s, Class<? extends UserDefinedFunction> aClass) {
getTableEnvironment().createFunction(s, aClass);
}
@Override
default void createFunction(String s, Class<? extends UserDefinedFunction> aClass, boolean b) {
getTableEnvironment().createFunction(s, aClass, b);
}
@Override
default boolean dropFunction(String s) {
return getTableEnvironment().dropFunction(s);
}
@Override
default void createTemporaryFunction(String s, Class<? extends UserDefinedFunction> aClass) {
getTableEnvironment().createTemporaryFunction(s, aClass);
}
@Override
default void createTemporaryFunction(String s, UserDefinedFunction userDefinedFunction) {
getTableEnvironment().createTemporaryFunction(s, userDefinedFunction);
}
@Override
default boolean dropTemporaryFunction(String s) {
return getTableEnvironment().dropTemporaryFunction(s);
}
@Override
default void registerTable(String s, Table table) {
getTableEnvironment().registerTable(s, table);
}
@Override
default void createTemporaryView(String s, Table table) {
getTableEnvironment().createTemporaryView(s, table);
}
@Override
default Table scan(String... strings) {
return getTableEnvironment().scan();
}
@Override
default Table from(String s) {
return getTableEnvironment().from(s);
}
@Override
default void insertInto(Table table, String s, String... strings) {
getTableEnvironment().insertInto(table, s, strings);
}
@Override
default void insertInto(String s, Table table) {
getTableEnvironment().insertInto(s, table);
}
@Override
default String[] listCatalogs() {
return getTableEnvironment().listCatalogs();
}
@Override
default String[] listModules() {
return getTableEnvironment().listModules();
}
@Override
default String[] listDatabases() {
return getTableEnvironment().listDatabases();
}
@Override
default String[] listTables() {
return getTableEnvironment().listTables();
}
@Override
default String[] listViews() {
return getTableEnvironment().listViews();
}
@Override
default String[] listTemporaryTables() {
return getTableEnvironment().listTemporaryTables();
}
@Override
default String[] listTemporaryViews() {
return getTableEnvironment().listTemporaryViews();
}
@Override
default String[] listUserDefinedFunctions() {
return getTableEnvironment().listUserDefinedFunctions();
}
@Override
default String[] listFunctions() {
return getTableEnvironment().listFunctions();
}
@Override
default boolean dropTemporaryTable(String s) {
return getTableEnvironment().dropTemporaryTable(s);
}
@Override
default boolean dropTemporaryView(String s) {
return getTableEnvironment().dropTemporaryView(s);
}
@Override
default String explain(Table table) {
return getTableEnvironment().explain(table);
}
@Override
default String explain(Table table, boolean b) {
return getTableEnvironment().explain(table, b);
}
@Override
default String explain(boolean b) {
return getTableEnvironment().explain(b);
}
@Override
default String explainSql(String s, ExplainDetail... explainDetails) {
return getTableEnvironment().explainSql(s, explainDetails);
}
@Override
default String[] getCompletionHints(String s, int i) {
return getTableEnvironment().getCompletionHints(s, i);
}
@Override
default Table sqlQuery(String s) {
return getTableEnvironment().sqlQuery(s);
}
@Override
default TableResult executeSql(String s) {
return getTableEnvironment().executeSql(s);
}
@Override
default void sqlUpdate(String s) {
getTableEnvironment().sqlUpdate(s);
}
@Override
default String getCurrentCatalog() {
return getTableEnvironment().getCurrentCatalog();
}
@Override
default void useCatalog(String s) {
getTableEnvironment().useCatalog(s);
}
@Override
default String getCurrentDatabase() {
return getTableEnvironment().getCurrentDatabase();
}
@Override
default void useDatabase(String s) {
getTableEnvironment().useDatabase(s);
}
@Override
default TableConfig getConfig() {
return getTableEnvironment().getConfig();
}
@Override
default JobExecutionResult execute(String s) throws Exception {
return getTableEnvironment().execute(s);
}
@Override
default StatementSet createStatementSet() {
return getTableEnvironment().createStatementSet();
}
@Override
default ConnectTableDescriptor connect(ConnectorDescriptor connectorDescriptor) {
return getTableEnvironment().connect(connectorDescriptor);
}
}
/*
*
* 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.executor;
import org.apache.flink.table.api.ExplainDetail;
import org.apache.flink.table.api.TableResult;
import org.apache.flink.table.api.internal.TableEnvironmentInternal;
import org.apache.flink.table.catalog.CatalogManager;
import org.apache.flink.table.delegation.Parser;
import org.apache.flink.table.operations.ModifyOperation;
import org.apache.flink.table.operations.Operation;
import org.apache.flink.table.operations.QueryOperation;
import org.apache.flink.table.sinks.TableSink;
import org.apache.flink.table.sources.TableSource;
import java.util.List;
/** */
public interface DefaultTableEnvironmentInternal
extends TableEnvironmentInternal, TableEnvironmentInstance {
default TableEnvironmentInternal getTableEnvironmentInternal() {
return (TableEnvironmentInternal) getTableEnvironment();
}
@Override
default Parser getParser() {
return getTableEnvironmentInternal().getParser();
}
@Override
default CatalogManager getCatalogManager() {
return getTableEnvironmentInternal().getCatalogManager();
}
@Override
default TableResult executeInternal(List<ModifyOperation> list) {
return getTableEnvironmentInternal().executeInternal(list);
}
@Override
default String explainInternal(List<Operation> list, ExplainDetail... explainDetails) {
return getTableEnvironmentInternal().explainInternal(list, explainDetails);
}
@Override
default void registerTableSourceInternal(String s, TableSource<?> tableSource) {
getTableEnvironmentInternal().registerTableSourceInternal(s, tableSource);
}
@Override
default void registerTableSinkInternal(String s, TableSink<?> tableSink) {
getTableEnvironmentInternal().registerTableSinkInternal(s, tableSink);
}
@Override
default TableResult executeInternal(QueryOperation queryOperation) {
return getTableEnvironmentInternal().executeInternal(queryOperation);
}
}
/*
*
* 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.executor;
import org.apache.flink.table.types.DataType;
/** @since 2021/6/7 22:06 */
public class TableSchemaField {
private String name;
private DataType type;
public TableSchemaField(String name, DataType type) {
this.name = name;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public DataType getType() {
return type;
}
public void setType(DataType type) {
this.type = type;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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