Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2420,13 +2420,11 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
final List<FieldValueList> collectedResults = Collections.synchronizedList(new ArrayList<>());
List<DatasetId> targetDatasets = getTargetDatasets(catalog, schema);

boolean ignoreAccessErrors = (catalog == null);
processTargetTablesConcurrently(
targetDatasets,
table,
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
(bqTable, results, fields) -> {
TableConstraints constraints = bqTable.getTableConstraints();
processPrimaryKey(constraints, bqTable.getTableId(), results, fields);
Expand Down Expand Up @@ -2517,13 +2515,11 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
final List<FieldValueList> collectedResults = Collections.synchronizedList(new ArrayList<>());
List<DatasetId> targetDatasets = getTargetDatasets(catalog, schema);

boolean ignoreAccessErrors = (catalog == null);
processTargetTablesConcurrently(
targetDatasets,
table,
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
(bqTable, results, fields) -> {
TableConstraints constraints = bqTable.getTableConstraints();
if (constraints == null || constraints.getForeignKeys() == null) {
Expand Down Expand Up @@ -2562,13 +2558,11 @@ public ResultSet getExportedKeys(String catalog, String schema, String table)
final List<FieldValueList> collectedResults = Collections.synchronizedList(new ArrayList<>());
List<DatasetId> targetDatasets = getTargetDatasets(catalog, null);

boolean ignoreAccessErrors = (catalog == null);
processTargetTablesConcurrently(
targetDatasets,
null,
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
(bqTable, results, fields) -> {
TableConstraints constraints = bqTable.getTableConstraints();
if (constraints == null || constraints.getForeignKeys() == null) {
Expand Down Expand Up @@ -2623,13 +2617,11 @@ public ResultSet getCrossReference(
final List<FieldValueList> collectedResults = Collections.synchronizedList(new ArrayList<>());
List<DatasetId> targetDatasets = getTargetDatasets(foreignCatalog, foreignSchema);

boolean ignoreAccessErrors = (foreignCatalog == null);
processTargetTablesConcurrently(
targetDatasets,
foreignTable,
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
(bqTable, results, fields) -> {
TableConstraints constraints = bqTable.getTableConstraints();
if (constraints == null || constraints.getForeignKeys() == null) {
Expand Down Expand Up @@ -4672,7 +4664,8 @@ <T> List<T> findMatchingBigQueryObjects(
}

} catch (BigQueryException e) {
if (!needsList && e.getCode() == 404) {
boolean isBroadDatasetScan = needsList && "Dataset".equals(objectTypeName);
if (e.getCode() == 404 && !isBroadDatasetScan) {
logger.info("%s '%s' not found (API error 404).", objectTypeName, pattern);
} else {
logger.warning(
Expand Down Expand Up @@ -5146,18 +5139,17 @@ private void processSingleTable(
String tableName,
List<FieldValueList> collectedResults,
FieldList resultSchemaFields,
boolean ignoreAccessErrors,
TableProcessor processor)
throws SQLException {
Table bqTable;
try {
bqTable =
bigquery.getTable(TableId.of(datasetId.getProject(), datasetId.getDataset(), tableName));
} catch (BigQueryException e) {
if (ignoreAccessErrors && (e.getCode() == 404 || e.getCode() == 403)) {
if (e.getCode() == 404) {
LOG.info(
"Table '%s' or dataset '%s' not found/accessible in project '%s' (API error %d). Skipping.",
tableName, datasetId.getDataset(), datasetId.getProject(), e.getCode());
"Table '%s' or dataset '%s' not found in project '%s' (API error 404). Skipping.",
tableName, datasetId.getDataset(), datasetId.getProject());
bqTable = null;
} else {
throw new SQLException("Error while fetching table metadata: " + e.getMessage(), e);
Expand All @@ -5175,17 +5167,11 @@ private void processTargetTablesConcurrently(
String tableName,
List<FieldValueList> collectedResults,
FieldList resultSchemaFields,
boolean ignoreAccessErrors,
TableProcessor processor)
throws SQLException {
if (targetDatasets.size() == 1 && tableName != null) {
processSingleTable(
targetDatasets.get(0),
tableName,
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
processor);
targetDatasets.get(0), tableName, collectedResults, resultSchemaFields, processor);
Comment thread
keshavdandeva marked this conversation as resolved.
return;
}

Expand All @@ -5199,12 +5185,7 @@ private void processTargetTablesConcurrently(
tasks.add(
() -> {
processSingleTable(
datasetId,
tableName,
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
processor);
datasetId, tableName, collectedResults, resultSchemaFields, processor);
Comment thread
keshavdandeva marked this conversation as resolved.
return null;
});
continue;
Expand All @@ -5228,16 +5209,15 @@ private void processTargetTablesConcurrently(
table.getTableId().getTable(),
collectedResults,
resultSchemaFields,
ignoreAccessErrors,
processor);
return null;
});
}
} catch (BigQueryException e) {
if (ignoreAccessErrors && (e.getCode() == 404 || e.getCode() == 403)) {
if (e.getCode() == 404) {
LOG.info(
"Dataset '%s' not found/accessible in project '%s' (API error %d). Skipping.",
datasetId.getDataset(), datasetId.getProject(), e.getCode());
"Dataset '%s' not found in project '%s' (API error 404). Skipping.",
datasetId.getDataset(), datasetId.getProject());
continue;
}
throw new SQLException("Error while listing tables: " + e.getMessage(), e);
Expand Down
Loading