use of com.flink.platform.common.job.Sql in project flink-platform-backend by itinycheng.
the class Sql112Application method main.
public static void main(String[] args) throws Exception {
// deSer sql context
Path sqlContextPath = Paths.get(args[0]);
SqlContext sqlContext = JsonUtil.toBean(sqlContextPath, SqlContext.class);
// step 1: create and configure environment
TableEnvironment tEnv = ExecutionEnvs.createExecutionEnv(sqlContext.getExecMode());
Map<String, String> configMap = ConfigLoader.loadDefault(sqlContext.getExecMode());
configMap.putAll(sqlContext.getConfigs());
configMap.putAll(sqlContext.getSqls().stream().filter(sql -> SqlType.SET.equals(sql.getType())).map(Sql::getOperands).collect(toMap(operands -> operands[0], operands -> operands[1])));
configMap.forEach((key, value) -> Configurations.setConfig(tEnv, key, value));
// step 2: add catalog
List<Catalog> catalogs = sqlContext.getCatalogs();
Catalogs.registerCatalogsToTableEnv(tEnv, catalogs);
// step 3: create temporary system function
List<Function> functions = sqlContext.getFunctions();
Functions.registerFunctionsToTableEnv(tEnv, functions);
// step 4: exec sql
List<Sql> executableSqls = sqlContext.getSqls().stream().filter(sql -> !SqlType.SET.equals(sql.getType())).collect(toList());
ExecuteSqls.execSqls(tEnv, executableSqls);
}
use of com.flink.platform.common.job.Sql in project flink-platform-backend by itinycheng.
the class SqlContextHelper method toSqls.
public List<Sql> toSqls(String subject) {
subject = subject.trim();
if (!subject.endsWith(SEMICOLON)) {
subject = subject + SEMICOLON;
}
List<Sql> sqlList = new ArrayList<>();
Matcher matcher = SQL_PATTERN.matcher(subject);
while (matcher.find()) {
String statement = matcher.group();
sqlList.add(SqlType.parse(statement));
}
if (sqlList.size() == 0) {
throw new JobCommandGenException(String.format("no sql found or parsing failed, subject: %s", subject));
}
return sqlList;
}
use of com.flink.platform.common.job.Sql in project flink-platform-backend by itinycheng.
the class JsonUtilTest method testEnum.
@Test
public void testEnum() {
SqlContext sqlContext = new SqlContext();
sqlContext.setId("a");
Sql sql = new Sql();
sql.setType(SqlType.INSERT_INTO);
sql.setOperands(new String[] { "insert into table" });
sqlContext.setSqls(Collections.singletonList(sql));
sqlContext.setExecMode(ExecutionMode.BATCH);
String jsonString = JsonUtil.toJsonString(sqlContext);
System.out.println(jsonString);
SqlContext sqlContext1 = JsonUtil.toBean(jsonString, SqlContext.class);
System.out.println(sqlContext1);
}
Aggregations