Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class BaseJdbcClient
protected final boolean caseInsensitiveNameMatching;
protected final Cache<JdbcIdentity, Map<String, String>> remoteSchemaNames;
protected final Cache<RemoteTableNameCacheKey, Map<String, String>> remoteTableNames;
protected final Set<String> listSchemasIgnoredSchemas;

public BaseJdbcClient(JdbcConnectorId connectorId, BaseJdbcConfig config, String identifierQuote, ConnectionFactory connectionFactory)
{
Expand All @@ -130,6 +131,7 @@ public BaseJdbcClient(JdbcConnectorId connectorId, BaseJdbcConfig config, String
.expireAfterWrite(config.getCaseInsensitiveNameMatchingCacheTtl().toMillis(), MILLISECONDS);
this.remoteSchemaNames = remoteNamesCacheBuilder.build();
this.remoteTableNames = remoteNamesCacheBuilder.build();
this.listSchemasIgnoredSchemas = config.getlistSchemasIgnoredSchemas();
}

@PreDestroy
Expand Down Expand Up @@ -165,7 +167,7 @@ protected Collection<String> listSchemas(Connection connection)
while (resultSet.next()) {
String schemaName = resultSet.getString("TABLE_SCHEM");
// skip internal schemas
if (!schemaName.equalsIgnoreCase("information_schema")) {
if (!listSchemasIgnoredSchemas.contains(schemaName.toLowerCase(ENGLISH))) {
schemaNames.add(schemaName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

import com.facebook.airlift.configuration.Config;
import com.facebook.airlift.configuration.ConfigSecuritySensitive;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import io.airlift.units.Duration;
import io.airlift.units.MinDuration;

import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;

import java.util.Set;

import static java.util.Locale.ENGLISH;
import static java.util.concurrent.TimeUnit.MINUTES;

public class BaseJdbcConfig
Expand All @@ -32,6 +37,7 @@ public class BaseJdbcConfig
private String passwordCredentialName;
private boolean caseInsensitiveNameMatching;
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES);
private Set<String> listSchemasIgnoredSchemas = ImmutableSet.of("information_schema");

@NotNull
public String getConnectionUrl()
Expand Down Expand Up @@ -124,4 +130,16 @@ public BaseJdbcConfig setCaseInsensitiveNameMatchingCacheTtl(Duration caseInsens
this.caseInsensitiveNameMatchingCacheTtl = caseInsensitiveNameMatchingCacheTtl;
return this;
}

public Set<String> getlistSchemasIgnoredSchemas()
{
return listSchemasIgnoredSchemas;
}

@Config("list-schemas-ignored-schemas")
public BaseJdbcConfig setlistSchemasIgnoredSchemas(String listSchemasIgnoredSchemas)
{
this.listSchemasIgnoredSchemas = ImmutableSet.copyOf(Splitter.on(",").trimResults().omitEmptyStrings().split(listSchemasIgnoredSchemas.toLowerCase(ENGLISH)));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public void testDefaults()
.setUserCredentialName(null)
.setPasswordCredentialName(null)
.setCaseInsensitiveNameMatching(false)
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, MINUTES)));
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, MINUTES))
.setlistSchemasIgnoredSchemas("information_schema"));
}

@Test
Expand All @@ -49,6 +50,7 @@ public void testExplicitPropertyMappings()
.put("password-credential-name", "bar")
.put("case-insensitive-name-matching", "true")
.put("case-insensitive-name-matching.cache-ttl", "1s")
.put("list-schemas-ignored-schemas", "test,test2")
.build();

BaseJdbcConfig expected = new BaseJdbcConfig()
Expand All @@ -58,6 +60,7 @@ public void testExplicitPropertyMappings()
.setUserCredentialName("foo")
.setPasswordCredentialName("bar")
.setCaseInsensitiveNameMatching(true)
.setlistSchemasIgnoredSchemas("test,test2")
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, SECONDS));

ConfigAssertions.assertFullMapping(properties, expected);
Expand Down
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/hana.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Property Name Description

``case-insensitive-name-matching.cache-ttl`` Duration for which remote dataset and table names will be
cached. Set to ``0ms`` to disable the cache. ``1m``

``list-schemas-ignored-schemas`` List of schemas to ignore when listing schemas. ``information_schema``
================================================== ==================================================================== ===========

Querying HANA
Expand Down
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/mysql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Property Name Description

``case-insensitive-name-matching.cache-ttl`` Duration for which remote dataset and table names will be
cached. Set to ``0ms`` to disable the cache. ``1m``

``list-schemas-ignored-schemas`` List of schemas to ignore when listing schemas. ``information_schema,mysql``
================================================== ==================================================================== ===========

