- Newest
- Most votes
- Most comments
Creating a view that takes advantage of partition projection while flattening data for AWS SES event logs requires a careful approach. The main issue with your current view is that it doesn't pass through the partition column (date) from the base table, which is essential for Athena to leverage partition projection.
To create a view that both flattens the data and benefits from partition projection, you should modify your view definition to include the partition column. Here's an improved version of your view:
CREATE OR REPLACE VIEW ses_send_event AS SELECT sm.eventtype as eventtype, sm.mail.messageId as mailmessageid, sm.mail.timestamp as mailtimestamp, sm.mail.source as mailsource, sm.mail.sendingAccountId as mailsendingAccountId, sm.mail.commonHeaders.subject as mailsubject, sm.mail.tags.ses_configurationset as mailses_configurationset, sm.mail.tags.ses_source_ip as mailses_source_ip, sm.mail.tags.ses_from_domain as mailses_from_domain, sm.mail.tags.ses_outgoing_ip as mailses_outgoing_ip, t.recipient as mailto, sm.date as date -- Include the partition column FROM ses_event_logs sm CROSS JOIN UNNEST(sm.mail.commonHeaders.to) AS t(recipient) WHERE sm.eventtype = 'Send'
This modified view definition includes several key changes:
- It includes the
datecolumn from the base table, which is crucial for partition projection to work. - It simplifies the query by using a single CROSS JOIN UNNEST operation instead of a subquery.
- It applies the 'Send' event type filter directly in the main query.
When using this view, make sure to include the date column in your WHERE clause to take advantage of partition projection. For example:
SELECT * FROM ses_send_event WHERE date = '2024/01/15'
This query will use partition projection and only scan the data for the specified date.
Remember that Athena doesn't use table properties of views for partition projection configuration. The projection is applied based on the underlying table's properties. By including the partition column in the view and using it in your queries, you ensure that Athena can push down the partition filtering to the base table, thus leveraging the partition projection setup.
Sources
Use partition projection with Amazon Athena - Amazon Athena
Create a table for AWS WAF S3 logs in Athena using partition projection - Amazon Athena
Create the table for ALB access logs in Athena using partition projection - Amazon Athena
Relevant content
asked 5 years ago
- AWS OFFICIALUpdated 2 years ago
