Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
corgy-w merged PR #10422: URL: https://github.com/apache/seatunnel/pull/10422 -- 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]
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
yzeng1618 commented on code in PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#discussion_r2761881562
##
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/utils/JdbcIdentifierUtils.java:
##
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.utils;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.Locale;
+
+public final class JdbcIdentifierUtils {
+
+private JdbcIdentifierUtils() {}
+
+public enum IdentifierCaseStrategy {
+CASE_SENSITIVE,
+LOWER_CASE,
+UPPER_CASE,
+CASE_INSENSITIVE
+}
+
+/**
+ * Resolve case handling strategy for unquoted identifiers based on {@link
DatabaseMetaData}.
+ *
+ * Note: JDBC metadata APIs often treat {@code schemaPattern}/{@code
tableNamePattern} as
+ * patterns (e.g. SQL LIKE), while identifier case sensitivity depends on
the database. This
+ * method provides a best-effort strategy to compare identifiers returned
by JDBC metadata APIs.
+ */
+public static IdentifierCaseStrategy
identifierCaseStrategy(DatabaseMetaData metadata)
+throws SQLException {
+if (metadata == null) {
+return IdentifierCaseStrategy.CASE_INSENSITIVE;
+}
+if (metadata.supportsMixedCaseIdentifiers()) {
+return IdentifierCaseStrategy.CASE_SENSITIVE;
+}
+if (metadata.storesLowerCaseIdentifiers()) {
+return IdentifierCaseStrategy.LOWER_CASE;
+}
+if (metadata.storesUpperCaseIdentifiers()) {
+return IdentifierCaseStrategy.UPPER_CASE;
+}
+return IdentifierCaseStrategy.CASE_INSENSITIVE;
Review Comment:
The main issue is that JDBC sources include both case-sensitive and
case-insensitive data sources. Therefore, we use the
supportsMixedCaseIdentifiers() function as a switch to treat unquoted
identifiers containing mixed case as case-sensitive.
--
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]
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
Carl-Zhou-CN commented on code in PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#discussion_r2758383306
##
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/utils/JdbcIdentifierUtils.java:
##
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.utils;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.Locale;
+
+public final class JdbcIdentifierUtils {
+
+private JdbcIdentifierUtils() {}
+
+public enum IdentifierCaseStrategy {
+CASE_SENSITIVE,
+LOWER_CASE,
+UPPER_CASE,
+CASE_INSENSITIVE
+}
+
+/**
+ * Resolve case handling strategy for unquoted identifiers based on {@link
DatabaseMetaData}.
+ *
+ * Note: JDBC metadata APIs often treat {@code schemaPattern}/{@code
tableNamePattern} as
+ * patterns (e.g. SQL LIKE), while identifier case sensitivity depends on
the database. This
+ * method provides a best-effort strategy to compare identifiers returned
by JDBC metadata APIs.
+ */
+public static IdentifierCaseStrategy
identifierCaseStrategy(DatabaseMetaData metadata)
+throws SQLException {
+if (metadata == null) {
+return IdentifierCaseStrategy.CASE_INSENSITIVE;
+}
+if (metadata.supportsMixedCaseIdentifiers()) {
Review Comment:
Could it be that he threw an exception
--
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]
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
Carl-Zhou-CN commented on code in PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#discussion_r2758386616
##
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/utils/JdbcIdentifierUtils.java:
##
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.utils;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.Locale;
+
+public final class JdbcIdentifierUtils {
+
+private JdbcIdentifierUtils() {}
+
+public enum IdentifierCaseStrategy {
+CASE_SENSITIVE,
+LOWER_CASE,
+UPPER_CASE,
+CASE_INSENSITIVE
+}
+
+/**
+ * Resolve case handling strategy for unquoted identifiers based on {@link
DatabaseMetaData}.
+ *
+ * Note: JDBC metadata APIs often treat {@code schemaPattern}/{@code
tableNamePattern} as
+ * patterns (e.g. SQL LIKE), while identifier case sensitivity depends on
the database. This
+ * method provides a best-effort strategy to compare identifiers returned
by JDBC metadata APIs.
+ */
+public static IdentifierCaseStrategy
identifierCaseStrategy(DatabaseMetaData metadata)
+throws SQLException {
+if (metadata == null) {
+return IdentifierCaseStrategy.CASE_INSENSITIVE;
+}
+if (metadata.supportsMixedCaseIdentifiers()) {
+return IdentifierCaseStrategy.CASE_SENSITIVE;
+}
+if (metadata.storesLowerCaseIdentifiers()) {
+return IdentifierCaseStrategy.LOWER_CASE;
+}
+if (metadata.storesUpperCaseIdentifiers()) {
+return IdentifierCaseStrategy.UPPER_CASE;
+}
+return IdentifierCaseStrategy.CASE_INSENSITIVE;
Review Comment:
Should we be the most tolerant?
--
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]
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
Carl-Zhou-CN commented on code in PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#discussion_r2758383306
##
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/utils/JdbcIdentifierUtils.java:
##
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.utils;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.Locale;
+
+public final class JdbcIdentifierUtils {
+
+private JdbcIdentifierUtils() {}
+
+public enum IdentifierCaseStrategy {
+CASE_SENSITIVE,
+LOWER_CASE,
+UPPER_CASE,
+CASE_INSENSITIVE
+}
+
+/**
+ * Resolve case handling strategy for unquoted identifiers based on {@link
DatabaseMetaData}.
+ *
+ * Note: JDBC metadata APIs often treat {@code schemaPattern}/{@code
tableNamePattern} as
+ * patterns (e.g. SQL LIKE), while identifier case sensitivity depends on
the database. This
+ * method provides a best-effort strategy to compare identifiers returned
by JDBC metadata APIs.
+ */
+public static IdentifierCaseStrategy
identifierCaseStrategy(DatabaseMetaData metadata)
+throws SQLException {
+if (metadata == null) {
+return IdentifierCaseStrategy.CASE_INSENSITIVE;
+}
+if (metadata.supportsMixedCaseIdentifiers()) {
Review Comment:
Could it be that he threw an exception
--
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]
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
yzeng1618 commented on code in PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#discussion_r2752861214
##
seatunnel-connectors-v2/connector-cdc/connector-cdc-sqlserver/src/main/java/io/debezium/connector/sqlserver/SqlServerConnection.java:
##
@@ -705,6 +705,20 @@ public Table getTableSchemaFromTable(String databaseName,
SqlServerChangeTable c
changeTable.getSourceTableId().table(),
null)) {
while (rs.next()) {
+// `tableNamePattern` is treated as a SQL LIKE pattern by many
drivers, so filter
Review Comment:
This is not a SQL Server-specific case; it is caused by the pattern
semantics of JDBC getColumns combined with differences in driver
implementations.
The reason SqlServerConnection.java appears in the PR is that SQL Server CDC
follows a separate code path in Debezium and does not reuse SeaTunnel’s JDBC
CatalogUtils or JdbcDialectTypeMapper. Therefore, the same protection logic
must also be applied to the CDC code path.
--
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]
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
DanielCarter-stack commented on PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#issuecomment-3831152467
### Issue 1: Improper Case Sensitivity Handling
**Location**:
- `JdbcDialectTypeMapper.java:97-110`
- `JdbcColumnConverter.java:87-98`
- `SqlServerConnection.java:710-721`
**Issue Description**:
Using `equalsIgnoreCase` for table name and schema name comparison, but in
some databases (such as PostgreSQL under certain configurations, Oracle, H2,
etc.), table names are **case-sensitive**. This could lead to:
- User queries `UserInfo` (uppercase U)
- Database returns columns of `userinfo` (lowercase)
- `equalsIgnoreCase` considers them equal, incorrectly including that column
**Related Context**:
- Parent/interface: `DatabaseMetaData.getColumns()` JDBC specification
states "whether identifiers are case-sensitive depends on the database"
- Caller: `CatalogUtils.getTableSchema()` is called in 23 database connectors
- Impact scope: All case-sensitive databases (PostgreSQL, Oracle, H2, DB2,
etc.)
**Potential Risks**:
- Risk 1: On case-sensitive databases, columns from wrong tables may be
included (though probability is low)
- Risk 2: Tests do not cover case sensitivity scenarios
**Impact Scope**:
- Direct impact: Column discovery for case-sensitive databases like
PostgreSQL, Oracle, H2, DB2, SAP HANA, etc.
- Indirect impact: Type inference and data conversion based on column
information
- Affected area: Multiple Connectors (approximately 10+ case-sensitive
databases)
**Severity**: **MAJOR**
**Improvement Suggestions**:
```java
// Suggestion: Consider database case sensitivity
// Solution 1: Get information from
DatabaseMetaData.storesLowerCaseIdentifiers()
boolean storesLowerCase = metadata.storesLowerCaseIdentifiers();
boolean storesUpperCase = metadata.storesUpperCaseIdentifiers();
boolean storesMixedCase = metadata.storesMixedCaseQuotedIdentifiers();
// Solution 2: Use DatabaseMetaData.identifierEqualsString() (JDBC 4.3+)
// But need to consider compatibility
// Solution 3 (current best practice): Keep equalsIgnoreCase, but add
warning log
if (actualTableName == null ||
!actualTableName.equalsIgnoreCase(tableNamePattern)) {
if (actualTableName != null &&
!actualTableName.equals(tableNamePattern)) {
log.debug("Filtered column from table '{}' while looking for '{}',
case-sensitive databases may require exact match",
actualTableName, tableNamePattern);
}
continue;
}
```
**Rationale**:
1. JDBC specification explicitly states that case sensitivity varies across
different databases
2. Using `equalsIgnoreCase` is correct on case-insensitive databases (such
as MySQL, SQL Server)
3. But may cause errors on case-sensitive databases
4. Adding logs can help users diagnose issues
---
### Issue 2: Missing Handling and Warning for Empty Column Lists
**Location**:
- `JdbcDialectTypeMapper.java:84-135`
- `JdbcColumnConverter.java:73-121`
**Issue Description**:
If all returned rows are filtered out (for example, the JDBC driver returns
completely mismatched tables), the code will **silently return an empty list**.
This could lead to:
1. Upstream callers assuming the table has no columns and continuing
processing
2. Failing at a later stage (such as missing required columns)
3. Unclear error messages, making diagnosis difficult
**Related Context**:
- Caller 1: `CatalogUtils.getTableSchema()` (lines 223-245)
- Caller 2: `SqlServerConnection.getTableSchemaFromTable()` (lines 696-739)
- These callers expect non-empty column lists to be returned
**Potential Risks**:
- Risk 1: When table doesn't exist or configuration is wrong, errors are
delayed to later stages
- Risk 2: Users see "table has no columns" instead of "table doesn't exist
or columns were filtered"
- Risk 3: Difficult to debug
**Impact Scope**:
- Direct impact: All users using JDBC CDC and JDBC Source
- Indirect impact: Task failures, data loss
- Affected area: All Connectors
**Severity**: **MINOR**
**Improvement Suggestions**:
```java
// In JdbcDialectTypeMapper.java
List columns = new ArrayList<>();
int filteredRows = 0; // Add counter
try (ResultSet rs = metadata.getColumns(...)) {
while (rs.next()) {
if (tableNamePattern != null) {
String actualTableName = rs.getString("TABLE_NAME");
if (actualTableName == null ||
!actualTableName.equalsIgnoreCase(tableNamePattern)) {
filteredRows++; // Log filtered rows
continue;
}
}
// ... rest of logic
columns.add(mappingColumn(typeDefine));
}
}
// Add: If all rows are filtered, log warning
if (colu
Re: [PR] [Fix][Connector-V2] Fix wrong column discovery when tableNamePattern is treated as LIKE [seatunnel]
Carl-Zhou-CN commented on code in PR #10422:
URL: https://github.com/apache/seatunnel/pull/10422#discussion_r2750833779
##
seatunnel-connectors-v2/connector-cdc/connector-cdc-sqlserver/src/main/java/io/debezium/connector/sqlserver/SqlServerConnection.java:
##
@@ -705,6 +705,20 @@ public Table getTableSchemaFromTable(String databaseName,
SqlServerChangeTable c
changeTable.getSourceTableId().table(),
null)) {
while (rs.next()) {
+// `tableNamePattern` is treated as a SQL LIKE pattern by many
drivers, so filter
Review Comment:
Why is only qlserver rather special?
--
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]
