Unverified Commit 2382e5c3 authored by Licho's avatar Licho Committed by GitHub

refactor: stochastic modify (#2437)

* refactor: stomach modify * Spotless Apply --------- Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 7092ea3f
...@@ -70,6 +70,7 @@ import java.util.List; ...@@ -70,6 +70,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import java.util.stream.Collectors;
import javax.xml.bind.DatatypeConverter; import javax.xml.bind.DatatypeConverter;
...@@ -239,13 +240,16 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -239,13 +240,16 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
List<Operation> operations = customTableEnvironment.getParser().parse(cdcSqlInsert); List<Operation> operations = customTableEnvironment.getParser().parse(cdcSqlInsert);
logger.info("Create {} FlinkSQL insert into successful...", tableName); logger.info("Create {} FlinkSQL insert into successful...", tableName);
if (operations.isEmpty()) {
return operations;
}
try { try {
if (!operations.isEmpty()) { Operation operation = operations.get(0);
Operation operation = operations.get(0); if (operation instanceof ModifyOperation) {
if (operation instanceof ModifyOperation) { modifyOperations.add((ModifyOperation) operation);
modifyOperations.add((ModifyOperation) operation);
}
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Translate to plan occur exception: {}", e.toString()); logger.error("Translate to plan occur exception: {}", e.toString());
throw e; throw e;
...@@ -445,53 +449,38 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -445,53 +449,38 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
@Override @Override
public String getSinkSchemaName(Table table) { public String getSinkSchemaName(Table table) {
String schemaName = table.getSchema(); return config.getSink().getOrDefault("sink.db", table.getSchema());
if (config.getSink().containsKey("sink.db")) {
schemaName = config.getSink().get("sink.db");
}
return schemaName;
} }
@Override @Override
public String getSinkTableName(Table table) { public String getSinkTableName(Table table) {
String tableName = table.getName(); String tableName = table.getName();
if (config.getSink().containsKey("table.prefix.schema") Map<String, String> sink = config.getSink();
&& (Boolean.parseBoolean(config.getSink().get("table.prefix.schema")))) { if (Boolean.parseBoolean(sink.get("table.prefix.schema"))) {
tableName = table.getSchema() + "_" + tableName; tableName = table.getSchema() + "_" + tableName;
} }
if (config.getSink().containsKey("table.prefix")) { tableName = sink.getOrDefault("table.prefix", "") + tableName + sink.getOrDefault("table.suffix", "");
tableName = config.getSink().get("table.prefix") + tableName;
}
if (config.getSink().containsKey("table.suffix")) {
tableName = tableName + config.getSink().get("table.suffix");
}
if (config.getSink().containsKey("table.lower") if (Boolean.parseBoolean(sink.get("table.lower"))) {
&& (Boolean.parseBoolean(config.getSink().get("table.lower")))) {
tableName = tableName.toLowerCase(); tableName = tableName.toLowerCase();
} }
if (config.getSink().containsKey("table.upper") if (Boolean.parseBoolean(sink.get("table.upper"))) {
&& (Boolean.parseBoolean(config.getSink().get("table.upper")))) {
tableName = tableName.toUpperCase(); tableName = tableName.toUpperCase();
} }
return tableName; return tableName;
} }
protected List<String> getPKList(Table table) { protected List<String> getPKList(Table table) {
List<String> pks = new ArrayList<>();
if (Asserts.isNullCollection(table.getColumns())) { if (Asserts.isNullCollection(table.getColumns())) {
return pks; return new ArrayList<>();
} }
for (Column column : table.getColumns()) { return table.getColumns().stream()
if (column.isKeyFlag()) { .filter(Column::isKeyFlag)
pks.add(column.getName()); .map(Column::getName)
} .collect(Collectors.toList());
}
return pks;
} }
protected ZoneId getSinkTimeZone() { protected ZoneId getSinkTimeZone() {
......
...@@ -28,7 +28,6 @@ import org.dinky.exception.FlinkClientException; ...@@ -28,7 +28,6 @@ import org.dinky.exception.FlinkClientException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader; import java.util.ServiceLoader;
...@@ -64,16 +63,8 @@ public class SinkBuilderFactory { ...@@ -64,16 +63,8 @@ public class SinkBuilderFactory {
final ServiceLoader<SinkBuilder> loader = ServiceLoader.load(SinkBuilder.class); final ServiceLoader<SinkBuilder> loader = ServiceLoader.load(SinkBuilder.class);
final List<SinkBuilder> sinkBuilders = new ArrayList<>(); final List<SinkBuilder> sinkBuilders = new ArrayList<>();
final Iterator<SinkBuilder> factories = loader.iterator(); for (SinkBuilder factory : loader) {
while (factories.hasNext()) { sinkBuilders.add(factory);
try {
final SinkBuilder factory = factories.next();
if (factory != null) {
sinkBuilders.add(factory);
}
} catch (Throwable e) {
logger.warn("Could not load service provider class : {}", e.getMessage());
}
} }
Map<String, Supplier<SinkBuilder>> plusSinkBuilder = sinkBuilders.stream() Map<String, Supplier<SinkBuilder>> plusSinkBuilder = sinkBuilders.stream()
......
...@@ -82,6 +82,7 @@ public class PostgresCDCBuilder extends AbstractCDCBuilder implements CDCBuilder ...@@ -82,6 +82,7 @@ public class PostgresCDCBuilder extends AbstractCDCBuilder implements CDCBuilder
} else { } else {
sourceBuilder.schemaList(); sourceBuilder.schemaList();
} }
List<String> schemaTableNameList = config.getSchemaTableNameList(); List<String> schemaTableNameList = config.getSchemaTableNameList();
if (Asserts.isNotNullCollection(schemaTableNameList)) { if (Asserts.isNotNullCollection(schemaTableNameList)) {
sourceBuilder.tableList(schemaTableNameList.toArray(new String[0])); sourceBuilder.tableList(schemaTableNameList.toArray(new String[0]));
......
...@@ -181,12 +181,13 @@ public abstract class Executor { ...@@ -181,12 +181,13 @@ public abstract class Executor {
if (Asserts.isNotNull(flinkInterceptorResult.getTableResult())) { if (Asserts.isNotNull(flinkInterceptorResult.getTableResult())) {
return flinkInterceptorResult.getTableResult(); return flinkInterceptorResult.getTableResult();
} }
if (!flinkInterceptorResult.isNoExecute()) {
KerberosUtil.authenticate(setConfig); if (flinkInterceptorResult.isNoExecute()) {
return tableEnvironment.executeSql(statement);
} else {
return CustomTableResultImpl.TABLE_RESULT_OK; return CustomTableResultImpl.TABLE_RESULT_OK;
} }
KerberosUtil.authenticate(setConfig);
return tableEnvironment.executeSql(statement);
} }
public void initUDF(String... udfFilePath) { public void initUDF(String... udfFilePath) {
......
...@@ -39,7 +39,7 @@ export default () => { ...@@ -39,7 +39,7 @@ export default () => {
const topics: string[] = []; const topics: string[] = [];
subscriberRef.current.forEach((sub) => topics.push(...sub.topic)); subscriberRef.current.forEach((sub) => topics.push(...sub.topic));
const para = { sessionKey: uuidRef.current, topics: topics }; const para = { sessionKey: uuidRef.current, topics: topics };
await postAll('api/sse/subscribeTopic', para).catch(e=>ErrorMessage(e)) await postAll('api/sse/subscribeTopic', para).catch((e) => ErrorMessage(e));
}; };
const reconnectSse = () => { const reconnectSse = () => {
...@@ -54,7 +54,7 @@ export default () => { ...@@ -54,7 +54,7 @@ export default () => {
useEffect(() => { useEffect(() => {
if (eventSource) { if (eventSource) {
eventSource.onopen = () => setTimeout(()=>subscribe(),1000); eventSource.onopen = () => setTimeout(() => subscribe(), 1000);
eventSource.onmessage = (e) => { eventSource.onmessage = (e) => {
try { try {
const data: SseData = JSON.parse(e.data); const data: SseData = JSON.parse(e.data);
......
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