Class ExampleMetadataHandler
- java.lang.Object
-
- com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
-
- com.amazonaws.athena.connector.lambda.examples.ExampleMetadataHandler
-
- All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestStreamHandler
public class ExampleMetadataHandler extends MetadataHandler
All items in the "com.amazonaws.athena.connector.lambda.examples" that this class belongs to are part of an 'Example' connector. We do not recommend using any of the classes in this package directly. Instead you can/should copy and modify as needed.This class defined an example MetadataHandler which showcases most of the features offered by the Amazon Athena Query Federation SDK. Some notable characteristics include: 1. Highly partitioned table. 2. Paginated split generation. 3. S3 Spill support. 4. Spill encryption using either KMS KeyFactory or LocalKeyFactory. 5. A wide range of field types including complex Struct and List types. 6. Pagination support for the ListTables request and response (doListTables).
- See Also:
MetadataHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classExampleMetadataHandler.ExampleTableWe use this as our static metastore for the example implementation
-
Field Summary
Fields Modifier and Type Field Description protected static intMAX_SPLITS_PER_REQUESTprotected static intNUM_PARTS_PER_SPLITprotected static StringPARTITION_LOCATIONprotected static StringSERDE-
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 protectedExampleMetadataHandler(EncryptionKeyFactory keyFactory, com.amazonaws.services.secretsmanager.AWSSecretsManager awsSecretsManager, com.amazonaws.services.athena.AmazonAthena athena, String spillBucket, String spillPrefix, Map<String,String> configOptions)Full DI constructor used mostly for testingExampleMetadataHandler(Map<String,String> configOptions)Default constructor used by Lambda.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GetSplitsResponsedoGetSplits(BlockAllocator allocator, GetSplitsRequest request)For each partition we generate a pre-determined number of splits based on the NUM_PARTS_PER_SPLIT setting.GetTableResponsedoGetTable(BlockAllocator allocator, GetTableRequest request)Retrieves a static Table schema for the example table.ListSchemasResponsedoListSchemaNames(BlockAllocator allocator, ListSchemasRequest request)Returns a static, single schema.ListTablesResponsedoListTables(BlockAllocator allocator, ListTablesRequest request)Returns a paginated list of TableNames.voidenhancePartitionSchema(SchemaBuilder partitionSchemaBuilder, GetTableLayoutRequest request)Here we inject the two additional columns we define for partition metadata.voidgetPartitions(BlockWriter writer, GetTableLayoutRequest request, QueryStatusChecker queryStatusChecker)Our example table is partitions on year, month, day so we loop over a range of years, months, and days to generate our example partitions.voidonPing(PingRequest request)We use the ping signal to simply log the fact that a ping request came in.protected voidsetEncryption(boolean enableEncryption)Used to toggle encryption during unit tests.-
Methods inherited from class com.amazonaws.athena.connector.lambda.handlers.MetadataHandler
doGetTableLayout, doHandleRequest, doPing, getSecret, handleRequest, makeEncryptionKey, makeSpillLocation, resolveSecrets
-
-
-
-
Field Detail
-
NUM_PARTS_PER_SPLIT
protected static final int NUM_PARTS_PER_SPLIT
- See Also:
- Constant Field Values
-
MAX_SPLITS_PER_REQUEST
protected static final int MAX_SPLITS_PER_REQUEST
- See Also:
- Constant Field Values
-
PARTITION_LOCATION
protected static final String PARTITION_LOCATION
- See Also:
- Constant Field Values
-
SERDE
protected static final String SERDE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExampleMetadataHandler
public ExampleMetadataHandler(Map<String,String> configOptions)
Default constructor used by Lambda.
-
ExampleMetadataHandler
protected ExampleMetadataHandler(EncryptionKeyFactory keyFactory, com.amazonaws.services.secretsmanager.AWSSecretsManager awsSecretsManager, com.amazonaws.services.athena.AmazonAthena athena, String spillBucket, String spillPrefix, Map<String,String> configOptions)
Full DI constructor used mostly for testing- Parameters:
keyFactory- The EncryptionKeyFactory to use for spill encryption.awsSecretsManager- The AWSSecretsManager client that can be used when attempting to resolve secrets.athena- The Athena client that can be used to fetch query termination status to fast-fail this handler.spillBucket- The S3 Bucket to use when spilling results.spillPrefix- The S3 prefix to use when spilling results.configOptions- The configOptions for this MetadataHandler.
-
-
Method Detail
-
setEncryption
protected void setEncryption(boolean enableEncryption)
Used to toggle encryption during unit tests.- Parameters:
enableEncryption-
-
doListSchemaNames
public ListSchemasResponse doListSchemaNames(BlockAllocator allocator, ListSchemasRequest request)
Returns a static, single schema. A connector for a real data source would likely query that source's metadata to create a real list of schemas.- Specified by:
doListSchemaNamesin classMetadataHandler- Parameters:
allocator- Tool for creating and managing Apache Arrow Blocks.request- Provides details on who made the request and which Athena catalog they are querying.- Returns:
- The ListSchemasResponse which mostly contains the list of schemas (aka databases).
-
doListTables
public ListTablesResponse doListTables(BlockAllocator allocator, ListTablesRequest request)
Returns a paginated list of TableNames.- Specified by:
doListTablesin classMetadataHandler- Parameters:
allocator- Tool for creating and managing Apache Arrow Blocks.request- Provides details on who made the request and which Athena catalog and database they are querying.- Returns:
- A ListTablesResponse containing the list of available TableNames and a nextToken String for the start of the next pagination (may be null if there are no more tables to paginate).
-
doGetTable
public GetTableResponse doGetTable(BlockAllocator allocator, GetTableRequest request)
Retrieves a static Table schema for the example table. A connector for a real data source would likely query that source's metadata to create a table definition.- Specified by:
doGetTablein classMetadataHandler- Parameters:
allocator- Tool for creating and managing Apache Arrow Blocks.request- Provides details on who made the request and which Athena catalog, database, and table they are querying.- Returns:
- A GetTableResponse containing the definition of the table (e.g. table schema and partition columns)
-
enhancePartitionSchema
public void enhancePartitionSchema(SchemaBuilder partitionSchemaBuilder, GetTableLayoutRequest request)
Here we inject the two additional columns we define for partition metadata. These columns are ignored by Athena but passed along to our code when Athena calls GetSplits(...). If you do not require any additional metadata on your partitions you may choose not to implement this function.- Overrides:
enhancePartitionSchemain classMetadataHandler- Parameters:
partitionSchemaBuilder- The SchemaBuilder you can use to add additional columns and metadata to the partitions response.request- The GetTableLayoutResquest that triggered this call.
-
getPartitions
public void getPartitions(BlockWriter writer, GetTableLayoutRequest request, QueryStatusChecker queryStatusChecker)
Our example table is partitions on year, month, day so we loop over a range of years, months, and days to generate our example partitions. A connector for a real data source would likely query that source's metadata to create a real list of partitions.- Specified by:
getPartitionsin classMetadataHandler- Parameters:
writer- Used to write rows (partitions) into the Apache Arrow response. The writes are automatically constrained.request- Provides details of the catalog, database, and table being queried as well as any filter predicate.queryStatusChecker-
-
doGetSplits
public GetSplitsResponse doGetSplits(BlockAllocator allocator, GetSplitsRequest request)
For each partition we generate a pre-determined number of splits based on the NUM_PARTS_PER_SPLIT setting. This method also demonstrates how to handle calls for batches of partitions and also leverage this API's ability to paginated. A connector for a real data source would likely query that source's metadata to determine if/how to split up the read operations for a particular partition.- Specified by:
doGetSplitsin classMetadataHandler- Parameters:
allocator- Tool for creating and managing Apache Arrow Blocks.request- Provides details of the catalog, database, table, andpartition(s) being queried as well as any filter predicate.- Returns:
- A GetSplitsResponse which contains a list of splits as an optional continuation token if we were not able to generate all splits for the partitions in this batch.
-
onPing
public void onPing(PingRequest request)
We use the ping signal to simply log the fact that a ping request came in.- Overrides:
onPingin classMetadataHandler- Parameters:
request- The PingRequest.
-
-