morozov commented on code in PR #4014:
URL: https://github.com/apache/flink-cdc/pull/4014#discussion_r2100980446


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-connector-sqlserver-cdc/src/main/java/org/apache/flink/cdc/connectors/sqlserver/source/utils/SqlServerUtils.java:
##########
@@ -361,12 +361,16 @@ private static String quoteSchemaAndTable(TableId 
tableId) {
         return quoted.toString();
     }
 
-    public static String quote(String dbOrTableName) {
-        return "[" + dbOrTableName + "]";
+    /**
+     * @link <a
+     *     
href="https://learn.microsoft.com/en-us/sql/t-sql/functions/quotename-transact-sql";>QUOTENAME</a>
+     */
+    public static String quote(String name) {
+        return "[" + name.replace("]", "]]") + "]";

Review Comment:
   Here's how the quotation logic can be validated manually:
   
   1. Create the table. Note that the closing square bracket is doubled: 
      ```sql
      CREATE TABLE [test [1]]] (id INT);
      ```
   2. Introspect databas tables:
      ```sql
      SELECT *
      FROM INFORMATION_SCHEMA.TABLES
      WHERE TABLE_TYPE = 'BASE TABLE';
      ```
      Note that the actual table name is `test [1]`:
      | TABLE\_CATALOG | TABLE\_SCHEMA | TABLE\_NAME | TABLE\_TYPE |
      | :--- | :--- | :--- | :--- |
      | customer | dbo | test \[1\] | BASE TABLE |
   3. Introspect table columns. Note that the opening square bracket is wrapped 
in square brackets. This is what Debezium doesn't do, and this is why Flink CDC 
cannot find the table PK in the reworked test:
      ```sql
      EXEC sp_columns_100 'test [[]1]'
      ``` 
      | TABLE\_QUALIFIER | TABLE\_OWNER | TABLE\_NAME | COLUMN\_NAME | 
DATA\_TYPE | TYPE\_NAME | PRECISION | LENGTH | SCALE | RADIX | NULLABLE | 
REMARKS | COLUMN\_DEF | SQL\_DATA\_TYPE | SQL\_DATETIME\_SUB | 
CHAR\_OCTET\_LENGTH | ORDINAL\_POSITION | IS\_NULLABLE | SS\_IS\_SPARSE | 
SS\_IS\_COLUMN\_SET | SS\_IS\_COMPUTED | SS\_IS\_IDENTITY | 
SS\_UDT\_CATALOG\_NAME | SS\_UDT\_SCHEMA\_NAME | SS\_UDT\_ASSEMBLY\_TYPE\_NAME 
| SS\_XML\_SCHEMACOLLECTION\_CATALOG\_NAME | 
SS\_XML\_SCHEMACOLLECTION\_SCHEMA\_NAME | SS\_XML\_SCHEMACOLLECTION\_NAME | 
SS\_DATA\_TYPE |
      | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | 
:--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | 
:--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
      | customer | dbo | test \[1\] | id | 4 | int | 10 | 4 | 0 | 10 | 1 | null 
| null | 4 | null | null | 1 | YES | 0 | 0 | 0 | 0 | null | null | null | null 
| null | null | 38 |
   



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to