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

相关内容

热门资讯

第六分钟讲解!花花生活圈私人局... 您好:花花生活圈私人局辅助器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
6分钟详情!边锋老友填大坑辅助... 边锋老友填大坑辅助是一款专注玩家量身打造的游戏记牌类型软件,在边锋老友填大坑辅助这款游戏中我们可以记...
第九分钟发现!随意玩房卡代理有... 第九分钟发现!随意玩房卡代理有挂吗(辅助挂)果然有挂(必胜教程开挂辅助下载)【无需打开直接搜索加薇1...
四分钟了解!途游四川bug(辅... 途游四川bug 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1、...
第8分钟明白!情怀透明器看手机... 第8分钟明白!情怀透明器看手机纸牌(辅助挂)其实真的是有挂(AI教程开挂辅助软件);超受欢迎的情怀透...
第六分钟透视!微乐小程序游戏破... 第六分钟透视!微乐小程序游戏破解器(辅助挂)原来是有挂(普及教程开挂辅助神器);无需打开直接搜索薇:...
5分钟发现!广西友乐解码器下载... 5分钟发现!广西友乐解码器下载安装(辅助挂)果然是有挂(介绍教程开挂辅助安装) 了解更多开挂安装加(...
第六分钟科普!湖北休闲辅助(辅... 第六分钟科普!湖北休闲辅助(辅助挂)一直确实有挂(安装教程开挂辅助神器)1、下载安装好湖北休闲辅助,...
第二分钟辅助!至余干辅助(辅助... 第二分钟辅助!至余干辅助(辅助挂)其实确实有挂(教你攻略开挂辅助平台) >>您好:软件加薇13670...
7分钟辅助!仟众部落辅助(辅助... 7分钟辅助!仟众部落辅助(辅助挂)其实确实有挂(德州论坛开挂辅助平台);亲,仟众部落辅助这款游戏原来...