Skip to content

Commit

Permalink
Fix check-style
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jf committed Feb 15, 2024
1 parent 3ca6226 commit 327d802
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 56 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro
}
break;


default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,8 @@ public ResultSet getPrimaryKeys(String originalCatalog, String originalSchema, f
}

final String catalogIn = catalog;
// These values for Schema and Table will only be used to filter results if the connection property
// These values for Schema and Table will only be used to filter results if the connection
// property
// enablePatternSearch=false
final String schemaIn = schema;
final String tableIn = table;
Expand Down Expand Up @@ -2120,10 +2121,10 @@ public boolean next() throws SQLException {
// Post filter based on the input
if (isPatternMatchingEnabled) {
if ((catalogIn == null || catalogIn.equals(table_cat))
&& (compiledSchemaPattern == null
&& (compiledSchemaPattern == null
|| compiledSchemaPattern.equals(table_schem)
|| compiledSchemaPattern.matcher(table_schem).matches())
&& (compiledTablePattern == null
&& (compiledTablePattern == null
|| compiledTablePattern.equals(table_name)
|| compiledTablePattern.matcher(table_name).matches())) {
nextRow[0] = table_cat;
Expand All @@ -2136,8 +2137,8 @@ public boolean next() throws SQLException {
}
} else {
if ((catalogIn == null || catalogIn.equals(table_cat))
&& (schemaIn == null || schemaIn.equals(table_schem))
&& (tableIn == null || tableIn.equals(table_name))) {
&& (schemaIn == null || schemaIn.equals(table_schem))
&& (tableIn == null || tableIn.equals(table_name))) {
nextRow[0] = table_cat;
nextRow[1] = table_schem;
nextRow[2] = table_name;
Expand Down Expand Up @@ -2186,7 +2187,8 @@ private ResultSet getForeignKeys(
final String parentCatalog = resPair.left;
final String parentSchema = resPair.right;

// These Patterns will only be used to filter results if the connection property enablePatternSearch=true
// These Patterns will only be used to filter results if the connection property
// enablePatternSearch=true
final Pattern compiledSchemaPattern = Wildcard.toRegexPattern(parentSchema, true);
final Pattern compiledParentTablePattern = Wildcard.toRegexPattern(parentTable, true);
final Pattern compiledForeignSchemaPattern = Wildcard.toRegexPattern(foreignSchema, true);
Expand All @@ -2206,7 +2208,8 @@ private ResultSet getForeignKeys(
return SnowflakeDatabaseMetaDataResultSet.getEmptyResultSet(GET_FOREIGN_KEYS, statement);
} else {
String unescapedParentCatalog = escapeSqlQuotes(parentCatalog);
if (parentSchema == null || (isSchemaNameWildcardPattern(parentSchema) && isPatternMatchingEnabled)) {
if (parentSchema == null
|| (isSchemaNameWildcardPattern(parentSchema) && isPatternMatchingEnabled)) {
commandBuilder.append("database \"" + unescapedParentCatalog + "\"");
} else if (parentSchema.isEmpty()) {
return SnowflakeDatabaseMetaDataResultSet.getEmptyResultSet(GET_FOREIGN_KEYS, statement);
Expand All @@ -2233,7 +2236,8 @@ private ResultSet getForeignKeys(

final String finalParentCatalog = parentCatalog;
final String finalForeignCatalog = foreignCatalog;
// These values will only be used to filter results if the connection property enablePatternSearch=true
// These values will only be used to filter results if the connection property
// enablePatternSearch=true
final String finalParentSchema = parentSchema;
final String finalParentTable = parentTable;
final String finalForeignSchema = foreignSchema;
Expand Down Expand Up @@ -2284,21 +2288,21 @@ public boolean next() throws SQLException {
if (client.equals("import")) {
// For imported keys, filter on the foreign key table
if ((finalParentCatalog == null || finalParentCatalog.equals(fktable_cat))
&& (compiledSchemaPattern == null
&& (compiledSchemaPattern == null
|| compiledSchemaPattern.equals(fktable_schem)
|| compiledSchemaPattern.matcher(fktable_schem).matches())
&& (compiledParentTablePattern == null
&& (compiledParentTablePattern == null
|| compiledParentTablePattern.equals(fktable_name)
|| compiledParentTablePattern.matcher(fktable_name).matches())) {
passedFilter = true;
}
} else if (client.equals("export")) {
// For exported keys, filter on the primary key table
if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat))
&& (compiledSchemaPattern == null
&& (compiledSchemaPattern == null
|| compiledSchemaPattern.equals(pktable_schem)
|| compiledSchemaPattern.matcher(pktable_schem).matches())
&& (compiledParentTablePattern == null
&& (compiledParentTablePattern == null
|| compiledParentTablePattern.equals(pktable_name)
|| compiledParentTablePattern.matcher(pktable_name).matches())) {
passedFilter = true;
Expand All @@ -2307,17 +2311,17 @@ public boolean next() throws SQLException {
// For cross references, filter on both the primary key and foreign
// key table
if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat))
&& (compiledSchemaPattern == null
&& (compiledSchemaPattern == null
|| compiledSchemaPattern.equals(pktable_schem)
|| compiledSchemaPattern.matcher(pktable_schem).matches())
&& (compiledParentTablePattern == null
&& (compiledParentTablePattern == null
|| compiledParentTablePattern.equals(pktable_name)
|| compiledParentTablePattern.matcher(pktable_name).matches())
&& (foreignCatalog == null || foreignCatalog.equals(fktable_cat))
&& (compiledForeignSchemaPattern == null
&& (foreignCatalog == null || foreignCatalog.equals(fktable_cat))
&& (compiledForeignSchemaPattern == null
|| compiledForeignSchemaPattern.equals(fktable_schem)
|| compiledForeignSchemaPattern.matcher(fktable_schem).matches())
&& (compiledForeignTablePattern == null
&& (compiledForeignTablePattern == null
|| compiledForeignTablePattern.equals(fktable_name)
|| compiledForeignTablePattern.matcher(fktable_name).matches())) {
passedFilter = true;
Expand All @@ -2328,30 +2332,29 @@ public boolean next() throws SQLException {
if (client.equals("import")) {
// For imported keys, filter on the foreign key table
if ((finalParentCatalog == null || finalParentCatalog.equals(fktable_cat))
&& (finalParentSchema == null || finalParentSchema.equals(fktable_schem))
&& (finalParentTable == null || finalParentTable.equals(fktable_name))) {
&& (finalParentSchema == null || finalParentSchema.equals(fktable_schem))
&& (finalParentTable == null || finalParentTable.equals(fktable_name))) {
passedFilter = true;
}
} else if (client.equals("export")) {
// For exported keys, filter on the primary key table
if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat))
&& (finalParentSchema == null || finalParentSchema.equals(pktable_schem))
&& (finalParentTable == null || finalParentTable.equals(pktable_name))) {
&& (finalParentSchema == null || finalParentSchema.equals(pktable_schem))
&& (finalParentTable == null || finalParentTable.equals(pktable_name))) {
passedFilter = true;
}
} else if (client.equals("cross")) {
// For cross references, filter on both the primary key and foreign
// key table
if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat))
&& (finalParentSchema == null || finalParentSchema.equals(pktable_schem))
&& (finalParentTable == null || finalParentTable.equals(pktable_name))
&& (finalForeignCatalog == null || finalForeignCatalog.equals(fktable_cat))
&& (finalForeignSchema == null || finalForeignSchema.equals(fktable_schem))
&& (finalForeignTable == null || finalForeignTable.equals(fktable_name))) {
&& (finalParentSchema == null || finalParentSchema.equals(pktable_schem))
&& (finalParentTable == null || finalParentTable.equals(pktable_name))
&& (finalForeignCatalog == null || finalForeignCatalog.equals(fktable_cat))
&& (finalForeignSchema == null || finalForeignSchema.equals(fktable_schem))
&& (finalForeignTable == null || finalForeignTable.equals(fktable_name))) {
passedFilter = true;
}
}

}

if (passedFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1714,16 +1714,16 @@ public void testNoPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcep
final String table2 = "T2";

connection
.createStatement()
.execute("create or replace table " + table1 + "(C1 int primary key, C2 string)");
.createStatement()
.execute("create or replace table " + table1 + "(C1 int primary key, C2 string)");
connection
.createStatement()
.execute(
"create or replace table "
+ table2
+ "(C1 int primary key, C2 string, C3 int references "
+ table1
+ ")");
.createStatement()
.execute(
"create or replace table "
+ table2
+ "(C1 int primary key, C2 string, C3 int references "
+ table1
+ ")");

DatabaseMetaData dbmd = connection.getMetaData();

Expand Down Expand Up @@ -1755,13 +1755,26 @@ public void testNoPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcep
assertEquals(0, getSizeOfResultSet(dbmd.getExportedKeys(database, null, "T%")));

// Should return result for matching schema and table name
assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, schema, table2)));
assertEquals(
1,
getSizeOfResultSet(
dbmd.getCrossReference(database, schema, table1, database, schema, table2)));

// Should return an empty result if we try a pattern match on any of the table or schema names
assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2)));
assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2)));
assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2)));
assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%")));
assertEquals(
0,
getSizeOfResultSet(
dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2)));
assertEquals(
0,
getSizeOfResultSet(
dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2)));
assertEquals(
0,
getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2)));
assertEquals(
0,
getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%")));
}

