Amazon Athena

Amazon Athena 是一種互動式查詢服務,讓您能夠輕鬆地使用標準 SQL 分析 Amazon Simple Storage Service (S3) 中的資料。Athena 是無伺服器架構,因此無需設定或管理基礎設施,而且您只需為執行的查詢付費。若要開始使用,只需指向 S3 中的資料,定義結構描述,然後開始使用標準 SQL 進行查詢即可。

先決條件任務

若要使用這些運算子,您必須執行幾項操作

通用參數

aws_conn_id

參考 Amazon Web Services 連線 ID。如果此參數設定為 None,則會使用預設的 boto3 行為,而不會查詢連線。否則,請使用儲存在連線中的憑證。預設值:aws_default

region_name

AWS 區域名稱。如果此參數設定為 None 或省略,則會使用 AWS 連線額外參數 中的 region_name。否則,請使用指定的值,而非連線值。預設值:None

verify

是否驗證 SSL 憑證。

  • False - 不驗證 SSL 憑證。

  • path/to/cert/bundle.pem - 要使用的 CA 憑證套件的檔案名稱。如果您想要使用與 botocore 使用的 CA 憑證套件不同的套件,可以指定此引數。

如果此參數設定為 None 或省略,則會使用 AWS 連線額外參數 中的 verify。否則,請使用指定的值,而非連線值。預設值:None

botocore_config

提供的字典用於建構 botocore.config.Config避免節流例外、逾時等設定可以使用此組態。

範例,如需更多關於參數的詳細資訊,請參閱 botocore.config.Config
{
    "signature_version": "unsigned",
    "s3": {
        "us_east_1_regional_endpoint": True,
    },
    "retries": {
      "mode": "standard",
      "max_attempts": 10,
    },
    "connect_timeout": 300,
    "read_timeout": 300,
    "tcp_keepalive": True,
}

如果此參數設定為 None 或省略,則會使用 AWS 連線額外參數 中的 config_kwargs。否則,請使用指定的值,而非連線值。預設值:None

注意

指定空字典 {} 將會覆寫 botocore.config.Config 的連線組態

運算子

在 Amazon Athena 中執行查詢

使用 AthenaOperator 在 Amazon Athena 中執行查詢。

在以下範例中,我們查詢現有的 Athena 表格,並將結果傳送到現有的 Amazon S3 儲存貯體。如需如何使用此運算子的更多範例,請參閱範例 DAG

tests/system/amazon/aws/example_athena.py

read_table = AthenaOperator(
    task_id="read_table",
    query=query_read_table,
    database=athena_database,
    output_location=f"s3://{s3_bucket}/",
)

感測器

等待 Amazon Athena 查詢結果

使用 AthenaSensor 等待 Amazon Athena 中查詢的結果。

tests/system/amazon/aws/example_athena.py

await_query = AthenaSensor(
    task_id="await_query",
    query_execution_id=read_table.output,
)

此條目是否有幫助?