Skip to content

Commit

Permalink
[feature][lib][rdbms] Add experimental support for DDL statement
Browse files Browse the repository at this point in the history
- Implement support for Data Definition Language (DDL) via setup `ddl` item.
- Enable experimental features for creating and altering tables before checking
  • Loading branch information
wgzhao committed Oct 11, 2024
1 parent 04ee37c commit 0ae2421
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -67,6 +68,7 @@ public Job(DataBaseType dataBaseType)

public void init(Configuration originalConfig)
{
ddlValid(originalConfig, dataBaseType);
OriginalConfPretreatmentUtil.doPretreatment(originalConfig, this.dataBaseType);
LOG.debug("After job init(), originalConfig now is:[\n{}\n]", originalConfig.toJSON());
}
Expand Down Expand Up @@ -109,6 +111,21 @@ public void privilegeValid(Configuration originalConfig, DataBaseType dataBaseTy
}
}

public void ddlValid(Configuration originalConfig, DataBaseType dataBaseType)
{
if (originalConfig.getString("ddl", null) != null) {
String username = originalConfig.getString(Key.USERNAME);
String password = originalConfig.getString(Key.PASSWORD);
Configuration connConf = originalConfig.getConfiguration(Key.CONNECTION);
String jdbcUrl = connConf.getString(Key.JDBC_URL);
String ddl = originalConfig.getString("ddl");
Connection connection = DBUtil.getConnection(dataBaseType, jdbcUrl, username, password);
LOG.info("Executing DDL: {}. context info:{}.", ddl, jdbcUrl);
WriterUtil.executeSqls(connection, Collections.singletonList(ddl));
DBUtil.closeDBResources(null, connection);
}
}

// 一般来说,是需要推迟到 task 中进行pre 的执行(单表情况例外)
public void prepare(Configuration originalConfig)
{
Expand Down

0 comments on commit 0ae2421

Please sign in to comment.