Skip to content

Commit be0fd22

Browse files
committed
add sqlexception handling and proper cancellation
1 parent 3af7ff2 commit be0fd22

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5078,8 +5078,13 @@ private void processSingleTable(
50785078
FieldList resultSchemaFields,
50795079
TableProcessor processor)
50805080
throws SQLException {
5081-
Table bqTable =
5082-
bigquery.getTable(TableId.of(datasetId.getProject(), datasetId.getDataset(), tableName));
5081+
Table bqTable;
5082+
try {
5083+
bqTable =
5084+
bigquery.getTable(TableId.of(datasetId.getProject(), datasetId.getDataset(), tableName));
5085+
} catch (Exception e) {
5086+
throw new SQLException("Error while fetching table metadata: " + e.getMessage(), e);
5087+
}
50835088
if (bqTable != null && bqTable.getDefinition() != null) {
50845089
processor.process(bqTable, collectedResults, resultSchemaFields);
50855090
}
@@ -5101,20 +5106,21 @@ private void processTargetTablesConcurrently(
51015106
ExecutorService executor = connection.getMetadataExecutor();
51025107
List<Future<?>> taskFutures = new ArrayList<>();
51035108

5104-
for (DatasetId datasetId : targetDatasets) {
5105-
taskFutures.add(
5106-
executor.submit(
5107-
() -> {
5108-
processSingleTable(
5109-
datasetId, tableName, collectedResults, resultSchemaFields, processor);
5110-
return null;
5111-
}));
5112-
}
5113-
51145109
try {
5110+
for (DatasetId datasetId : targetDatasets) {
5111+
taskFutures.add(
5112+
executor.submit(
5113+
() -> {
5114+
processSingleTable(
5115+
datasetId, tableName, collectedResults, resultSchemaFields, processor);
5116+
return null;
5117+
}));
5118+
}
51155119
waitForTasksCompletion(taskFutures);
51165120
} catch (ExecutionException e) {
51175121
throw new SQLException("Error while fetching metadata", e);
5122+
} finally {
5123+
taskFutures.forEach(future -> future.cancel(true));
51185124
}
51195125
}
51205126
}

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ public void testBigqueryDatabaseMetaDataGetters() throws SQLException {
159159
assertEquals("Project", dbMetadata.getCatalogTerm());
160160
}
161161

162-
163162
@Test
164163
public void testNeedsListing() {
165164
assertTrue(dbMetadata.needsListing(null), "Null pattern should require listing");
@@ -3233,7 +3232,6 @@ public void testWrapperMethods() throws SQLException {
32333232
assertThat((Throwable) e).hasMessageThat().contains("Cannot unwrap to java.sql.Connection");
32343233
}
32353234

3236-
32373235
@ParameterizedTest
32383236
@EnumSource(StandardSQLTypeName.class)
32393237
public void testMetadataAndResultSetMetadataTypeMappingConsistency(StandardSQLTypeName type) {

0 commit comments

Comments
 (0)