Package io.trino.plugin.jdbc
Class BaseJdbcClient
- java.lang.Object
-
- io.trino.plugin.jdbc.BaseJdbcClient
-
- All Implemented Interfaces:
JdbcClient
public abstract class BaseJdbcClient extends Object implements JdbcClient
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancaseInsensitiveNameMatchingprotected ConnectionFactoryconnectionFactoryprotected StringidentifierQuoteprotected Set<String>jdbcTypesMappedToVarcharprotected com.google.common.cache.Cache<JdbcIdentity,Map<String,String>>remoteSchemaNamesprotected com.google.common.cache.Cache<io.trino.plugin.jdbc.RemoteTableNameCacheKey,Map<String,String>>remoteTableNames
-
Constructor Summary
Constructors Constructor Description BaseJdbcClient(BaseJdbcConfig config, String identifierQuote, ConnectionFactory connectionFactory)BaseJdbcClient(String identifierQuote, ConnectionFactory connectionFactory, Set<String> jdbcTypesMappedToVarchar, boolean caseInsensitiveNameMatching, io.airlift.units.Duration caseInsensitiveNameMatchingCacheTtl)
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.trino.plugin.jdbc.JdbcClient
abortReadConnection, getSystemTable, getTableScanRedirection, implementAggregation, schemaExists, setColumnComment, supportsAggregationPushdown, toColumnMapping, toWriteMapping
-
-
-
-
Field Detail
-
connectionFactory
protected final ConnectionFactory connectionFactory
-
identifierQuote
protected final String identifierQuote
-
caseInsensitiveNameMatching
protected final boolean caseInsensitiveNameMatching
-
remoteSchemaNames
protected final com.google.common.cache.Cache<JdbcIdentity,Map<String,String>> remoteSchemaNames
-
-
Constructor Detail
-
BaseJdbcClient
public BaseJdbcClient(BaseJdbcConfig config, String identifierQuote, ConnectionFactory connectionFactory)
-
BaseJdbcClient
public BaseJdbcClient(String identifierQuote, ConnectionFactory connectionFactory, Set<String> jdbcTypesMappedToVarchar, boolean caseInsensitiveNameMatching, io.airlift.units.Duration caseInsensitiveNameMatchingCacheTtl)
-
-
Method Detail
-
getSchemaNames
public final Set<String> getSchemaNames(ConnectorSession session)
- Specified by:
getSchemaNamesin interfaceJdbcClient
-
listSchemas
protected Collection<String> listSchemas(Connection connection)
-
filterSchema
protected boolean filterSchema(String schemaName)
-
getTableNames
public List<SchemaTableName> getTableNames(ConnectorSession session, Optional<String> schema)
- Specified by:
getTableNamesin interfaceJdbcClient
-
getTableHandle
public Optional<JdbcTableHandle> getTableHandle(ConnectorSession session, SchemaTableName schemaTableName)
- Specified by:
getTableHandlein interfaceJdbcClient
-
getColumns
public List<JdbcColumnHandle> getColumns(ConnectorSession session, JdbcTableHandle tableHandle)
- Specified by:
getColumnsin interfaceJdbcClient
-
getInteger
protected static Optional<Integer> getInteger(ResultSet resultSet, String columnLabel) throws SQLException
- Throws:
SQLException
-
getColumns
protected ResultSet getColumns(JdbcTableHandle tableHandle, DatabaseMetaData metadata) throws SQLException
- Throws:
SQLException
-
legacyToPrestoType
@Deprecated protected Optional<ColumnMapping> legacyToPrestoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle)
Deprecated.Each connector should provide its own explicit type mapping, along with respective tests.
-
toColumnMappings
public List<ColumnMapping> toColumnMappings(ConnectorSession session, List<JdbcTypeHandle> typeHandles)
Description copied from interface:JdbcClient- Specified by:
toColumnMappingsin interfaceJdbcClient
-
getForcedMappingToVarchar
protected Optional<ColumnMapping> getForcedMappingToVarchar(JdbcTypeHandle typeHandle)
-
mapToUnboundedVarchar
protected static Optional<ColumnMapping> mapToUnboundedVarchar(JdbcTypeHandle typeHandle)
-
getSplits
public ConnectorSplitSource getSplits(ConnectorSession session, JdbcTableHandle tableHandle)
- Specified by:
getSplitsin interfaceJdbcClient
-
getConnection
public Connection getConnection(ConnectorSession session, JdbcSplit split) throws SQLException
- Specified by:
getConnectionin interfaceJdbcClient- Throws:
SQLException
-
prepareQuery
public PreparedQuery prepareQuery(ConnectorSession session, JdbcTableHandle table, Optional<List<List<JdbcColumnHandle>>> groupingSets, List<JdbcColumnHandle> columns, Map<String,String> columnExpressions)
- Specified by:
prepareQueryin interfaceJdbcClient
-
buildSql
public PreparedStatement buildSql(ConnectorSession session, Connection connection, JdbcSplit split, JdbcTableHandle table, List<JdbcColumnHandle> columns) throws SQLException
- Specified by:
buildSqlin interfaceJdbcClient- Throws:
SQLException
-
createTable
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata)
- Specified by:
createTablein interfaceJdbcClient
-
beginCreateTable
public JdbcOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata)
- Specified by:
beginCreateTablein interfaceJdbcClient
-
createTable
protected JdbcOutputTableHandle createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, String tableName) throws SQLException
- Throws:
SQLException
-
createTableSql
protected String createTableSql(RemoteTableName remoteTableName, List<String> columns, ConnectorTableMetadata tableMetadata)
-
getColumnDefinitionSql
protected String getColumnDefinitionSql(ConnectorSession session, ColumnMetadata column, String columnName)
-
beginInsertTable
public JdbcOutputTableHandle beginInsertTable(ConnectorSession session, JdbcTableHandle tableHandle, List<JdbcColumnHandle> columns)
- Specified by:
beginInsertTablein interfaceJdbcClient
-
copyTableSchema
protected void copyTableSchema(Connection connection, String catalogName, String schemaName, String tableName, String newTableName, List<String> columnNames)
-
generateTemporaryTableName
protected String generateTemporaryTableName()
-
commitCreateTable
public void commitCreateTable(ConnectorSession session, JdbcOutputTableHandle handle)
- Specified by:
commitCreateTablein interfaceJdbcClient
-
renameTable
public void renameTable(ConnectorSession session, JdbcTableHandle handle, SchemaTableName newTableName)
- Specified by:
renameTablein interfaceJdbcClient
-
renameTable
protected void renameTable(ConnectorSession session, String catalogName, String schemaName, String tableName, SchemaTableName newTable)
-
finishInsertTable
public void finishInsertTable(ConnectorSession session, JdbcOutputTableHandle handle)
- Specified by:
finishInsertTablein interfaceJdbcClient
-
addColumn
public void addColumn(ConnectorSession session, JdbcTableHandle handle, ColumnMetadata column)
- Specified by:
addColumnin interfaceJdbcClient
-
renameColumn
public void renameColumn(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle jdbcColumn, String newColumnName)
- Specified by:
renameColumnin interfaceJdbcClient
-
dropColumn
public void dropColumn(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle column)
- Specified by:
dropColumnin interfaceJdbcClient
-
dropTable
public void dropTable(ConnectorSession session, JdbcTableHandle handle)
- Specified by:
dropTablein interfaceJdbcClient
-
rollbackCreateTable
public void rollbackCreateTable(ConnectorSession session, JdbcOutputTableHandle handle)
- Specified by:
rollbackCreateTablein interfaceJdbcClient
-
buildInsertSql
public String buildInsertSql(JdbcOutputTableHandle handle, List<WriteFunction> columnWriters)
- Specified by:
buildInsertSqlin interfaceJdbcClient
-
getConnection
public Connection getConnection(ConnectorSession session, JdbcOutputTableHandle handle) throws SQLException
- Specified by:
getConnectionin interfaceJdbcClient- Throws:
SQLException
-
getPreparedStatement
public PreparedStatement getPreparedStatement(Connection connection, String sql) throws SQLException
- Specified by:
getPreparedStatementin interfaceJdbcClient- Throws:
SQLException
-
getTables
protected ResultSet getTables(Connection connection, Optional<String> schemaName, Optional<String> tableName) throws SQLException
- Throws:
SQLException
-
getTableSchemaName
protected String getTableSchemaName(ResultSet resultSet) throws SQLException
- Throws:
SQLException
-
toRemoteSchemaName
protected String toRemoteSchemaName(JdbcIdentity identity, Connection connection, String schemaName)
-
listSchemasByLowerCase
protected Map<String,String> listSchemasByLowerCase(Connection connection)
-
toRemoteTableName
protected String toRemoteTableName(JdbcIdentity identity, Connection connection, String remoteSchema, String tableName)
-
listTablesByLowerCase
protected Map<String,String> listTablesByLowerCase(Connection connection, String remoteSchema)
-
getTableStatistics
public TableStatistics getTableStatistics(ConnectorSession session, JdbcTableHandle handle, TupleDomain<ColumnHandle> tupleDomain)
- Specified by:
getTableStatisticsin interfaceJdbcClient
-
createSchema
public void createSchema(ConnectorSession session, String schemaName)
- Specified by:
createSchemain interfaceJdbcClient
-
dropSchema
public void dropSchema(ConnectorSession session, String schemaName)
- Specified by:
dropSchemain interfaceJdbcClient
-
execute
protected void execute(ConnectorSession session, String query)
-
execute
protected void execute(Connection connection, String query)
-
legacyToWriteMapping
@Deprecated protected WriteMapping legacyToWriteMapping(ConnectorSession session, Type type)
Deprecated.Each connector should provide its own explicit type mapping, along with respective tests.
-
tryApplyLimit
protected Function<String,String> tryApplyLimit(OptionalLong limit)
-
supportsLimit
public boolean supportsLimit()
- Specified by:
supportsLimitin interfaceJdbcClient
-
limitFunction
protected Optional<BiFunction<String,Long,String>> limitFunction()
-
isLimitGuaranteed
public boolean isLimitGuaranteed(ConnectorSession session)
- Specified by:
isLimitGuaranteedin interfaceJdbcClient
-
quoted
public String quoted(String name)
- Specified by:
quotedin interfaceJdbcClient
-
quoted
public String quoted(RemoteTableName remoteTableName)
- Specified by:
quotedin interfaceJdbcClient
-
getTableProperties
public Map<String,Object> getTableProperties(ConnectorSession session, JdbcTableHandle tableHandle)
- Specified by:
getTablePropertiesin interfaceJdbcClient
-
-