Class 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
    • 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:
        doListSchemaNames in class MetadataHandler
        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:
        doListTables in class MetadataHandler
        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:
        doGetTable in class MetadataHandler
        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:
        enhancePartitionSchema in class MetadataHandler
        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:
        getPartitions in class MetadataHandler
        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:
        doGetSplits in class MetadataHandler
        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:
        onPing in class MetadataHandler
        Parameters:
        request - The PingRequest.