Unverified Commit 9b7e8b4e authored by Licho's avatar Licho Committed by GitHub

feat: could watch table view (#1810)

* feat: could watch table view * feat: assume watch is insert sql * refactor: add CTAS sqlTYpe * feat:add CTAS table * refactor: remove redundance * Spotless Apply --------- Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent ac84664a
...@@ -130,14 +130,10 @@ public class Explainer { ...@@ -130,14 +130,10 @@ public class Explainer {
WatchStatementExplainer watchStatementExplainer = WatchStatementExplainer watchStatementExplainer =
new WatchStatementExplainer(statement); new WatchStatementExplainer(statement);
String tableName = watchStatementExplainer.getTableName(); String tableName = watchStatementExplainer.getTableName();
ddl.add(
new StatementParam(
watchStatementExplainer.getCreateStatement(tableName),
SqlType.CREATE));
trans.add( trans.add(
new StatementParam( new StatementParam(
watchStatementExplainer.getInsertStatement(tableName), watchStatementExplainer.getCreateStatement(tableName),
SqlType.INSERT)); SqlType.CTAS));
} else { } else {
UDF udf = UDFUtil.toUDF(statement); UDF udf = UDFUtil.toUDF(statement);
if (Asserts.isNotNull(udf)) { if (Asserts.isNotNull(udf)) {
......
...@@ -34,8 +34,7 @@ public class WatchStatementExplainer { ...@@ -34,8 +34,7 @@ public class WatchStatementExplainer {
public static final String CREATE_SQL_TEMPLATE = public static final String CREATE_SQL_TEMPLATE =
"CREATE TABLE print_{0} WITH (''connector'' = ''printnet'', " "CREATE TABLE print_{0} WITH (''connector'' = ''printnet'', "
+ "''port''=''{2,number,#}'', ''hostName'' = ''{1}'', ''sink.parallelism''=''{3}'')\n" + "''port''=''{2,number,#}'', ''hostName'' = ''{1}'', ''sink.parallelism''=''{3}'')\n"
+ "LIKE {0};"; + "AS SELECT * FROM {0}";
public static final String INSERT_SQL_TEMPLATE = "insert into print_{0} select * from {0};";
public static final int PORT = 7125; public static final int PORT = 7125;
private final String statement; private final String statement;
...@@ -56,10 +55,6 @@ public class WatchStatementExplainer { ...@@ -56,10 +55,6 @@ public class WatchStatementExplainer {
return MessageFormat.format(CREATE_SQL_TEMPLATE, tableName, ip, PORT, 1); return MessageFormat.format(CREATE_SQL_TEMPLATE, tableName, ip, PORT, 1);
} }
public String getInsertStatement(String tableName) {
return MessageFormat.format(INSERT_SQL_TEMPLATE, tableName);
}
private static Optional<InetAddress> getSystemLocalIp() { private static Optional<InetAddress> getSystemLocalIp() {
try { try {
InetAddress ip = InetAddress.getLocalHost(); InetAddress ip = InetAddress.getLocalHost();
......
...@@ -444,7 +444,7 @@ public class JobManager { ...@@ -444,7 +444,7 @@ public class JobManager {
} else if (useStatementSet && !useGateway) { } else if (useStatementSet && !useGateway) {
List<String> inserts = new ArrayList<>(); List<String> inserts = new ArrayList<>();
for (StatementParam item : jobParam.getTrans()) { for (StatementParam item : jobParam.getTrans()) {
if (item.getType().isInsert()) { if (item.getType().isInsert() || item.getType().equals(SqlType.CTAS)) {
inserts.add(item.getValue()); inserts.add(item.getValue());
} }
} }
......
...@@ -42,8 +42,9 @@ public enum SqlType { ...@@ -42,8 +42,9 @@ public enum SqlType {
RESET("RESET"), RESET("RESET"),
EXECUTE("EXECUTE"), EXECUTE("EXECUTE"),
ADD("ADD"), ADD("ADD"),
UNKNOWN("UNKNOWN"), WATCH("WATCH"),
WATCH("WATCH"); CTAS("CTAS"),
UNKNOWN("UNKNOWN");
private String type; private String type;
......
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