Class JdbcMetadataHandler
- java.lang.Object
-
- com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
-
- com.amazonaws.athena.connectors.jdbc.manager.JdbcMetadataHandler
-
- All Implemented Interfaces:
FederationRequestHandler,com.amazonaws.services.lambda.runtime.RequestStreamHandler
- Direct Known Subclasses:
DataLakeGen2MetadataHandler,Db2As400MetadataHandler,Db2MetadataHandler,HiveMetadataHandler,HiveMetadataHandler,ImpalaMetadataHandler,MultiplexingJdbcMetadataHandler,MySqlMetadataHandler,OracleMetadataHandler,PostGreSqlMetadataHandler,SaphanaMetadataHandler,SnowflakeMetadataHandler,SqlServerMetadataHandler,SynapseMetadataHandler,TeradataMetadataHandler,VerticaMetadataHandler
public abstract class JdbcMetadataHandler extends MetadataHandler
Abstracts JDBC metadata handler and provides common reusable metadata handling.
-
-
Field Summary
Fields Modifier and Type Field Description protected JDBCCaseResolvercaseResolverprotected JdbcQueryPassthroughjdbcQueryPassthroughstatic StringTABLES_AND_VIEWS-
Fields inherited from class com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
configOptions, DISABLE_SPILL_ENCRYPTION, KMS_KEY_ID_ENV, SPILL_BUCKET_ENV, SPILL_PREFIX_ENV
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions)protectedJdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver caseResolver)protectedJdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions)protectedJdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver caseResolver)protectedJdbcMetadataHandler(String sourceType, Map<String,String> configOptions)Used only by Multiplexing handler.protectedJdbcMetadataHandler(String sourceType, Map<String,String> configOptions, JDBCCaseResolver caseResolver)Used only by Multiplexing handler.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Optional<org.apache.arrow.vector.types.pojo.ArrowType>convertDatasourceTypeToArrow(int columnIndex, int precision, Map<String,String> configOptions, ResultSetMetaData metadata)A method that takes in a JDBC type; and converts it to Arrow Type This can be overriden by other Metadata Handlers extending JDBCGetTableResponsedoGetQueryPassthroughSchema(BlockAllocator blockAllocator, GetTableRequest getTableRequest)Used to get definition (field names, types, descriptions, etc...) of a Query PassThrough.abstract GetSplitsResponsedoGetSplits(BlockAllocator blockAllocator, GetSplitsRequest getSplitsRequest)Used to split-up the reads required to scan the requested batch of partition(s).GetTableResponsedoGetTable(BlockAllocator blockAllocator, GetTableRequest getTableRequest)Used to get definition (field names, types, descriptions, etc...) of a Table.ListSchemasResponsedoListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest listSchemasRequest)Used to get the list of schemas (aka databases) that this source contains.ListTablesResponsedoListTables(BlockAllocator blockAllocator, ListTablesRequest listTablesRequest)Used to get the list of tables that this source contains.protected StringescapeNamePattern(String name, String escape)protected org.apache.arrow.vector.types.pojo.ArrowTypegetArrayArrowTypeFromTypeName(String typeName, int precision, int scale)Converts an ARRAY column's TYPE_NAME (provided by the jdbc metadata) to an ArrowType.protected ResultSetgetColumns(String catalogName, TableName tableHandle, DatabaseMetaData metadata)protected CredentialsProvidergetCredentialProvider()protected DatabaseConnectionConfiggetDatabaseConnectionConfig()protected JdbcConnectionFactorygetJdbcConnectionFactory()abstract voidgetPartitions(BlockWriter blockWriter, GetTableLayoutRequest request, QueryStatusChecker queryStatusChecker)Used to get the partitions that must be read from the request table in order to satisfy the requested predicate.abstract org.apache.arrow.vector.types.pojo.SchemagetPartitionSchema(String catalogName)Delegates creation of partition schema to database type implementation.protected org.apache.arrow.vector.types.pojo.SchemagetSchema(Connection jdbcConnection, TableName tableName, org.apache.arrow.vector.types.pojo.Schema partitionSchema)protected List<String>getSplitClauses(TableName tableName)protected Set<String>listDatabaseNames(Connection jdbcConnection)protected ListTablesResponselistPaginatedTables(Connection connection, ListTablesRequest listTablesRequest)This is default getAllTables without true pagination.protected List<TableName>listTables(Connection jdbcConnection, String databaseName)protected GetSplitsResponsesetupQueryPassthroughSplit(GetSplitsRequest request)Helper function that provides a single partition for Query Pass-Throughprotected StringwrapNameWithEscapedCharacter(String input)-
Methods inherited from class com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
doGetDataSourceCapabilities, doGetTableLayout, doHandleRequest, doPing, enhancePartitionSchema, getCachableSecretsManager, getRequestOverrideConfig, getSecret, handleRequest, makeEncryptionKey, makeSpillLocation, onPing, resolveSecrets, resolveWithDefaultCredentials
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.amazonaws.athena.connector.lambda.handlers.FederationRequestHandler
getAthenaClient, getRequestOverrideConfig, getS3Client, getSessionCredentials
-
-
-
-
Field Detail
-
TABLES_AND_VIEWS
public static final String TABLES_AND_VIEWS
- See Also:
- Constant Field Values
-
caseResolver
protected final JDBCCaseResolver caseResolver
-
jdbcQueryPassthrough
protected JdbcQueryPassthrough jdbcQueryPassthrough
-
-
Constructor Detail
-
JdbcMetadataHandler
protected JdbcMetadataHandler(String sourceType, Map<String,String> configOptions)
Used only by Multiplexing handler. All calls will be delegated to respective database handler.
-
JdbcMetadataHandler
protected JdbcMetadataHandler(String sourceType, Map<String,String> configOptions, JDBCCaseResolver caseResolver)
Used only by Multiplexing handler. All calls will be delegated to respective database handler.
-
JdbcMetadataHandler
protected JdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions)
-
JdbcMetadataHandler
protected JdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver caseResolver)
-
JdbcMetadataHandler
protected JdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions)
-
JdbcMetadataHandler
protected JdbcMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver caseResolver)
-
-
Method Detail
-
getJdbcConnectionFactory
protected JdbcConnectionFactory getJdbcConnectionFactory()
-
getDatabaseConnectionConfig
protected DatabaseConnectionConfig getDatabaseConnectionConfig()
-
getCredentialProvider
protected CredentialsProvider getCredentialProvider()
-
doListSchemaNames
public ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest listSchemasRequest) throws Exception
Description copied from class:MetadataHandlerUsed to get the list of schemas (aka databases) that this source contains.- Specified by:
doListSchemaNamesin classMetadataHandler- Parameters:
blockAllocator- Tool for creating and managing Apache Arrow Blocks.listSchemasRequest- Provides details on who made the request and which Athena catalog they are querying.- Returns:
- A ListSchemasResponse which primarily contains a Set
of schema names and a catalog name corresponding the Athena catalog that was queried. - Throws:
Exception
-
listDatabaseNames
protected Set<String> listDatabaseNames(Connection jdbcConnection) throws SQLException
- Throws:
SQLException
-
doListTables
public ListTablesResponse doListTables(BlockAllocator blockAllocator, ListTablesRequest listTablesRequest) throws Exception
Description copied from class:MetadataHandlerUsed to get the list of tables that this source contains.- Specified by:
doListTablesin classMetadataHandler- Parameters:
blockAllocator- Tool for creating and managing Apache Arrow Blocks.listTablesRequest- Provides details on who made the request and which Athena catalog and database they are querying.- Returns:
- A ListTablesResponse which primarily contains a List
enumerating the tables in this catalog, database tuple. It also contains the catalog name corresponding the Athena catalog that was queried. - Throws:
Exception
-
listPaginatedTables
protected ListTablesResponse listPaginatedTables(Connection connection, ListTablesRequest listTablesRequest) throws SQLException
This is default getAllTables without true pagination. Paginated list of tables will be returned by retrieving all tables first, then returning subset based off request. Override this if you want to support true pagination behavior.- Parameters:
connection-listTablesRequest-- Returns:
- Throws:
SQLException
-
listTables
protected List<TableName> listTables(Connection jdbcConnection, String databaseName) throws SQLException
- Throws:
SQLException
-
doGetTable
public GetTableResponse doGetTable(BlockAllocator blockAllocator, GetTableRequest getTableRequest) throws Exception
Description copied from class:MetadataHandlerUsed to get definition (field names, types, descriptions, etc...) of a Table.- Specified by:
doGetTablein classMetadataHandler- Parameters:
blockAllocator- Tool for creating and managing Apache Arrow Blocks.getTableRequest- Provides details on who made the request and which Athena catalog, database, and table they are querying.- Returns:
- A GetTableResponse which primarily contains:
1. An Apache Arrow Schema object describing the table's columns, types, and descriptions.
2. A Set
of partition column names (or empty if the table isn't partitioned). - Throws:
Exception
-
doGetQueryPassthroughSchema
public GetTableResponse doGetQueryPassthroughSchema(BlockAllocator blockAllocator, GetTableRequest getTableRequest) throws Exception
Description copied from class:MetadataHandlerUsed to get definition (field names, types, descriptions, etc...) of a Query PassThrough.- Overrides:
doGetQueryPassthroughSchemain classMetadataHandler- Parameters:
blockAllocator- Tool for creating and managing Apache Arrow Blocks.getTableRequest- Provides details on who made the request and which Athena catalog, database, and table they are querying.- Returns:
- A GetTableResponse which primarily contains:
1. An Apache Arrow Schema object describing the table's columns, types, and descriptions.
2. A Set
of partition column names (or empty if the table isn't partitioned). - Throws:
Exception
-
convertDatasourceTypeToArrow
protected Optional<org.apache.arrow.vector.types.pojo.ArrowType> convertDatasourceTypeToArrow(int columnIndex, int precision, Map<String,String> configOptions, ResultSetMetaData metadata) throws SQLException
A method that takes in a JDBC type; and converts it to Arrow Type This can be overriden by other Metadata Handlers extending JDBC- Parameters:
columnIndex-precision-configOptions-metadata-- Returns:
- Arrow Type
- Throws:
SQLException
-
getSchema
protected org.apache.arrow.vector.types.pojo.Schema getSchema(Connection jdbcConnection, TableName tableName, org.apache.arrow.vector.types.pojo.Schema partitionSchema) throws Exception
- Throws:
Exception
-
getColumns
protected ResultSet getColumns(String catalogName, TableName tableHandle, DatabaseMetaData metadata) throws SQLException
- Throws:
SQLException
-
getPartitionSchema
public abstract org.apache.arrow.vector.types.pojo.Schema getPartitionSchema(String catalogName)
Delegates creation of partition schema to database type implementation.- Parameters:
catalogName- Athena provided catalog name.- Returns:
- schema. See
Schema
-
getPartitions
public abstract void getPartitions(BlockWriter blockWriter, GetTableLayoutRequest request, QueryStatusChecker queryStatusChecker) throws Exception
Description copied from class:MetadataHandlerUsed to get the partitions that must be read from the request table in order to satisfy the requested predicate.- Specified by:
getPartitionsin classMetadataHandler- Parameters:
blockWriter- Used to write rows (partitions) into the Apache Arrow response.request- Provides details of the catalog, database, and table being queried as well as any filter predicate.queryStatusChecker- A QueryStatusChecker that you can use to stop doing work for a query that has already terminated- Throws:
Exception
-
doGetSplits
public abstract GetSplitsResponse doGetSplits(BlockAllocator blockAllocator, GetSplitsRequest getSplitsRequest)
Description copied from class:MetadataHandlerUsed to split-up the reads required to scan the requested batch of partition(s).- Specified by:
doGetSplitsin classMetadataHandler- Parameters:
blockAllocator- Tool for creating and managing Apache Arrow Blocks.getSplitsRequest- Provides details of the catalog, database, table, andpartition(s) being queried as well as any filter predicate.- Returns:
- A GetSplitsResponse which primarily contains:
1. A Set
which represent read operations Amazon Athena must perform by calling your read function. 2. (Optional) A continuation token which allows you to paginate the generation of splits for large queries.
-
getArrayArrowTypeFromTypeName
protected org.apache.arrow.vector.types.pojo.ArrowType getArrayArrowTypeFromTypeName(String typeName, int precision, int scale)
Converts an ARRAY column's TYPE_NAME (provided by the jdbc metadata) to an ArrowType.- Parameters:
typeName- The column's TYPE_NAME (e.g. _int4, _text, _float8, etc...)precision- Used for BigDecimal ArrowTypescale- Used for BigDecimal ArrowType- Returns:
- Utf8 ArrowType (VARCHAR)
-
setupQueryPassthroughSplit
protected GetSplitsResponse setupQueryPassthroughSplit(GetSplitsRequest request)
Helper function that provides a single partition for Query Pass-Through
-
-