Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS Glue:ETL作业创建许多空输出文件_Amazon Web Services_Aws Glue - Fatal编程技术网

Amazon web services AWS Glue:ETL作业创建许多空输出文件

Amazon web services AWS Glue:ETL作业创建许多空输出文件,amazon-web-services,aws-glue,Amazon Web Services,Aws Glue,我对这个很陌生,所以不确定这个脚本是否可以简化/我是否做了一些导致这种情况发生的错误。我已经为AWS Glue编写了一个ETL脚本,它可以写入S3存储桶中的目录 import sys from awsglue.transforms import * from awsglue.utils import getResolvedOptions from pyspark.context import SparkContext from awsglue.context import GlueContext

我对这个很陌生,所以不确定这个脚本是否可以简化/我是否做了一些导致这种情况发生的错误。我已经为AWS Glue编写了一个ETL脚本,它可以写入S3存储桶中的目录

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.dynamicframe import DynamicFrame
from awsglue.job import Job

## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

# catalog: database and table names
db_name = "events"
tbl_base_event_info = "base_event_info"
tbl_event_details = "event_details"

# output directories
output_dir = "s3://whatever/output"

# create dynamic frames from source tables
base_event_source = glueContext.create_dynamic_frame.from_catalog(database = db_name, table_name = tbl_base_event_info)
event_details_source = glueContext.create_dynamic_frame.from_catalog(database = db_name, table_name = tbl_event_details)

# join frames
base_event_source_df = workout_event_source.toDF()
event_details_source_df = workout_device_source.toDF()
enriched_event_df = base_event_source_df.join(event_details_source_df, "event_id")
enriched_event = DynamicFrame.fromDF(enriched_event_df, glueContext, "enriched_event")

# write frame to json files 
datasink = glueContext.write_dynamic_frame.from_options(frame = enriched_event, connection_type = "s3", connection_options = {"path": output_dir}, format = "json")
job.commit()
base\u event\u info
表有4列:
event\u id
event\u name
平台
客户端信息
event\u details
表有两列:
event\u id
event\u details

联接的表架构应该如下所示:
event\u id
event\u name
platform
client\u info
event\u details

在我运行这个作业之后,我希望得到2个json文件,因为这是结果联接表中的记录数。(表中有两条记录具有相同的
事件id
)但是,我得到的是大约200个文件,格式为
run-1540321737719-part-r-00000
run-1540321737719-part-r-00001
,等等:

  • 198个文件包含0个字节
  • 2个文件包含250个字节(每个文件具有与丰富事件对应的正确信息)

这是预期的行为吗?为什么这个作业会生成这么多空文件?我的剧本有什么问题吗

根据我的经验,空输出文件表明转换中存在错误。 您可以使用


顺便说一句,为什么要使用Spark数据帧而不是DynamicFrames进行连接?

Spark SQL模块包含以下默认配置:

spark.sql.shuffle.partitions设置为200

这就是为什么你首先要得到200个文件。 您可以通过执行以下操作来检查是否存在这种情况:

enriched_event_df.rdd.getNumPartitions()
如果得到的值为200,则可以使用以下代码根据要生成的文件数进行更改:

enriched_event_df.repartition(2)

上面的代码将只使用您的数据创建两个文件。

您可以通过spark sql转换步骤向数据帧添加
列式时间戳,而不是重新分区,并在将数据帧写入S3时将其作为分区键添加

例如:
从myDataSource中选择replace(replace(字符串(date_trunc('HOUR',current_timestamp()))、'-'、''、'':''、''、'','')作为datasetdate;*


使用
datasetdate
作为
partitionkey
编写dynamicframe时,glue job应该能够自动添加分区

Hello。。。检查//观察。。。你的答案阐述得很差。插入带有代码和参考的有效响应非常有用。总结出切实有效的解决方案。这个平台不仅仅是任何论坛。我们是世界上最大的帮助和支持其他程序员和开发人员的中心。回顾社区的条款,学习如何发布