4545import com .google .cloud .bigquery .StandardSQLField ;
4646import com .google .cloud .bigquery .StandardSQLTableType ;
4747import com .google .cloud .bigquery .StandardSQLTypeName ;
48- import com .google .cloud .bigquery .StandardTableDefinition ;
4948import com .google .cloud .bigquery .Table ;
5049import com .google .cloud .bigquery .TableConstraints ;
5150import com .google .cloud .bigquery .TableDefinition ;
@@ -2530,7 +2529,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
25302529 || table == null
25312530 || table .isEmpty ()) {
25322531 LOG .warning (
2533- "Returning empty ResultSet as one or more patterns are empty or catalog is empty." );
2532+ "Returning empty ResultSet as required parameters are null/ empty, or catalog/schema parameters are empty." );
25342533 return new BigQueryJsonResultSet ();
25352534 }
25362535
@@ -2600,7 +2599,7 @@ public ResultSet getCrossReference(
26002599 || foreignTable == null
26012600 || foreignTable .isEmpty ()) {
26022601 LOG .warning (
2603- "Returning empty ResultSet as one or more patterns are empty or catalog is empty." );
2602+ "Returning empty ResultSet as required parameters are null/ empty, or catalog/schema parameters are empty." );
26042603 return new BigQueryJsonResultSet ();
26052604 }
26062605
@@ -2622,8 +2621,8 @@ public ResultSet getCrossReference(
26222621 if (constraints != null && constraints .getForeignKeys () != null ) {
26232622 for (ForeignKey fk : constraints .getForeignKeys ()) {
26242623 TableId pkTableId = fk .getReferencedTable ();
2625- if (matchesOrNullWildcard (parentCatalog , pkTableId .getProject ())
2626- && matchesOrNullWildcard (parentSchema , pkTableId .getDataset ())
2624+ if (equalsOrNullMatchesAll (parentCatalog , pkTableId .getProject ())
2625+ && equalsOrNullMatchesAll (parentSchema , pkTableId .getDataset ())
26272626 && parentTable .equals (pkTableId .getTable ())) {
26282627 processForeignKey (fk , pkTableId , bqTable .getTableId (), results , fields );
26292628 }
@@ -5060,7 +5059,7 @@ private List<String> getAccessibleCatalogNames() throws SQLException {
50605059 return sortedCatalogs ;
50615060 }
50625061
5063- private boolean matchesOrNullWildcard (String expected , String actual ) {
5062+ private boolean equalsOrNullMatchesAll (String expected , String actual ) {
50645063 return expected == null || expected .equals (actual );
50655064 }
50665065
@@ -5212,6 +5211,7 @@ private void processTargetTablesConcurrently(
52125211 taskFutures .forEach (future -> future .cancel (true ));
52135212 }
52145213 }
5214+
52155215 private Schema defineForeignKeyResultSetSchema () {
52165216 return Schema .of (
52175217 Field .of ("PKTABLE_CAT" , StandardSQLTypeName .STRING ),
@@ -5236,6 +5236,13 @@ private void processForeignKey(
52365236 TableId fkTableId ,
52375237 List <FieldValueList > collectedResults ,
52385238 FieldList resultSchemaFields ) {
5239+ if (pkTableId == null ) {
5240+ LOG .warning (
5241+ String .format (
5242+ "Skipping foreign key '%s' on table '%s' because its referenced table ID is null." ,
5243+ fk .getName () != null ? fk .getName () : "unnamed" , fkTableId .getTable ()));
5244+ return ;
5245+ }
52395246 List <ColumnReference > colRefs = fk .getColumnReferences ();
52405247 if (colRefs != null ) {
52415248 for (int i = 0 ; i < colRefs .size (); i ++) {
0 commit comments