Class PostGreSqlMetadataHandler
- java.lang.Object
-
- com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
-
- com.amazonaws.athena.connectors.jdbc.manager.JdbcMetadataHandler
-
- com.amazonaws.athena.connectors.postgresql.PostGreSqlMetadataHandler
-
- All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestStreamHandler
- Direct Known Subclasses:
RedshiftMetadataHandler
public class PostGreSqlMetadataHandler extends JdbcMetadataHandler
Handles metadata for PostGreSql. User must have access to `schemata`, `tables`, `columns`, `partitions` tables in information_schema.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ALL_PARTITIONS
static String
BLOCK_PARTITION_COLUMN_NAME
static String
BLOCK_PARTITION_SCHEMA_COLUMN_NAME
static String
GET_PARTITIONS_QUERY
static Map<String,String>
JDBC_PROPERTIES
protected static String
NON_DEFAULT_COLLATE
-
Fields inherited from class com.amazonaws.athena.connectors.jdbc.manager.JdbcMetadataHandler
caseResolver, jdbcQueryPassthrough, TABLES_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 protected
PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, GenericJdbcConnectionFactory genericJdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver resolver)
PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, Map<String,String> configOptions)
protected
PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions)
protected
PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver resolver)
PostGreSqlMetadataHandler(Map<String,String> configOptions)
Instantiates handler to be used by Lambda function directly.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GetDataSourceCapabilitiesResponse
doGetDataSourceCapabilities(BlockAllocator allocator, GetDataSourceCapabilitiesRequest request)
Used to describe the types of capabilities supported by a data source.GetSplitsResponse
doGetSplits(BlockAllocator blockAllocator, GetSplitsRequest getSplitsRequest)
Used to split-up the reads required to scan the requested batch of partition(s).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.static List<String>
getCharColumns(Connection connection, String schema, String table)
Retrieves the names of columns with the data type 'CHAR' for a specified table in a PostgreSQL/Redshift database.protected List<TableName>
getPaginatedResults(Connection connection, String databaseName, int token, int limit)
void
getPartitions(BlockWriter blockWriter, GetTableLayoutRequest getTableLayoutRequest, QueryStatusChecker queryStatusChecker)
Used to get the partitions that must be read from the request table in order to satisfy the requested predicate.org.apache.arrow.vector.types.pojo.Schema
getPartitionSchema(String catalogName)
Delegates creation of partition schema to database type implementation.protected ListTablesResponse
listPaginatedTables(Connection connection, ListTablesRequest listTablesRequest)
This is default getAllTables no pagination.protected List<TableName>
listTables(Connection jdbcConnection, String databaseName)
protected String
wrapNameWithEscapedCharacter(String input)
-
Methods inherited from class com.amazonaws.athena.connectors.jdbc.manager.JdbcMetadataHandler
convertDatasourceTypeToArrow, doGetQueryPassthroughSchema, doGetTable, doListSchemaNames, doListTables, escapeNamePattern, getColumns, getCredentialProvider, getJdbcConnectionFactory, getSchema, getSplitClauses, listDatabaseNames, setupQueryPassthroughSplit
-
Methods inherited from class com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
doGetTableLayout, doHandleRequest, doPing, enhancePartitionSchema, getSecret, handleRequest, makeEncryptionKey, makeSpillLocation, onPing, resolveSecrets, resolveWithDefaultCredentials
-
-
-
-
Field Detail
-
GET_PARTITIONS_QUERY
public static final String GET_PARTITIONS_QUERY
- See Also:
- Constant Field Values
-
BLOCK_PARTITION_COLUMN_NAME
public static final String BLOCK_PARTITION_COLUMN_NAME
- See Also:
- Constant Field Values
-
BLOCK_PARTITION_SCHEMA_COLUMN_NAME
public static final String BLOCK_PARTITION_SCHEMA_COLUMN_NAME
- See Also:
- Constant Field Values
-
ALL_PARTITIONS
public static final String ALL_PARTITIONS
- See Also:
- Constant Field Values
-
NON_DEFAULT_COLLATE
protected static final String NON_DEFAULT_COLLATE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PostGreSqlMetadataHandler
public PostGreSqlMetadataHandler(Map<String,String> configOptions)
Instantiates handler to be used by Lambda function directly. Recommend usingPostGreSqlMuxCompositeHandler
instead.
-
PostGreSqlMetadataHandler
public PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, Map<String,String> configOptions)
-
PostGreSqlMetadataHandler
protected PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions)
-
PostGreSqlMetadataHandler
protected PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager, software.amazon.awssdk.services.athena.AthenaClient athena, JdbcConnectionFactory jdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver resolver)
-
PostGreSqlMetadataHandler
protected PostGreSqlMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, GenericJdbcConnectionFactory genericJdbcConnectionFactory, Map<String,String> configOptions, JDBCCaseResolver resolver)
-
-
Method Detail
-
doGetDataSourceCapabilities
public GetDataSourceCapabilitiesResponse doGetDataSourceCapabilities(BlockAllocator allocator, GetDataSourceCapabilitiesRequest request)
Description copied from class:MetadataHandler
Used to describe the types of capabilities supported by a data source. An engine can use this to determine what portions of the query to push down. A connector that returns any optimization will guarantee that the associated predicate will be pushed down.- Overrides:
doGetDataSourceCapabilities
in classMetadataHandler
- Parameters:
allocator
- Tool for creating and managing Apache Arrow Blocks.request
- Provides details about the catalog being used.- Returns:
- A GetDataSourceCapabilitiesResponse object which returns a map of supported optimizations that the connector is advertising to the consumer. The connector assumes all responsibility for whatever is passed here.
-
getPartitionSchema
public org.apache.arrow.vector.types.pojo.Schema getPartitionSchema(String catalogName)
Description copied from class:JdbcMetadataHandler
Delegates creation of partition schema to database type implementation.- Specified by:
getPartitionSchema
in classJdbcMetadataHandler
- Parameters:
catalogName
- Athena provided catalog name.- Returns:
- schema. See
Schema
-
getPartitions
public void getPartitions(BlockWriter blockWriter, GetTableLayoutRequest getTableLayoutRequest, QueryStatusChecker queryStatusChecker) throws Exception
Description copied from class:MetadataHandler
Used to get the partitions that must be read from the request table in order to satisfy the requested predicate.- Specified by:
getPartitions
in classJdbcMetadataHandler
- Parameters:
blockWriter
- Used to write rows (partitions) into the Apache Arrow response.getTableLayoutRequest
- 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 GetSplitsResponse doGetSplits(BlockAllocator blockAllocator, GetSplitsRequest getSplitsRequest)
Description copied from class:MetadataHandler
Used to split-up the reads required to scan the requested batch of partition(s).- Specified by:
doGetSplits
in classJdbcMetadataHandler
- 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.
-
listPaginatedTables
protected ListTablesResponse listPaginatedTables(Connection connection, ListTablesRequest listTablesRequest) throws SQLException
Description copied from class:JdbcMetadataHandler
This is default getAllTables no pagination. Override this if you want to support the behavior.- Overrides:
listPaginatedTables
in classJdbcMetadataHandler
- Returns:
- Throws:
SQLException
-
getPaginatedResults
protected List<TableName> getPaginatedResults(Connection connection, String databaseName, int token, int limit) throws SQLException
- Throws:
SQLException
-
listTables
protected List<TableName> listTables(Connection jdbcConnection, String databaseName) throws SQLException
- Overrides:
listTables
in classJdbcMetadataHandler
- Throws:
SQLException
-
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.- Overrides:
getArrayArrowTypeFromTypeName
in classJdbcMetadataHandler
- Parameters:
typeName
- The column's TYPE_NAME (e.g. _int4, _text, _float8, etc...)precision
- Used for BigDecimal ArrowTypescale
- Used for BigDecimal ArrowType- Returns:
- ArrowType equivalent of the fieldType.
-
getCharColumns
public static List<String> getCharColumns(Connection connection, String schema, String table) throws SQLException
Retrieves the names of columns with the data type 'CHAR' for a specified table in a PostgreSQL/Redshift database.- Parameters:
connection
- the JDBC connection to the databaseschema
- Postgresql/Redshift schema nametable
- Postgresql/Redshift table name- Returns:
- a list of column names that have the data type 'CHAR'
- Throws:
SQLException
- if a database access error occurs
-
wrapNameWithEscapedCharacter
protected String wrapNameWithEscapedCharacter(String input)
- Overrides:
wrapNameWithEscapedCharacter
in classJdbcMetadataHandler
-
-