AWSGlueETLJob:Bookmark还是Overwrite-最佳实践?
创始人
2024-09-25 15:01:41
0

在AWS Glue ETL作业中,决定应该使用书签或覆盖的最佳实践取决于源数据的特性和作业的要求。

对于只能追加数据的源数据,例如日志文件或Kinesis数据流,最好使用书签。这可以确保每次作业运行时仅处理新的数据。以下是使用书签的代码示例:

from awsglue.utils import getResolvedOptions
from awsglue.context import GlueContext
from awsglue.dynamicframe import DynamicFrame

args = getResolvedOptions(sys.argv, ['JOB_NAME'])

# create a Glue context
glueContext = GlueContext(SparkContext.getOrCreate())

# read in the data using the bookmark option
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "mydatabase", table_name = "mysourcetable", transformation_ctx = "datasource0", additional_options = {"bookmarkKeys": ["id", "timestamp"]})

# apply your transformations
# ...
  
# write the data using the bookmark option
glueContext.write_dynamic_frame.from_options(frame = transformed, connection_type = "s3", connection_options = {"path": "s3://mybucket/myoutputpath/",
"partitionKeys": ["year", "month", "day", "hour"]}, format = "parquet", transformation_ctx = "datasink")

对于可以覆盖现有数据的源数据,最好使用覆盖。这可以确保每次作业运行时处理整个数据集。以下是使用覆盖的代码示例:

# read in the data using the overwrite option
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "mydatabase", table_name = "mysourcetable", transformation_ctx = "datasource0", additional_options = {"option": "OVERWRITE_FILES"})

# apply your transformations
# ...
  
# write the data using the overwrite option
glueContext.write_dynamic_frame.from_options(frame = transformed, connection_type = "s3", connection_options = {"path": "s3://mybucket/myoutput

相关内容

热门资讯

四分钟发现!点点长牌辅助工具教... 四分钟发现!点点长牌辅助工具教程(辅助挂)原来确实有挂(攻略方法开挂辅助脚本);无需打开直接搜索打开...
第1分钟明白!靖边打锅子奇迹陕... 【亲,靖边打锅子奇迹陕西辅助下载 这款游戏可以开挂的,确实是有挂的,很多玩家在这款靖边打锅子奇迹陕西...
第六分钟了解!中至江西源代码(... 第六分钟了解!中至江西源代码(辅助挂)一直真的是有挂(AI教程开挂辅助脚本);无需打开直接搜索薇:1...
1分钟开挂!潮汕汇软件辅助(辅... 1分钟开挂!潮汕汇软件辅助(辅助挂)果然确实有挂(2026教程开挂辅助插件);无需打开直接搜索加薇1...
第六分钟明白!人海大厅挂件怎么... 第六分钟明白!人海大厅挂件怎么买(辅助挂)其实真的是有挂(2026新版教程开挂辅助平台)您好:人海大...
第2分钟开挂!牛总管辅助免费版... 第2分钟开挂!牛总管辅助免费版(辅助挂)其实是有挂的(新版2026教程开挂辅助神器)《详细加薇136...
5分钟科普!九九山城万州版脚本... 5分钟科普!九九山城万州版脚本(辅助挂)原来真的有挂(扑克教程!开挂辅助神器) >>您好:软件加薇1...
第3分钟讲究!友间十三道有什么... 第3分钟讲究!友间十三道有什么窍门(辅助挂)原来确实有挂(玩家教程开挂辅助软件)《详细加薇13670...
四分钟辅助!阿当比鸡破解版2.... 四分钟辅助!阿当比鸡破解版2.0.0(辅助挂)果然确实有挂(教你教程开挂辅助平台)1、下载安装好阿当...
第三分钟开挂!西兵辅助器(辅助... 第三分钟开挂!西兵辅助器(辅助挂)原来是有挂的(玩家教程开挂辅助脚本) 了解更多开挂安装加(1367...