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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBaseJdbcClient.TopNFunction
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionFactoryconnectionFactoryprotected StringidentifierQuoteprotected Set<String>jdbcTypesMappedToVarchar
-
Constructor Summary
Constructors Constructor Description BaseJdbcClient(BaseJdbcConfig config, String identifierQuote, ConnectionFactory connectionFactory, IdentifierMapping identifierMapping)BaseJdbcClient(String identifierQuote, ConnectionFactory connectionFactory, Set<String> jdbcTypesMappedToVarchar, IdentifierMapping identifierMapping)
-
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
-
-
Constructor Detail
-
BaseJdbcClient
public BaseJdbcClient(BaseJdbcConfig config, String identifierQuote, ConnectionFactory connectionFactory, IdentifierMapping identifierMapping)
-
BaseJdbcClient
public BaseJdbcClient(String identifierQuote, ConnectionFactory connectionFactory, Set<String> jdbcTypesMappedToVarchar, IdentifierMapping identifierMapping)
-
-
Method Detail
-
getIdentifierMapping
protected IdentifierMapping getIdentifierMapping()
-
getSchemaNames
public final Set<String> getSchemaNames(ConnectorSession session)
- Specified by:
getSchemaNamesin interfaceJdbcClient
-
listSchemas
public 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
-
legacyColumnMapping
@Deprecated protected Optional<ColumnMapping> legacyColumnMapping(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
-
prepareQuery
protected PreparedQuery prepareQuery(ConnectorSession session, Connection connection, JdbcTableHandle table, Optional<List<List<JdbcColumnHandle>>> groupingSets, List<JdbcColumnHandle> columns, Map<String,String> columnExpressions, Optional<JdbcSplit> split)
-
implementJoin
public Optional<PreparedQuery> implementJoin(ConnectorSession session, JoinType joinType, PreparedQuery leftSource, PreparedQuery rightSource, List<JdbcJoinCondition> joinConditions, Map<JdbcColumnHandle,String> rightAssignments, Map<JdbcColumnHandle,String> leftAssignments, JoinStatistics statistics)
- Specified by:
implementJoinin interfaceJdbcClient
-
isSupportedJoinCondition
protected boolean isSupportedJoinCondition(JdbcJoinCondition joinCondition)
-
applyQueryTransformations
protected PreparedQuery applyQueryTransformations(JdbcTableHandle tableHandle, PreparedQuery query)
-
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 targetTableName) 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 remoteSchemaName, String remoteTableName, SchemaTableName newTable)
-
finishInsertTable
public void finishInsertTable(ConnectorSession session, JdbcOutputTableHandle handle)
- Specified by:
finishInsertTablein interfaceJdbcClient
-
buildInsertSql
protected String buildInsertSql(ConnectorSession session, RemoteTableName targetTable, RemoteTableName sourceTable, List<String> columnNames)
-
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
public ResultSet getTables(Connection connection, Optional<String> remoteSchemaName, Optional<String> remoteTableName) throws SQLException
- Throws:
SQLException
-
getTableSchemaName
protected String getTableSchemaName(ResultSet resultSet) throws SQLException
- Throws:
SQLException
-
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.
-
supportsTopN
public boolean supportsTopN(ConnectorSession session, JdbcTableHandle handle, List<JdbcSortItem> sortOrder)
- Specified by:
supportsTopNin interfaceJdbcClient
-
topNFunction
protected Optional<BaseJdbcClient.TopNFunction> topNFunction()
-
isTopNGuaranteed
public boolean isTopNGuaranteed(ConnectorSession session)
Description copied from interface:JdbcClientReports whether result cardinality and ordering is guaranteed whenJdbcClient.supportsTopN(ConnectorSession, JdbcTableHandle, List)returns true.- Specified by:
isTopNGuaranteedin interfaceJdbcClient
-
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
-
-