From 33513dd4f2dd090a4893ec340bb4d85fd1cdf20d Mon Sep 17 00:00:00 2001 From: Shashwat Tiwari Date: Mon, 21 Oct 2024 19:17:38 +0530 Subject: [PATCH] [Improve][DB2] Use generate_sink_sql=true for db2 upsert (#233) Signed-off-by: Mohammad Arshad --- .../impl/Db2DataSourceConfigSwitcher.java | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/thirdparty/datasource/impl/Db2DataSourceConfigSwitcher.java b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/thirdparty/datasource/impl/Db2DataSourceConfigSwitcher.java index 022148d61..a9277c2de 100644 --- a/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/thirdparty/datasource/impl/Db2DataSourceConfigSwitcher.java +++ b/seatunnel-server/seatunnel-app/src/main/java/org/apache/seatunnel/app/thirdparty/datasource/impl/Db2DataSourceConfigSwitcher.java @@ -42,9 +42,6 @@ public class Db2DataSourceConfigSwitcher extends BaseJdbcDataSourceConfigSwitcher { private static final String QUERY_KEY = "query"; - - private static final String GENERATE_SINK_SQL = "generate_sink_sql"; - private static final String URL_KEY = "url"; // for catalog @@ -109,16 +106,6 @@ public Config mergeDatasourceConfig( connectorConfig = connectorConfig.withValue(QUERY_KEY, ConfigValueFactory.fromAnyRef(sql)); - } else if (pluginType.equals(PluginType.SINK)) { - - List tableFields = selectTableFields.getTableFields(); - - String sql = generateDb2(tableFields, databaseName, tableName); - - connectorConfig = - connectorConfig.withValue(QUERY_KEY, ConfigValueFactory.fromAnyRef(sql)); - } else { - throw new UnsupportedOperationException("Unsupported plugin type: " + pluginType); } return super.mergeDatasourceConfig( @@ -185,10 +172,6 @@ protected String tableFieldsToSql(List tableFields, String database, Str return generateSql(tableFields, database, null, table); } - protected String generateDb2(List tableFields, String database, String table) { - return generateSinkSql(tableFields, database, null, table); - } - protected String generateSql( List tableFields, String database, String schema, String table) { StringBuilder sb = new StringBuilder(); @@ -208,35 +191,6 @@ protected String quoteIdentifier(String identifier) { return "\"" + identifier + "\""; } - protected String generateSinkSql( - List tableFields, String database, String schema, String table) { - StringBuilder sb = new StringBuilder(); - sb.append("INSERT INTO ") - .append(quoteIdentifier(database) + "." + quoteIdentifier(table)) - .append(" ("); - - // Append column names - for (int i = 0; i < tableFields.size(); i++) { - sb.append(quoteIdentifier(tableFields.get(i))); - if (i < tableFields.size() - 1) { - sb.append(", "); - } - } - - sb.append(") VALUES ("); - - // Append placeholders - for (int i = 0; i < tableFields.size(); i++) { - sb.append("?"); - if (i < tableFields.size() - 1) { - sb.append(", "); - } - } - - sb.append(");"); - return sb.toString(); - } - @Override public String getDataSourceName() { return "JDBC-DB2";