JingsongLi commented on a change in pull request #11381: 
[FLINK-16294][connectors /jdbc]Support to create non-existed table in database 
automatically when writing data to JDBC connector.
URL: https://github.com/apache/flink/pull/11381#discussion_r398289746
 
 

 ##########
 File path: 
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/dialect/JDBCDialect.java
 ##########
 @@ -139,4 +146,46 @@ default String getSelectFromStatement(String tableName, 
String[] selectFields, S
                return "SELECT " + selectExpressions + " FROM " +
                                quoteIdentifier(tableName) + 
(conditionFields.length > 0 ? " WHERE " + fieldExpressions : "");
        }
+
+       /**
+        * Get create table statement.
+        */
+       default String getCreateTableStatement(String tableName, String[] 
fieldNames,
+                       int[] fieldTypes, String[] primaryKeyFields) {
+               List<String> expressions = new ArrayList<>();
+               for (int i = 0; i < fieldNames.length; i++) {
+                       expressions.add(quoteIdentifier(fieldNames[i]) + " " + 
getSqlType2DialectTypeNameMap().get(fieldTypes[i]));
+               }
+               if (primaryKeyFields != null && primaryKeyFields.length > 0) {
+                       String primaryKey = quoteIdentifier("PRIMARY KEY") +
+                               String.format("(%s)", 
StringUtils.join(primaryKeyFields, ","));
+                       expressions.add(primaryKey);
+               }
+
+               return String.format("CREATE TABLE IF NOT EXISTS %s (%s)", 
quoteIdentifier(tableName),
+                       StringUtils.join(expressions, ","));
+       }
+
+       /**
+        * Get the type mapping between SQL types and dialect Types.
+        */
+       default Map<Integer, String> getSqlType2DialectTypeNameMap() {
 
 Review comment:
   Have we considered keep precision information?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to