You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/07/31 12:32:16 UTC

[GitHub] [inlong] leosanqing commented on a diff in pull request #5263: [INLONG-5228][Manager] Support create SQLServer databases and tables

leosanqing commented on code in PR #5263:
URL: https://github.com/apache/inlong/pull/5263#discussion_r933979921


##########
inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/core/sink/SQLServerSinkServiceTest.java:
##########
@@ -98,4 +106,68 @@ public void testGetAndUpdate() {
         deleteSink(sinkId);
     }
 
+    /**
+     * Just using in local test.
+     */
+    @Disabled
+    public void testDbResource() {
+        String url = "jdbc:sqlserver://127.0.0.1:1434;databaseName=inlong;";
+        String username = "sa";
+        String password = "123456";
+        String tableName = "test01";
+        String schemaName = "dbo";
+
+        try (Connection connection = SQLServerJdbcUtils.getConnection(url, username, password);) {
+            SQLServerTableInfo tableInfo = bulidTableInfo(schemaName, tableName);
+            SQLServerJdbcUtils.createSchema(connection, schemaName);
+            SQLServerJdbcUtils.createTable(connection, tableInfo);
+            List<SQLServerColumnInfo> addColumns = buildAddColumns();
+            SQLServerJdbcUtils.addColumns(connection, schemaName, tableName, addColumns);
+            List<SQLServerColumnInfo> columns = SQLServerJdbcUtils.getColumns(connection, schemaName, tableName);
+            Assertions.assertEquals(columns.size(), tableInfo.getColumns().size() + addColumns.size());
+        } catch (Exception e) {
+            // print to local console
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Build add SQLServer column info.
+     *
+     * @return {@link List}
+     */
+    private final List<SQLServerColumnInfo> buildAddColumns() {
+        List<SQLServerColumnInfo> addCloums = new ArrayList<>();
+        SQLServerColumnInfo test1 = new SQLServerColumnInfo("test1", "varchar(40)", "test1");
+        addCloums.add(test1);
+        SQLServerColumnInfo test2 = new SQLServerColumnInfo("test2", "varchar(40)", "test2");
+        addCloums.add(test2);
+        return addCloums;
+    }
+
+    /**
+     * Build test SQLServer table info.
+     *
+     * @param schemaName SqlServer schema name
+     * @param tableName SqlServer table name
+     * @return {@link SQLServerTableInfo}
+     */
+    private final SQLServerTableInfo bulidTableInfo(String schemaName, String tableName) {
+        SQLServerTableInfo tableInfo = new SQLServerTableInfo();
+        tableInfo.setTableName(tableName);
+        tableInfo.setComment("test01 ");
+        tableInfo.setPrimaryKey("id");
+        tableInfo.setSchemaName(schemaName);
+        List<SQLServerColumnInfo> columnInfos = new ArrayList<>();

Review Comment:
   Initializing columnInfos should be separated from the field logic of set tableInfo, with a blank line in the middle, which will be more readable



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org