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. This
is what Flink CDC currently doesn't do:
```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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]