How to connect to Amazon Athena from Denodo
You can translate the document:Goal
This document explains how to integrate Amazon Athena into the Denodo Platform using its JDBC driver.
In addition to explaining how to configure a basic JDBC data source and base view we will also explain how Denodo handles partitioned tables in Amazon Athena.
Creating the JDBC data source
Amazon Athena allows connectivity from Denodo using an official JDBC driver. You can find the documentation and the download links here: Using Athena with the JDBC Driver.
The JDBC data source can be defined like this using the native adapter for Amazon Athena:
Connection parameters details
Authentication: The authentication fields should be your AWS access key and AWS secret access key. Keep in mind that AWS security policies may need to be configured in order to allow access to AWS resources such as Athena. We recommend following the Access through JDBC and ODBC Connections section of the Athena documentation to get detailed information on how to configure the IAM permissions policy for this purpose.
Region: Ensure you replace the value “region” in the AwsRegion field with the region where your Amazon Athena installation is located. You can check this AWS document for more information about AWS regions including a list of the available ones.
Once you have configured the connection, you can proceed to create base views. Base views can be created easily with the usual mechanism from the Create base view section:
Creating the Base View
With the adapter, following the previous instructions, the connectivity to Amazon Athena should work properly:
Querying an Athena Partitioned table
In Amazon Athena, a partitioned table is a table that is divided into smaller, manageable parts called partitions, based on the values of one or more columns (for example, year, month or region).
Each partition corresponds to a specific subset of data stored separately in Amazon S3. Instead of scanning the entire dataset, Athena can scan only the relevant partitions when a query includes partition filters, resulting in improved performance and reduced query cost.
The following example illustrates a typical Athena partitioned table setup.
Sample Amazon S3 Folder Structure
|
s3://<bucket-name>/sales_data/year=2023/month=12/sales_2023_12.csv s3://<bucket-name>/sales_data/year=2024/month=02/sales_2024_02.csv s3://<bucket-name>/sales_data/year=2024/month=04/sales.csv |
Athena Partitioned table definition
The following DDL creates a partitioned external table called “sales_data_partitioned” in Athena pointing to the S3 location:
|
CREATE EXTERNAL TABLE IF NOT EXISTS sales_data_partitioned ( customer_id STRING, item STRING, amount DOUBLE, region STRING ) PARTITIONED BY (year STRING, month STRING) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES ( "separatorChar" = ",", "quoteChar" = "\"" ) STORED AS TEXTFILE LOCATION 's3://<bucket-name>/sales_data/' TBLPROPERTIES ( 'has_encrypted_data' = 'false', 'skip.header.line.count' = '1' ); |
After creating the table, the partitions are loaded with the below command:
|
MSCK REPAIR TABLE sales_data_partitioned; |
Creating the base view on the partitioned table
Once you have created a partitioned table in Athena and loaded the partitions, the base views can be created easily in Denodo with the usual mechanism from the Create base view section as we saw before.
When checking the Execution Trace of a query on a partitioned Athena partitioned table, we will see a difference in the Execution Time while querying with and without partitions.
Accessing a partitioned table without filtering by any partition
No conditions are set for the partition fields and Denodo will delegate the query to Athena as it is resulting in a full scan of all the partitions in the partitioned table.
|
SELECT * FROM sales_data_partitioned; |
Accessing a partitioned table filtering by partition
A condition is set for both partition fields, as Denodo delegates both conditions to the data source, an Amazon Athena partitioned table in this case, Athena will receive this filter and will only scan the partition that contains the data with these values for these two partition columns.
|
SELECT * FROM sales_data_partitioned WHERE year = '2023' AND month = '12'; |
As we can see the integration of Athena partitioned tables is transparent to Denodo. The partitioned table will be imported into Denodo as any other base view and the base view will be queried normally. As the filter conditions are directly delegated to the data source, if those filters include the partition columns, Athena will take care of only scanning the relevant partitions.
References
Partition your data - Amazon Athena
The information provided in the Denodo Knowledge Base is intended to assist our users in advanced uses of Denodo. Please note that the results from the application of processes and configurations detailed in these documents may vary depending on your specific environment. Use them at your own discretion.
For an official guide of supported features, please refer to the User Manuals. For questions on critical systems or complex environments we recommend you to contact your Denodo Customer Success Manager.
