DynamicFrameWriter 类
Methods
__init__
__init__(glue_context)
glue_context– 要使用的 GlueContext 类。
from_options
from_options(frame, connection_type, connection_options={},
format=None, format_options={}, transformation_ctx="")
使用指定的连接和格式编写一个 DynamicFrame。
frame– 要编写的DynamicFrame。connection_type– 连接类型。有效值包括s3、mysql、postgresql、redshift、sqlserver和oracle。connection_options– 连接选项,例如路径和数据库表 (可选)。对于connection_type的s3,将会定义 Amazon S3 路径。connection_options = {"path": "s3://aws-glue-target/temp"}对于 JDBC 连接,必须定义多个属性。请注意,数据库名称必须是 URL 的一部分。它可以选择性地包含在连接选项中。
警告
不建议在脚本中存储密码。请考虑使用
boto3从 AWS Secrets Manager 或 AWS 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”架构。有关更多信息,请参阅 AWS Glue for Spark 中适用于 ETL 的连接类型和选项。
format– 格式规范(可选)。这用于 Amazon Simple Storage Service(Amazon S3)或支持多种格式的 AWS Glue 连接。有关支持的格式,请参阅 AWS Glue for Spark 中的输入和输出的数据格式选项。format_options– 指定格式的格式选项。有关支持的格式,请参阅 AWS 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提供给 AWS Glue 的额外选项。要写入 Lake Formation 受管表,可以使用以下附加选项:
-
transactionId–(字符串)用于写入受管表的事务 ID。此事务无法提交或中止,否则写入将失败。 -
callDeleteObjectsOnCancel–(布尔值,可选)如果设置为true(原定设置)、则在将对象写入 Amazon S3 后 AWS Glue 将自动调用DeleteObjectsOnCancelAPI。有关更多信息,请参阅 AWS 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_type 与 connection_options 中的 POSIX 路径参数,在本地写入输出,从而允许将数据写入本地存储。
glueContext.write_dynamic_frame.from_options(\ frame = dyf_splitFields,\ connection_options = {'path': '/home/glue/GlueLocalOutput/'},\ connection_type = 's3',\ format = 'json')