Skip to content

Commit 5742436

Browse files
authored
Fix getCrossReference case-insensitive parent matching (#1411)
## Summary - `getCrossReference()` returned 0 rows when parent catalog/schema/table args were passed in uppercase - Root cause: `CrossReferenceKeysDatabricksResultSetAdapter.includeRow()` used `.equals()` for comparing user-provided parent args against server-returned lowercase values - Fixed by changing to `.equalsIgnoreCase()` — Databricks identifiers are case-insensitive ## Test plan - [x] Unit tests: 2 new tests for case-insensitive matching (12 total pass) - [x] End-to-end: verified with `getCrossReference(COMPARATOR_TESTS, OSS_JDBC_TESTS, FK_PARENT, ...)` — SEA now returns 1 row matching Thrift - [x] Tested on both Peco testing and Peco comparator workspaces Signed-off-by: Sreekanth Vadigi <[email protected]>
1 parent c594e81 commit 5742436

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Fixed escaped pattern characters in catalogName for `getSchemas`, as returned catalogName should be unescaped.
1717
- Fixed `getColumnClassName()` returning null for VARIANT columns in SEA mode by adding VARIANT to the type system.
1818
- Fixed `getColumns()` returning `DATA_TYPE=0` (NULL) for GEOMETRY/GEOGRAPHY columns in Thrift mode. Now returns `Types.VARCHAR` (12) when geospatial is disabled and `Types.OTHER` (1111) when enabled, consistent with SEA mode.
19+
- Fixed `getCrossReference()` returning 0 rows when parent args are passed in uppercase. The client-side filter used case-sensitive comparison against server-returned lowercase names.
1920

2021
---
2122
*Note: When making changes, please add your change under the appropriate section

src/main/java/com/databricks/jdbc/dbclient/impl/common/CrossReferenceKeysDatabricksResultSetAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public boolean includeRow(ResultSet resultSet, List<ResultColumn> columns) throw
4343
boolean isParentCatalogMatching =
4444
resultSet
4545
.getString(parentCatalogNameColumn.getResultSetColumnName())
46-
.equals(targetParentCatalogName);
46+
.equalsIgnoreCase(targetParentCatalogName);
4747
boolean isParentNamespaceMatching =
4848
resultSet
4949
.getString(parentNamespaceColumn.getResultSetColumnName())
50-
.equals(targetParentNamespaceName);
50+
.equalsIgnoreCase(targetParentNamespaceName);
5151
boolean isParentTableMatching =
5252
resultSet
5353
.getString(parentTableNameColumn.getResultSetColumnName())
54-
.equals(targetParentTableName);
54+
.equalsIgnoreCase(targetParentTableName);
5555

5656
if (!isParentTableMatching || !isParentCatalogMatching || !isParentNamespaceMatching) {
5757
return false;

src/test/java/com/databricks/jdbc/dbclient/impl/common/CrossReferenceKeysDatabricksResultSetAdapterTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,45 @@ public void testConstructorSetsTargetParentTableName() throws SQLException {
125125
assertTrue(result, "Constructor should properly set the target parent table name");
126126
}
127127

128+
@Test
129+
public void testIncludeRowMatchesCaseInsensitively() throws SQLException {
130+
List<ResultColumn> columns = new ArrayList<>();
131+
132+
// Mock the ResultSet to return lowercase values while adapter was constructed with mixed case
133+
when(mockResultSet.getString(PARENT_CATALOG_NAME.getResultSetColumnName()))
134+
.thenReturn("targetcatalog");
135+
when(mockResultSet.getString(PARENT_NAMESPACE_NAME.getResultSetColumnName()))
136+
.thenReturn("targetschema");
137+
when(mockResultSet.getString(PARENT_TABLE_NAME.getResultSetColumnName()))
138+
.thenReturn("targettable");
139+
140+
boolean result = crossRefAdapter.includeRow(mockResultSet, columns);
141+
142+
assertTrue(result, "includeRow should match case-insensitively");
143+
}
144+
145+
@Test
146+
public void testIncludeRowMatchesUppercaseInput() throws SQLException {
147+
List<ResultColumn> columns = new ArrayList<>();
148+
149+
// Adapter constructed with mixed case, server returns lowercase
150+
CrossReferenceKeysDatabricksResultSetAdapter uppercaseAdapter =
151+
new CrossReferenceKeysDatabricksResultSetAdapter(
152+
"TARGETCATALOG", "TARGETSCHEMA", "TARGETTABLE");
153+
154+
when(mockResultSet.getString(PARENT_CATALOG_NAME.getResultSetColumnName()))
155+
.thenReturn("targetcatalog");
156+
when(mockResultSet.getString(PARENT_NAMESPACE_NAME.getResultSetColumnName()))
157+
.thenReturn("targetschema");
158+
when(mockResultSet.getString(PARENT_TABLE_NAME.getResultSetColumnName()))
159+
.thenReturn("targettable");
160+
161+
boolean result = uppercaseAdapter.includeRow(mockResultSet, columns);
162+
163+
assertTrue(
164+
result, "includeRow should match when user passes uppercase and server returns lowercase");
165+
}
166+
128167
@Test
129168
public void testInheritanceFromImportedKeysAdapter() {
130169
assertInstanceOf(ImportedKeysDatabricksResultSetAdapter.class, crossRefAdapter);

0 commit comments

Comments
 (0)