Skip to content

Commit

Permalink
Fasten listing tables in BigQuery connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Apr 18, 2021
1 parent 714e70e commit 212e1bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Expand Up @@ -112,6 +112,11 @@ Optional<RemoteDatabaseObject> toRemoteDataset(String projectId, String datasetN
}

Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName)
{
return toRemoteTable(projectId, remoteDatasetName, tableName, listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW));
}

Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName, Iterable<Table> tables)
{
requireNonNull(projectId, "projectId is null");
requireNonNull(remoteDatasetName, "remoteDatasetName is null");
Expand All @@ -129,7 +134,7 @@ Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteData

// cache miss, reload the cache
Map<TableId, Optional<RemoteDatabaseObject>> mapping = new HashMap<>();
for (Table table : listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW)) {
for (Table table : tables) {
mapping.merge(
tableIdToLowerCase(table.getTableId()),
Optional.of(RemoteDatabaseObject.of(table.getTableId().getTable())),
Expand Down
Expand Up @@ -144,9 +144,10 @@ public List<SchemaTableName> listTables(ConnectorSession session, Optional<Strin

ImmutableList.Builder<SchemaTableName> tableNames = ImmutableList.builder();
for (String remoteSchemaName : remoteSchemaNames) {
for (Table table : bigQueryClient.listTables(DatasetId.of(projectId, remoteSchemaName), TABLE, VIEW)) {
Iterable<Table> tables = bigQueryClient.listTables(DatasetId.of(projectId, remoteSchemaName), TABLE, VIEW);
for (Table table : tables) {
// filter ambiguous tables
boolean isAmbiguous = bigQueryClient.toRemoteTable(projectId, remoteSchemaName, table.getTableId().getTable().toLowerCase(ENGLISH))
boolean isAmbiguous = bigQueryClient.toRemoteTable(projectId, remoteSchemaName, table.getTableId().getTable().toLowerCase(ENGLISH), tables)
.filter(RemoteDatabaseObject::isAmbiguous)
.isPresent();
if (!isAmbiguous) {
Expand Down

0 comments on commit 212e1bb

Please sign in to comment.