Skip to content

Commit 94f3003

Browse files
authored
[PECOBLR-1338] fix isNullOrEmpty check for schemaNamePattern in SEA (databricks#1119)
## Description <!-- Provide a brief summary of the changes made and the issue they aim to address.--> Fix incorrect schemaPattern check in SEA metadata commands Repro: ``` ResultSet rs = con.getMetaData().getTables("main", "", "%", null); ``` Above code snippet should return empty result. Same as thrift ## Testing <!-- Describe how the changes have been tested--> - Unit test - Verified that repro snippet behaves accordingly ## Additional Notes to the Reviewer <!-- Share any additional context or insights that may help the reviewer understand the changes better. This could include challenges faced, limitations, or compromises made during the development process. Also, mention any areas of the code that you would like the reviewer to focus on specifically. --> NO_CHANGELOG=true
1 parent 9e26d82 commit 94f3003

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/main/java/com/databricks/jdbc/dbclient/impl/sqlexec/CommandBuilder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private String fetchSchemaSQL() {
8787
} else {
8888
showSchemasSQL = String.format(SHOW_SCHEMAS_IN_CATALOG_SQL, catalogName);
8989
}
90-
if (!WildcardUtil.isNullOrEmpty(schemaPattern)) {
90+
if (schemaPattern != null) {
9191
showSchemasSQL += String.format(LIKE_SQL, schemaPattern);
9292
}
9393
return showSchemasSQL;
@@ -107,10 +107,10 @@ private String fetchTablesSQL() {
107107
} else {
108108
showTablesSQL = String.format(SHOW_TABLES_SQL, catalogName);
109109
}
110-
if (!WildcardUtil.isNullOrEmpty(schemaPattern)) {
110+
if (schemaPattern != null) {
111111
showTablesSQL += String.format(SCHEMA_LIKE_SQL, schemaPattern);
112112
}
113-
if (!WildcardUtil.isNullOrEmpty(tablePattern)) {
113+
if (tablePattern != null) {
114114
showTablesSQL += String.format(LIKE_SQL, tablePattern);
115115
}
116116
return showTablesSQL;
@@ -125,15 +125,15 @@ private String fetchColumnsSQL() throws DatabricksSQLException {
125125
throwErrorIfNull(Collections.singletonMap(CATALOG, catalogName), contextString);
126126
String showColumnsSQL = String.format(SHOW_COLUMNS_SQL, catalogName);
127127

128-
if (!WildcardUtil.isNullOrEmpty(schemaPattern)) {
128+
if (schemaPattern != null) {
129129
showColumnsSQL += String.format(SCHEMA_LIKE_SQL, schemaPattern);
130130
}
131131

132-
if (!WildcardUtil.isNullOrEmpty(tablePattern)) {
132+
if (tablePattern != null) {
133133
showColumnsSQL += String.format(TABLE_LIKE_SQL, tablePattern);
134134
}
135135

136-
if (!WildcardUtil.isNullOrEmpty(columnPattern)) {
136+
if (columnPattern != null) {
137137
showColumnsSQL += String.format(LIKE_SQL, columnPattern);
138138
}
139139
return showColumnsSQL;
@@ -148,10 +148,10 @@ private String fetchFunctionsSQL() throws DatabricksSQLException {
148148
LOGGER.debug(contextString);
149149
throwErrorIfNull(Collections.singletonMap(CATALOG, catalogName), contextString);
150150
String showFunctionsSQL = String.format(SHOW_FUNCTIONS_SQL, catalogName);
151-
if (!WildcardUtil.isNullOrEmpty(schemaPattern)) {
151+
if (schemaPattern != null) {
152152
showFunctionsSQL += String.format(SCHEMA_LIKE_SQL, schemaPattern);
153153
}
154-
if (!WildcardUtil.isNullOrEmpty(functionPattern)) {
154+
if (functionPattern != null) {
155155
showFunctionsSQL += String.format(LIKE_SQL, functionPattern);
156156
}
157157
return showFunctionsSQL;

src/test/java/com/databricks/jdbc/dbclient/impl/sqlexec/CommandBuilderTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,39 @@ void shouldGenerateCorrectSqlForTablesWithWildcardCatalog() throws SQLException
148148
String sql1 = builder1.getSQLString(CommandName.LIST_TABLES);
149149
assertEquals(SHOW_TABLES_IN_ALL_CATALOGS_SQL, sql1);
150150
}
151+
152+
@Test
153+
@DisplayName("Should generate SCHEMA LIKE clause for empty string schema pattern")
154+
void shouldGenerateSchemaLikeClauseForEmptyStringSchemaPattern() throws SQLException {
155+
CommandBuilder builder = new CommandBuilder(TEST_CATALOG, mockSession).setSchemaPattern("");
156+
157+
String sql = builder.getSQLString(CommandName.LIST_TABLES);
158+
159+
String expectedSql = String.format(SHOW_TABLES_SQL.concat(SCHEMA_LIKE_SQL), TEST_CATALOG, "");
160+
assertEquals(expectedSql, sql);
161+
}
162+
163+
@Test
164+
@DisplayName("Should NOT generate SCHEMA LIKE clause for null schema pattern")
165+
void shouldNotGenerateSchemaLikeClauseForNullSchemaPattern() throws SQLException {
166+
CommandBuilder builder = new CommandBuilder(TEST_CATALOG, mockSession).setSchemaPattern(null);
167+
168+
String sql = builder.getSQLString(CommandName.LIST_TABLES);
169+
170+
String expectedSql = String.format(SHOW_TABLES_SQL, TEST_CATALOG);
171+
assertEquals(expectedSql, sql);
172+
}
173+
174+
@Test
175+
@DisplayName("Should generate LIKE clause for empty string table pattern")
176+
void shouldGenerateLikeClauseForEmptyStringTablePattern() throws SQLException {
177+
CommandBuilder builder = new CommandBuilder(TEST_CATALOG, mockSession).setTablePattern("");
178+
179+
String sql = builder.getSQLString(CommandName.LIST_TABLES);
180+
181+
String expectedSql = String.format(SHOW_TABLES_SQL.concat(LIKE_SQL), TEST_CATALOG, "");
182+
assertEquals(expectedSql, sql);
183+
}
151184
}
152185

153186
@Nested

0 commit comments

Comments
 (0)