Skip to content

Commit 212e1bb

Browse files
committed
Fasten listing tables in BigQuery connector
1 parent 714e70e commit 212e1bb

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

plugin/trino-bigquery/src/main/java/io/trino/plugin/bigquery/BigQueryClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ Optional<RemoteDatabaseObject> toRemoteDataset(String projectId, String datasetN
112112
}
113113

114114
Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName)
115+
{
116+
return toRemoteTable(projectId, remoteDatasetName, tableName, listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW));
117+
}
118+
119+
Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName, Iterable<Table> tables)
115120
{
116121
requireNonNull(projectId, "projectId is null");
117122
requireNonNull(remoteDatasetName, "remoteDatasetName is null");
@@ -129,7 +134,7 @@ Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteData
129134

130135
// cache miss, reload the cache
131136
Map<TableId, Optional<RemoteDatabaseObject>> mapping = new HashMap<>();
132-
for (Table table : listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW)) {
137+
for (Table table : tables) {
133138
mapping.merge(
134139
tableIdToLowerCase(table.getTableId()),
135140
Optional.of(RemoteDatabaseObject.of(table.getTableId().getTable())),

plugin/trino-bigquery/src/main/java/io/trino/plugin/bigquery/BigQueryMetadata.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ public List<SchemaTableName> listTables(ConnectorSession session, Optional<Strin
144144

145145
ImmutableList.Builder<SchemaTableName> tableNames = ImmutableList.builder();
146146
for (String remoteSchemaName : remoteSchemaNames) {
147-
for (Table table : bigQueryClient.listTables(DatasetId.of(projectId, remoteSchemaName), TABLE, VIEW)) {
147+
Iterable<Table> tables = bigQueryClient.listTables(DatasetId.of(projectId, remoteSchemaName), TABLE, VIEW);
148+
for (Table table : tables) {
148149
// filter ambiguous tables
149-
boolean isAmbiguous = bigQueryClient.toRemoteTable(projectId, remoteSchemaName, table.getTableId().getTable().toLowerCase(ENGLISH))
150+
boolean isAmbiguous = bigQueryClient.toRemoteTable(projectId, remoteSchemaName, table.getTableId().getTable().toLowerCase(ENGLISH), tables)
150151
.filter(RemoteDatabaseObject::isAmbiguous)
151152
.isPresent();
152153
if (!isAmbiguous) {

0 commit comments

Comments
 (0)