Skip to content

Commit f7eb23d

Browse files
fix(bigquery-jdbc): correct FilterTablesOnDefaultDataset fallback logic (#13625)
b/530193573 This PR fixes two compliance issues with how the driver handles JDBC metadata when `FilterTablesOnDefaultDataset=1` is enabled: 1. Updated `determineEffectiveCatalogAndSchema` to strictly follow the specification matrix. - Empty strings (`""`) no longer incorrectly trigger the fallback. - Wildcards (`"%"`) correctly trigger the fallback alongside `null`. - Properly normalize the `effectiveCatalog` to `null`, ensuring the driver correctly searches for the specified dataset across *all* accessible projects rather than incorrectly restricting to the default project. 2. Moved the `.isEmpty()` checks in `getTables()` and `getColumns()` to the very top of the methods.
1 parent 3a9d5d7 commit f7eb23d

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,19 +1548,19 @@ Comparator<FieldValueList> defineGetProcedureColumnsComparator(FieldList resultS
15481548
public ResultSet getTables(
15491549
String catalog, String schemaPattern, String tableNamePattern, String[] types) {
15501550

1551-
Tuple<String, String> effectiveIdentifiers =
1552-
determineEffectiveCatalogAndSchema(catalog, schemaPattern);
1553-
String effectiveCatalog = effectiveIdentifiers.x();
1554-
String effectiveSchemaPattern = effectiveIdentifiers.y();
1555-
1556-
if ((effectiveCatalog != null && effectiveCatalog.isEmpty())
1557-
|| (effectiveSchemaPattern != null && effectiveSchemaPattern.isEmpty())
1551+
if ((catalog != null && catalog.isEmpty())
1552+
|| (schemaPattern != null && schemaPattern.isEmpty())
15581553
|| (tableNamePattern != null && tableNamePattern.isEmpty())) {
15591554
LOG.warning(
15601555
"Returning empty ResultSet as one or more patterns are empty or catalog is empty.");
15611556
return new BigQueryJsonResultSet();
15621557
}
15631558

1559+
Tuple<String, String> effectiveIdentifiers =
1560+
determineEffectiveCatalogAndSchema(catalog, schemaPattern);
1561+
String effectiveCatalog = effectiveIdentifiers.x();
1562+
String effectiveSchemaPattern = effectiveIdentifiers.y();
1563+
15641564
LOG.info(
15651565
"getTables called for catalog: %s, schemaPattern: %s, tableNamePattern: %s, types: %s",
15661566
effectiveCatalog, effectiveSchemaPattern, tableNamePattern, Arrays.toString(types));
@@ -1865,20 +1865,20 @@ static List<FieldValueList> prepareGetTableTypesRows(Schema schema) {
18651865
public ResultSet getColumns(
18661866
String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) {
18671867

1868-
Tuple<String, String> effectiveIdentifiers =
1869-
determineEffectiveCatalogAndSchema(catalog, schemaPattern);
1870-
String effectiveCatalog = effectiveIdentifiers.x();
1871-
String effectiveSchemaPattern = effectiveIdentifiers.y();
1872-
1873-
if ((effectiveCatalog != null && effectiveCatalog.isEmpty())
1874-
|| (effectiveSchemaPattern != null && effectiveSchemaPattern.isEmpty())
1868+
if ((catalog != null && catalog.isEmpty())
1869+
|| (schemaPattern != null && schemaPattern.isEmpty())
18751870
|| (tableNamePattern != null && tableNamePattern.isEmpty())
18761871
|| (columnNamePattern != null && columnNamePattern.isEmpty())) {
18771872
LOG.warning(
18781873
"Returning empty ResultSet as one or more patterns are empty or catalog is empty.");
18791874
return new BigQueryJsonResultSet();
18801875
}
18811876

1877+
Tuple<String, String> effectiveIdentifiers =
1878+
determineEffectiveCatalogAndSchema(catalog, schemaPattern);
1879+
String effectiveCatalog = effectiveIdentifiers.x();
1880+
String effectiveSchemaPattern = effectiveIdentifiers.y();
1881+
18821882
LOG.info(
18831883
"getColumns called for catalog: %s, schemaPattern: %s, tableNamePattern: %s,"
18841884
+ " columnNamePattern: %s",
@@ -4429,28 +4429,25 @@ private Tuple<String, String> determineEffectiveCatalogAndSchema(
44294429
// We only use the dataset part of the DefaultDataset for schema filtering
44304430
String defaultSchemaFromConnection = this.connection.getDefaultDataset().getDataset();
44314431

4432-
boolean catalogIsNullOrEmptyOrWildcard =
4433-
(catalog == null || catalog.isEmpty() || catalog.equals("%"));
4434-
boolean schemaPatternIsNullOrEmptyOrWildcard =
4435-
(schemaPattern == null || schemaPattern.isEmpty() || schemaPattern.equals("%"));
4432+
boolean catalogIsUnspecified = (effectiveCatalog == null || effectiveCatalog.equals("%"));
4433+
boolean schemaIsUnspecified =
4434+
(effectiveSchemaPattern == null || effectiveSchemaPattern.equals("%"));
44364435

44374436
final String logPrefix = "FilterTablesOnDefaultDatasetTrue: ";
4438-
if (catalogIsNullOrEmptyOrWildcard && schemaPatternIsNullOrEmptyOrWildcard) {
4437+
if (catalogIsUnspecified && schemaIsUnspecified) {
44394438
effectiveCatalog = defaultProjectFromConnection;
44404439
effectiveSchemaPattern = defaultSchemaFromConnection;
44414440
LOG.info(
44424441
logPrefix + "Using default catalog '%s' and default dataset '%s'.",
44434442
effectiveCatalog,
44444443
effectiveSchemaPattern);
4445-
} else if (catalogIsNullOrEmptyOrWildcard) {
4446-
effectiveCatalog = defaultProjectFromConnection;
4444+
} else if (catalogIsUnspecified) {
4445+
effectiveCatalog = null;
44474446
LOG.info(
4448-
logPrefix
4449-
+ "Using default catalog '%s' with user dataset '%s'. Default dataset '%s' ignored.",
4450-
effectiveCatalog,
4447+
logPrefix + "Using all catalogs with user dataset '%s'. Default dataset '%s' ignored.",
44514448
effectiveSchemaPattern,
44524449
defaultSchemaFromConnection);
4453-
} else if (schemaPatternIsNullOrEmptyOrWildcard) {
4450+
} else if (schemaIsUnspecified) {
44544451
effectiveSchemaPattern = defaultSchemaFromConnection;
44554452
LOG.info(
44564453
logPrefix + "Using user catalog '%s' and default dataset '%s'.",

0 commit comments

Comments
 (0)