in ingestion-core/src/main/java/com/mozilla/telemetry/ingestion/core/schema/BigQuerySchemaStore.java [84:112]
public Schema getSchema(TableId tableId, Map<String, String> attributes) {
if (tableId == null) {
// Always throws SchemaNotFoundException
return getSchema(attributes);
}
if (tableSchemaCache == null) {
// We need to be very careful about settings for the cache here. We have had significant
// issues in the past due to exceeding limits on BigQuery API requests; see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1623000
tableSchemaCache = CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(10))
.build();
}
if (bqService == null) {
bqService = BigQueryOptions.newBuilder().setProjectId(tableId.getProject())
.setRetrySettings(RETRY_SETTINGS).build().getService();
}
try {
return Optional.of(tableSchemaCache.get(tableId, () -> {
Table table = bqService.getTable(tableId);
if (table != null) {
return table.getDefinition().getSchema();
} else {
return null;
}
})).orElseThrow(() -> SchemaNotFoundException.forName(tableId.toString()));
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e.getCause());
}
}