@Test
Expand All @@ -1783,16 +1796,16 @@ public void testPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcepti
final String table2 = "T2";

connection
.createStatement()
.execute("create or replace table " + table1 + "(C1 int primary key, C2 string)");
.createStatement()
.execute("create or replace table " + table1 + "(C1 int primary key, C2 string)");
connection
.createStatement()
.execute(
"create or replace table "
+ table2
+ "(C1 int primary key, C2 string, C3 int references "
+ table1
+ ")");
.createStatement()
.execute(
"create or replace table "
+ table2
+ "(C1 int primary key, C2 string, C3 int references "
+ table1
+ ")");

DatabaseMetaData dbmd = connection.getMetaData();

Expand Down Expand Up @@ -1824,12 +1837,25 @@ public void testPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcepti
assertEquals(1, getSizeOfResultSet(dbmd.getExportedKeys(database, null, "T%")));

// Should return result for matching schema and table name
assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, schema, table2)));
assertEquals(
1,
getSizeOfResultSet(
dbmd.getCrossReference(database, schema, table1, database, schema, table2)));

// Should return a result if we try a pattern match on any of the table or schema names
assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2)));
assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2)));
assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2)));
assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%")));
assertEquals(
1,
getSizeOfResultSet(
dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2)));
assertEquals(
1,
getSizeOfResultSet(
dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2)));
assertEquals(
1,
getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2)));
assertEquals(
1,
getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%")));
}
}

0 comments on commit 327d802

Please sign in to comment.