fsk119 commented on PR #19741:
URL: https://github.com/apache/flink/pull/19741#issuecomment-1144402454

   Hi, all. After digging in, I find the SQL
   
   ```
   SELECT TABLE_SCHEMA AS TABLE_CAT, NULL AS TABLE_SCHEM, TABLE_NAME, 
COLUMN_NAME, SEQ_IN_INDEX AS KEY_SEQ, 'PRIMARY' AS PK_NAME FROM 
INFORMATION_SCHEMA.STATISTICS
   WHERE TABLE_NAME = 't_grouped_by_sink' AND INDEX_NAME='PRIMARY' ORDER BY 
TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, SEQ_IN_INDEX;
   ```
   will get the PK name whose name is `t_grouped_by_sink` only. But the 
original logic that converts the ResultSet to PK
   
   ```
          while (rs.next()) {
               String columnName = rs.getString("COLUMN_NAME");
               pkName = rs.getString("PK_NAME"); // all the PK_NAME should be 
the same
               int keySeq = rs.getInt("KEY_SEQ");
               System.out.println(columnName); //Print all the column name
               keySeqColumnName.put(keySeq - 1, columnName); // KEY_SEQ is 
1-based index
           }
   ```
   
   may overwrite the pk here. You can notice `keySeqColumnName` is a Map. If 
you have two tables whose name is equal and they both have pks, it will only 
keep the PK in the last table in the `keySeqColumnName`. 
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to