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

相关内容

热门资讯

一分钟揭秘!微扑克有辅助软件吗... 一分钟揭秘!微扑克有辅助软件吗,aapoker挂,我来教教你(固有有挂)1、aapoker挂ai辅助...
重大发现!wpk德州辅助,we... 重大发现!wpk德州辅助,wepoke有挂,微扑克教程(原本有挂)1.wepoke有挂 ai辅助创建...
总算明白!微扑克辅助器是真的么... 总算明白!微扑克辅助器是真的么,德州ai辅助有用,力荐教程(都是是真的有挂)1、构建自己的微扑克辅助...
玩家必备科技!gg扑克辅助,w... 玩家必备科技!gg扑克辅助,wepoke辅助有挂,AI教程(确实真的是有挂)1、在wepoke辅助有...
重大来袭!cloudpoker... 重大来袭!cloudpoker辅助器,wepoke真的有挂,力荐教程(固有真的有挂)1、wepoke...
最新技巧!wepoke透明真的... 最新技巧!wepoke透明真的吗,智星德州菠萝有挂吗,AI教程(最初有挂);人气非常高,ai更新快且...
一分钟快速了解!德州微扑克辅助... 一分钟快速了解!德州微扑克辅助,德州微扑克辅助,高科技教程(好像存在有挂)是一款可以让一直输的玩家,...
一分钟教会你!wpk有吗,德州... 一分钟教会你!wpk有吗,德州ai辅助软件,玩家教你(固有是真的有挂)德州ai辅助软件辅助器中分为三...
实操分享!微扑克辅助,德州ai... 实操分享!微扑克辅助,德州ai机器人,科技教程(真是有挂)1、超多福利:超高返利,海量正版游戏,德州...
玩家必看科普!微扑克有辅助软件... 自定义aapoker辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不...