简体   繁体   English

如何使用 AWS Glue 从 S3 存储桶合并 CSV 文件并将其保存回 S3

[英]How to merge CSV file from S3 bucket and save it back into S3 using AWS Glue

Objective is to transform the data (csv files) from one S3 bucket to another S3 bucket - using Glue.目标是使用 Glue 将数据(csv 文件)从一个 S3 存储桶转换为另一个 S3 存储桶。

What I already tried:我已经尝试过的:

I created a CSV classifier.我创建了一个 CSV 分类器。 I created a crawler which scans the data coming in S3 bucket.我创建了一个爬虫来扫描 S3 存储桶中的数据。 Where I am stuck:我被困的地方:

Unable to find how can we store the output in S3 again without saving it in any RDS or other database services.无法找到如何将输出再次存储在 S3 中而不将其保存在任何 RDS 或其他数据库服务中。 Because Glue output is asking for database output, which I don't have and don't want to use.因为 Glue 输出要求数据库输出,我没有也不想使用。

Is there any way I can achieve the goal without using any other DB system, just plain - S3, Glue?有什么方法可以在不使用任何其他数据库系统的情况下实现目标,只是简单的 - S3,Glue?

More Information Sample single CSV file, I am trying to merge更多信息示例单个 CSV 文件,我正在尝试合并

在此处输入图片说明

Classifier with delimeter of ";"分隔符为“;”的分类器

在此处输入图片说明

Crawler Configuration爬虫配置

在此处输入图片说明

Crawler Result (No schema detected)爬虫结果(未检测到架构)

在此处输入图片说明

The reason why Glue crawler detected schema is UNKNOWN because of the number of rows present in the source files.由于源文件中存在的行数,Glue 爬网程序检测到架构的原因是未知的。 Refer to section Built-In CSV Classifier in this doc which you are using in your case.请参阅本 文档中您在案例中使用的内置 CSV 分类器部分。

According to the doc to be classified as CSV, the table schema must have at least two columns and two rows of data.根据要归类为CSV的文档,表模式必须至少有两列两行数据。

In your case you can use AWS Glue job and read files directly from S3 using either of below ways:在您的情况下,您可以使用 AWS Glue 作业并使用以下任一方式直接从 S3 读取文件:

1.Create a dynamicframe and pass spearator as ; 1.创建一个动态框架并将spearator作为; in format_options.在格式选项中。 Below is sample which you can modify according to your needs.以下是您可以根据需要进行修改的示例。

dyF = GlueContext.create_dynamic_frame_from_options(connection_type="s3",connection_options = {"paths": [InputDir]},format="csv",format_options={"withHeader": True,"separator": ";","quoteChar": '"',"escaper": '"'},transformation_ctx = "taxidata")

2.Use spark dataframe to read data from S3 and then convert it back to dynamicframe if you want to levarage Glue native transformations: 2.如果您想利用 Glue 原生转换,请使用 spark 数据帧从 S3 读取数据,然后将其转换回动态帧:

df = spark.read.options(delimiter=';').csv("s3://path-to-files/")

If you want to merge files with different schemas then read data containing different schema into different frames of your choice and then merge them using a Join operator.如果要合并具有不同架构的文件,则将包含不同架构的数据读取到您选择的不同框架中,然后使用 Join 运算符合并它们。

Refer to this which has example code to join and write data back to s3.请参阅this ,其中包含用于将数据连接并写回 s3 的示例代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Glue 作业将 JSON 从 s3 转换为 CSV 文件并将其保存在同一个 s3 存储桶中 - How to convert JSON to CSV file from s3 and save it in same s3 bucket using Glue job 使用 Glue 从 S3 存储桶转换 CSV 文件并将转换后的数据保存回另一个 S3 存储桶 - Using Glue to transform CSV file from S3 bucket and saving the transformed data back into another S3 bucket 如何使用 AWS GLUE 对 S3 CSV 文件进行排序 - How to sort S3 CSV File using AWS GLUE 使用AWS Glue将JSON文件写入S3存储桶 - Using AWS Glue to write a JSON file to an S3 bucket 如何在不使用复制命令的情况下使用 AWS Glue 将 s3 存储桶上的 csv 文件中的数据导入/加载到 Redshift - How to import/load data from csv files on s3 bucket into Redshift using AWS Glue without using copy command 在AWS中如何使用lambda函数将文件从一个s3存储桶复制到另一个s3存储桶 - In AWS how to Copy file from one s3 bucket to another s3 bucket using lambda function 将 output 文件保存到 AWS S3 存储桶中 - Save output file into AWS S3 Bucket 从 S3 解压缩文件并将其写回 S3 的 AWS Glue 作业 - AWS Glue job to unzip a file from S3 and write it back to S3 如何合并 AWS S3 存储桶策略? - How to merge AWS S3 bucket policies? AWS 将文件从 lambda 目录 /tmp/ 保存到 S3 存储桶 - AWS save a file from lambda directory /tmp/ to S3 bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM