Skip to content

Commit 41be8e3

Browse files
committed
Fix information_schema query failures in BigQuery connector
In 212e1bb the toRemoteTable method called listTables unconditionally instead of returning early if case-insensitive name matching is not enabled. That caused query failures for information_schema queries because instead of an early return it tried to list tables in a remote schema called `information_schema` (which isn't intended). This change fixes the issue by making the listTables call lazy by using a Supplier instead of a materialized iterable.
1 parent 0dfafc8 commit 41be8e3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.Map;
4242
import java.util.Optional;
4343
import java.util.Set;
44+
import java.util.function.Supplier;
4445

4546
import static com.google.cloud.bigquery.TableDefinition.Type.TABLE;
4647
import static com.google.cloud.bigquery.TableDefinition.Type.VIEW;
@@ -113,10 +114,15 @@ Optional<RemoteDatabaseObject> toRemoteDataset(String projectId, String datasetN
113114

114115
Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName)
115116
{
116-
return toRemoteTable(projectId, remoteDatasetName, tableName, listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW));
117+
return toRemoteTable(projectId, remoteDatasetName, tableName, () -> listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW));
117118
}
118119

119120
Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName, Iterable<Table> tables)
121+
{
122+
return toRemoteTable(projectId, remoteDatasetName, tableName, () -> tables);
123+
}
124+
125+
private Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName, Supplier<Iterable<Table>> tables)
120126
{
121127
requireNonNull(projectId, "projectId is null");
122128
requireNonNull(remoteDatasetName, "remoteDatasetName is null");
@@ -134,7 +140,7 @@ Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteData
134140

135141
// cache miss, reload the cache
136142
Map<TableId, Optional<RemoteDatabaseObject>> mapping = new HashMap<>();
137-
for (Table table : tables) {
143+
for (Table table : tables.get()) {
138144
mapping.merge(
139145
tableIdToLowerCase(table.getTableId()),
140146
Optional.of(RemoteDatabaseObject.of(table.getTableId().getTable())),

0 commit comments

Comments
 (0)