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 {
WatchStatementExplainer watchStatementExplainer =
new WatchStatementExplainer(statement);
String tableName = watchStatementExplainer.getTableName();
ddl.add(
new StatementParam(
watchStatementExplainer.getCreateStatement(tableName),
SqlType.CREATE));
trans.add(
new StatementParam(
watchStatementExplainer.getInsertStatement(tableName),
SqlType.INSERT));
watchStatementExplainer.getCreateStatement(tableName),
SqlType.CTAS));
} else {
UDF udf = UDFUtil.toUDF(statement);
if (Asserts.isNotNull(udf)) {
......
......@@ -34,8 +34,7 @@ public class WatchStatementExplainer {
public static final String CREATE_SQL_TEMPLATE =
"CREATE TABLE print_{0} WITH (''connector'' = ''printnet'', "
+ "''port''=''{2,number,#}'', ''hostName'' = ''{1}'', ''sink.parallelism''=''{3}'')\n"
+ "LIKE {0};";
public static final String INSERT_SQL_TEMPLATE = "insert into print_{0} select * from {0};";
+ "AS SELECT * FROM {0}";
public static final int PORT = 7125;
private final String statement;
......@@ -56,10 +55,6 @@ public class WatchStatementExplainer {
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() {
try {
InetAddress ip = InetAddress.getLocalHost();
......
......@@ -444,7 +444,7 @@ public class JobManager {
} else if (useStatementSet && !useGateway) {
List<String> inserts = new ArrayList<>();
for (StatementParam item : jobParam.getTrans()) {
if (item.getType().isInsert()) {
if (item.getType().isInsert() || item.getType().equals(SqlType.CTAS)) {
inserts.add(item.getValue());
}
}
......
......@@ -42,8 +42,9 @@ public enum SqlType {
RESET("RESET"),
EXECUTE("EXECUTE"),
ADD("ADD"),
UNKNOWN("UNKNOWN"),
WATCH("WATCH");
WATCH("WATCH"),
CTAS("CTAS"),
UNKNOWN("UNKNOWN");
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