Querying MySQL
Expand Down
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/oracle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Property Name Description

``case-insensitive-name-matching.cache-ttl`` Duration for which remote dataset and table names will be
cached. Set to ``0ms`` to disable the cache. ``1m``

``list-schemas-ignored-schemas`` List of schemas to ignore when listing schemas. ``information_schema``
================================================== ==================================================================== ===========

Querying Oracle
Expand Down
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/postgresql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Property Name Description

``case-insensitive-name-matching.cache-ttl`` Duration for which remote dataset and table names will be
cached. Set to ``0ms`` to disable the cache. ``1m``

``list-schemas-ignored-schemas`` List of schemas to ignore when listing schemas. ``information_schema``
================================================== ==================================================================== ===========

Querying PostgreSQL
Expand Down
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/redshift.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Property Name Description

``case-insensitive-name-matching.cache-ttl`` Duration for which remote dataset and table names will be
cached. Set to ``0ms`` to disable the cache. ``1m``

``list-schemas-ignored-schemas`` List of schemas to ignore when listing schemas. ``information_schema``
================================================== ==================================================================== ===========

Querying Redshift
Expand Down
3 changes: 3 additions & 0 deletions presto-docs/src/main/sphinx/connector/singlestore.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ available in the `SingleStore Connection String Parameters
The ``connection-user`` and ``connection-password`` are typically required and
determine the user credentials for the connection, often a service user.

An optional ``list-schemas-ignored-schemas`` config can be set to ignore certain schemas
when listing schemas. The default value for this is ``information_schema,memsql``.

Multiple SingleStore Servers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/sqlserver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Property Name Description

``case-insensitive-name-matching.cache-ttl`` Duration for which remote dataset and table names will be
cached. Set to ``0ms`` to disable the cache. ``1m``

``list-schemas-ignored-schemas`` List of schemas to ignore when listing schemas. ``information_schema``
================================================== ==================================================================== ===========

Querying SQL Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected Collection<String> listSchemas(Connection connection)
while (resultSet.next()) {
String schemaName = resultSet.getString("TABLE_CAT");
// skip internal schemas
if (!schemaName.equalsIgnoreCase("information_schema") && !schemaName.equalsIgnoreCase("mysql")) {
if (!listSchemasIgnoredSchemas.contains(schemaName.toLowerCase(ENGLISH))) {
schemaNames.add(schemaName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class MySqlClientModule
protected void setup(Binder binder)
{
binder.bind(JdbcClient.class).to(MySqlClient.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfigDefaults(BaseJdbcConfig.class, baseJdbcConfig -> {
baseJdbcConfig.setlistSchemasIgnoredSchemas("information_schema,mysql");
});
ensureCatalogIsEmpty(buildConfigObject(BaseJdbcConfig.class).getConnectionUrl());
configBinder(binder).bindConfig(MySqlConfig.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public void testDropTable()
assertFalse(getQueryRunner().tableExists(getSession(), "test_drop"));
}

@Test
public void testIgnoredSchemas()
{
MaterializedResult actual = computeActual("SHOW SCHEMAS");
assertFalse(actual.getMaterializedRows().stream().anyMatch(schemaResult -> schemaResult.getField(0).equals("mysql")));
}

@Test
public void testViews()
throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ protected Collection<String> listSchemas(Connection connection)
while (resultSet.next()) {
String schemaName = resultSet.getString("TABLE_CAT");
// skip internal schemas
if (!schemaName.equalsIgnoreCase("information_schema") && !schemaName.equalsIgnoreCase("memsql")
&& !schemaName.equalsIgnoreCase("cluster")) {
if (!listSchemasIgnoredSchemas.contains(schemaName.toLowerCase(ENGLISH))) {
schemaNames.add(schemaName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class SingleStoreClientModule
protected void setup(Binder binder)
{
binder.bind(JdbcClient.class).to(SingleStoreClient.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfigDefaults(BaseJdbcConfig.class, baseJdbcConfig -> {
baseJdbcConfig.setlistSchemasIgnoredSchemas("information_schema,memsql");
});
configBinder(binder).bindConfig(BaseJdbcConfig.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ public void testInsertIntoNotNullColumn()
assertUpdate("DROP TABLE test_insert_not_null");
}

@Test
public void testIgnoredSchemas()
{
MaterializedResult actual = computeActual("SHOW SCHEMAS");
assertFalse(actual.getMaterializedRows().stream().anyMatch(schemaResult -> schemaResult.getField(0).equals("memsql")));
}

@Test
public void testColumnComment()
throws Exception
Expand Down
Loading