Amazon Athena¶
Amazon Athena 是一种交互式查询服务,可轻松使用标准 SQL 分析 Amazon Simple Storage Service(S3)中的数据。Athena 是无服务器的,因此无需设置或管理基础设施,且只为您运行的查询付费。要开始使用,只需指向 S3 中的数据,定义模式,并使用标准 SQL 开始查询。
前置任务¶
要使用这些操作符,您需要完成以下几项工作
通过 pip 安装 API 库。
pip install 'apache-airflow[amazon]'详细信息可在 Airflow® 安装 中获取。
设置连接.
通用参数¶
- aws_conn_id
引用 Amazon Web Services Connection ID。如果此参数设置为
None,则使用默认的 boto3 行为且不进行连接查找。否则使用存储在连接中的凭证。默认值:aws_default- region_name
AWS 区域名称。如果此参数设置为
None或省略,则使用来自 region_name 的 AWS Connection Extra Parameter。否则使用指定的值而非连接中的值。默认值:None- verify
是否验证 SSL 证书。
False- 不验证 SSL 证书。path/to/cert/bundle.pem - 要使用的 CA 证书捆绑文件名。如果您想使用与 botocore 不同的 CA 证书捆绑,可指定此参数。
如果此参数设置为
None或省略,则使用来自 verify 的 AWS Connection Extra Parameter。否则使用指定的值而非连接中的值。默认值: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或省略,则使用来自 config_kwargs 的 AWS Connection Extra Parameter。否则使用指定的值而非连接中的值。默认值:None注意
指定一个空字典
{}将覆盖 botocore.config.Config 的连接配置。
操作符¶
在 Amazon Athena 中运行查询¶
使用 AthenaOperator 在 Amazon Athena 中运行查询。
在下面的示例中,我们查询已有的 Athena 表并将结果发送到现有的 Amazon S3 存储桶。有关如何使用此运算符的更多示例,请参阅 Sample Dag。
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 中查询的结果。
await_query = AthenaSensor(
task_id="await_query",
query_execution_id=read_table.output,
)