Athena Federated query

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.

Athena

Yêu cầu

Hoàn thành Ingestion with DMSTransforming data with Glue ETL labs.

Step

  1. Tạo S3 endpoint để cho phép S3 truy cập vào Athena connector for Lambda, hãy làm theo các bước được đề cập ở đây để tạo S3 endpoint. Đảm bảo sử dụng cùng subnet sẽ được sử dụng cho hàm Lambda trong bước tiếp theo.
  2. Tại Athena console, chọn “Data sources”, Create data source button

Athena

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

  2. Nhập Data source name: Postgres_DB

Athena

  1. Tại Connection detail, Chọn ‘Create Lambda function’

Athena

  1. Điền các thông tin như sau
    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

Athena Athena

  1. Đợi function deploy, Chọn function ở ô Select or enter a Lambda function. Nhấn Next

Athena

Nhấn Create data source

  1. Cấu hình biến môi trường cho Lamda function. Thêm một biến môi trường có tên là: Postgres_DB_connection_string và copy dữ liệu của biến default

Athena

Athena

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

  2. Truy cập query editor chọn new datasource

Athena

  1. Truy vấn kết hợp sử dụng, “sport_location” tables của Postgres data source và “parquet_sporting_event” table từ data lake

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;

Athena