DynamicFrameWriter 类 - Amazon Glue
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

DynamicFrameWriter 类

  Methods

__init__

__init__(glue_context)

from_options

from_options(frame, connection_type, connection_options={}, format=None, format_options={}, transformation_ctx="")

使用指定的连接和格式编写一个 DynamicFrame

  • frame – 要编写的 DynamicFrame

  • connection_type – 连接类型。有效值包括 s3mysqlpostgresqlredshiftsqlserveroracle

  • connection_options – 连接选项,例如路径和数据库表 (可选)。对于 connection_types3,将会定义 Amazon S3 路径。

    connection_options = {"path": "s3://aws-glue-target/temp"}

    对于 JDBC 连接,必须定义多个属性。请注意,数据库名称必须是 URL 的一部分。它可以选择性地包含在连接选项中。

    警告

    不建议在脚本中存储密码。请考虑使用 boto3 从 Amazon Secrets Manager 或 Amazon Glue Data Catalog 检索它们。

    connection_options = {"url": "jdbc-url/database", "user": "username", "password": passwordVariable,"dbtable": "table-name", "redshiftTmpDir": "s3-tempdir-path"}

    dbtable 属性是 JDBC 表的名称。对于在数据库中支持架构的 JDBC 数据存储,指定 schema.table-name。如果未提供架构,则使用默认的“public”架构。

    有关更多信息,请参阅Amazon Glue for Spark 中适用于 ETL 的连接类型和选项

  • format – 格式规范(可选)。这用于 Amazon Simple Storage Service(Amazon S3)或支持多种格式的 Amazon Glue 连接。有关支持的格式,请参阅 Amazon Glue for Spark 中的输入和输出的数据格式选项

  • format_options – 指定格式的格式选项。有关支持的格式,请参阅 Amazon Glue for Spark 中的输入和输出的数据格式选项

  • transformation_ctx – 要使用的转换上下文 (可选)。

from_catalog

from_catalog(frame, name_space, table_name, redshift_tmp_dir="", transformation_ctx="")

使用指定的目录数据库和表名称编写一个 DynamicFrame

  • frame – 要编写的 DynamicFrame

  • name_space – 要使用的数据库。

  • table_name – 要使用的 table_name

  • redshift_tmp_dir – 要使用的 Amazon Redshift 临时目录(可选)。

  • transformation_ctx – 要使用的转换上下文 (可选)。

  • additional_options 提供给 Amazon Glue 的额外选项。

    要写入 Lake Formation 受管表,可以使用以下附加选项:

    • transactionId –(字符串)用于写入受管表的事务 ID。此事务无法提交或中止,否则写入将失败。

    • callDeleteObjectsOnCancel –(布尔值,可选)如果设置为 true(原定设置)、则在将对象写入 Amazon S3 后 Amazon Glue 将自动调用 DeleteObjectsOnCancel API。有关更多信息,请参阅 Amazon Lake Formation 开发人员指南中的 DeleteObjectsOnCancel

    例 示例:写入 Lake Formation 中的受管表
    txId = glueContext.start_transaction(read_only=False) glueContext.write_dynamic_frame.from_catalog( frame=dyf, database = db, table_name = tbl, transformation_ctx = "datasource0", additional_options={"transactionId":txId}) ... glueContext.commit_transaction(txId)

from_jdbc_conf

from_jdbc_conf(frame, catalog_connection, connection_options={}, redshift_tmp_dir = "", transformation_ctx="")

使用指定的 JDBC 连接信息编写一个 DynamicFrame

  • frame – 要编写的 DynamicFrame

  • catalog_connection – 要使用的目录连接。

  • connection_options – 连接选项,例如路径和数据库表 (可选)。

  • redshift_tmp_dir – 要使用的 Amazon Redshift 临时目录(可选)。

  • transformation_ctx – 要使用的转换上下文 (可选)。

write_dynamic_frame 示例

此示例结合使用 S3 的 connection_typeconnection_options 中的 POSIX 路径参数,在本地写入输出,从而允许将数据写入本地存储。

glueContext.write_dynamic_frame.from_options(\ frame = dyf_splitFields,\ connection_options = {'path': '/home/glue/GlueLocalOutput/'},\ connection_type = 's3',\ format = 'json')