AWS Glue 支持两种不同的运行模式:标准模式和增量模式。
标准模式运行时,AWS Glue 会扫描整个数据源,并将所有数据加载到目标中。这适用于小型数据集,因为它们可以很快处理完毕,但对于大数据集来说,会导致资源的浪费。
增量模式运行时,AWS Glue 会跟踪源数据的更改,并仅插入或更新新数据。这种方法可以节省大量的计算资源,并提高处理速度。
示例代码:
glue_context = GlueContext(SparkContext.getOrCreate()) job = Job(glue_context) args = getResolvedOptions(sys.argv, ['JOB_NAME']) job.init(args['JOB_NAME'], args)
datasource = args['input'] df = glue_context.create_dynamic_frame_from_options( connection_options={'paths': [datasource]}, format='csv', transformation_ctx='DataSource' )
df.toDF().write.mode('append').jdbc( url=jdbcUrl, table=args['table'], mode='append', properties=connectionProperties )
job.commit()