Skip to content

Commit

Permalink
Fix information_schema query failures in BigQuery connector
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hashhar committed May 4, 2021
1 parent 0dfafc8 commit 41be8e3
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -41,6 +41,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

import static com.google.cloud.bigquery.TableDefinition.Type.TABLE;
import static com.google.cloud.bigquery.TableDefinition.Type.VIEW;
Expand Down Expand Up @@ -113,10 +114,15 @@ 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));
return toRemoteTable(projectId, remoteDatasetName, tableName, () -> listTables(DatasetId.of(projectId, remoteDatasetName), TABLE, VIEW));
}

Optional<RemoteDatabaseObject> toRemoteTable(String projectId, String remoteDatasetName, String tableName, Iterable<Table> tables)
{
return toRemoteTable(projectId, remoteDatasetName, tableName, () -> tables);
}

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

// cache miss, reload the cache
Map<TableId, Optional<RemoteDatabaseObject>> mapping = new HashMap<>();
for (Table table : tables) {
for (Table table : tables.get()) {
mapping.merge(
tableIdToLowerCase(table.getTableId()),
Optional.of(RemoteDatabaseObject.of(table.getTableId().getTable())),
Expand Down

0 comments on commit 41be8e3

Please sign in to comment.