Federated query là một tính năng mới của Amazon Athena cho phép các nhà phân tích dữ liệu, kỹ sư và nhà khoa học dữ liệu thực hiện các truy vấn SQL trên dữ liệu được lưu trữ trong các nguồn dữ liệu quan hệ, không quan hệ, đối tượng và tùy chỉnh. Với Athena federated query, khách hàng có thể gửi một truy vấn SQL duy nhất và phân tích dữ liệu từ nhiều nguồn chạy tại chỗ hoặc được lưu trữ trên đám mây. Athena thực hiện federated queries bằng Data Source Connectors chạy trên AWS Lambda.
Trong bài này, chúng ta sẽ khám phá cách truy vấn các nguồn dữ liệu khác nhau từ Athena. Chúng tôi sẽ sử dụng cơ sở dữ liệu RDS hiện có được tạo như một phần của thiết lập ban đầu dưới dạng datasource-1 và data lake data (được lưu trữ trong S3) dưới dạng datasource-2.

Hoàn thành Ingestion with DMS và Transforming data with Glue ETL labs.

Chọn PostgreSQL làm data source, và nhấn Next

Nhập Data source name: Postgres_DB


| Field | Value |
|---|---|
| Application Name | AthenaJdbcConnector |
| SecretNamePrefix | AthenaFed_ |
| SpillBucket | Get the BucketName from Workshop Studio Event Dashboard (e.g. dmslab-student-dmslabs3bucket-dpxexymdkhve) |
| DefaultConnectionString | postgres://jdbc:postgresql://<DATABASE_ENDPOINT>:5432/sportstickets?user=adminuser&password=admin123 → replace <DATABASE_EDNPOINT> with the correct database endpoint (e.g. dmslabinstance.abcdshic87yz.eu-west-1.rds.amazonaws.com) |
| DisableSpillEncryption | false |
| LambdaFunctionName | postgresqlconnector |
| LambdaMemory | 3008 |
| LambdaTimeout | 900 |
| SecurityGroupIds | Use the SecurityGroupId noted in prerequisites |
| SpillPrefix | athena-spill |
| SubnetIds | Use the SubnetId noted in prerequisites |


Nhấn Create data source


Xác thực data source đã được tạo ở Athena Console.

Truy cập query editor chọn new datasource

Copy đoạn code sau và chạy:
SELECT loc.city, count(distinct evt.id) AS events
FROM "Postgres_DB"."dms_sample"."sport_location" AS loc
JOIN "AwsDataCatalog"."ticketdata"."parquet_sporting_event" AS evt
ON loc.id = evt.location_id
GROUP BY loc.city
ORDER BY loc.city ASC;
