-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dataset cache to BigQuery connector
When caseInsensitiveNameMatching=true, the BigQueryClient makes a call to listDatasets for each call on toRemoteDataset. This is problematic when running queries like SHOW SCHEMAS since listDatasets is called once to get the initial list, then once again for each schema. This is expensive if the BigQuery project has a large number of datasets. This commit adds a cache to listing datasets to drastically reduce the query time for SHOW SCHEMAS.
- Loading branch information
1 parent
c7e0ecc
commit b69938f
Showing
7 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...in/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryMetadataCaching.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.plugin.bigquery; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.trino.testing.AbstractTestQueryFramework; | ||
import io.trino.testing.QueryRunner; | ||
import org.testng.annotations.Test; | ||
|
||
import static io.trino.plugin.bigquery.BigQueryQueryRunner.BigQuerySqlExecutor; | ||
import static io.trino.testing.sql.TestTable.randomTableSuffix; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
public class TestBigQueryMetadataCaching | ||
extends AbstractTestQueryFramework | ||
{ | ||
protected BigQuerySqlExecutor bigQuerySqlExecutor; | ||
|
||
@Override | ||
protected QueryRunner createQueryRunner() | ||
throws Exception | ||
{ | ||
this.bigQuerySqlExecutor = new BigQuerySqlExecutor(); | ||
return BigQueryQueryRunner.createQueryRunner( | ||
ImmutableMap.of(), | ||
ImmutableMap.of("bigquery.metadata.cache-ttl", "5m")); | ||
} | ||
|
||
@Test | ||
public void testMetadataCaching() | ||
{ | ||
String schema = "test_metadata_caching_" + randomTableSuffix(); | ||
try { | ||
getQueryRunner().execute("CREATE SCHEMA " + schema); | ||
assertEquals(getQueryRunner().execute("SHOW SCHEMAS IN bigquery LIKE '" + schema + "'").getOnlyValue(), schema); | ||
|
||
String schemaTableName = schema + ".test_metadata_caching"; | ||
getQueryRunner().execute("CREATE TABLE " + schemaTableName + " AS SELECT * FROM tpch.tiny.region"); | ||
assertEquals(getQueryRunner().execute("SELECT * FROM " + schemaTableName).getRowCount(), 5); | ||
|
||
bigQuerySqlExecutor.execute("DROP SCHEMA " + schema + " CASCADE"); | ||
assertEquals(getQueryRunner().execute("SHOW SCHEMAS IN bigquery LIKE '" + schema + "'").getOnlyValue(), schema); | ||
|
||
assertQueryFails("SELECT * FROM " + schemaTableName, ".*Schema '.+' does not exist.*"); | ||
} | ||
finally { | ||
bigQuerySqlExecutor.execute("DROP SCHEMA IF EXISTS " + schema + " CASCADE"); | ||
} | ||
} | ||
} |