简体   繁体   English

如何使用 AWS Glue ETL 工具从 S3 读取文件名

[英]How to Read Filename from S3 using AWS Glue ETL Tools

I have a some files in S3 that look like this (all in the same path):我在 S3 中有一些看起来像这样的文件(都在同一路径中):

group1_20210415.csv
group2_20210415.csv
group1_20210416.csv
group2_20210416.csv

The schema for each file is rather simple:每个文件的架构相当简单:

group1_name, group1_id
group2_name, group2_id

I want to be able to query these names and ids from S3 with Athena, and use AWS Glue to crawl that S3 location when new files are present.我希望能够使用 Athena 从 S3 查询这些名称和 ID,并在存在新文件时使用 AWS Glue 抓取该 S3 位置。

Specifically, I want to have a table in Athena with schema:具体来说,我想在 Athena 中有一个带有架构的表:

group1_name, group1_id, group2_name, group2_id, hit_date

My intuition says to use AWS Glue PySpark to combine the data in the S3 files into a single DataFrame, which is simple enough.我的直觉是使用 AWS Glue PySpark 将 S3 文件中的数据组合成一个 DataFrame,这很简单。 However, the date for each file exists in the file name itself not in the data.但是,每个文件的日期存在于文件名本身而不是数据中。

Is there a way to extract the 'date' part of the filename and use that as a column in the AWS Glue PySpark DataFrame?有没有办法提取文件名的“日期”部分并将其用作 AWS Glue PySpark DataFrame 中的列? If not, does anyone's intuition suggest an alternative method?如果没有,是否有人的直觉提出了另一种方法?

You could try this: data_frame.withColumn("input_file", input_file_name()) You can then transform this column to extract the date.你可以试试这个: data_frame.withColumn("input_file", input_file_name())然后你可以转换这个列来提取日期。

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

相关问题 运行 AWS Glue ETL 作业并命名 output 文件名时,有没有办法从 S3 存储桶读取文件名。 pyspark 是否提供了一种方法来做到这一点? - Is there a way to read filename from S3 bucket when running AWS Glue ETL job and name the output filename. Does pyspark provide a way to do it? AWS Glue:ETL 读取 S3 CSV 文件 - AWS Glue: ETL to read S3 CSV files 从 AWS Redshift 到 S3 的 AWS Glue ETL 作业失败 - AWS Glue ETL job from AWS Redshift to S3 fails 使用 AWS Glue ETL 将镶木地板文件从 S3 加载到 AWS RDS 需要很长时间 - Loading parquet file from S3 to AWS RDS taking extremely long time using AWS Glue ETL AWS胶水ETL作业在批次的S3事件上触发 - AWS Glue ETL Job triggered on batches of S3 Events AWS Glue ETL:将数据传输到S3存储桶 - AWS Glue ETL : transfer data to S3 Bucket 在 AWS Glue ETL 作业中从 S3 加载分区的 json 文件 - Load partitioned json files from S3 in AWS Glue ETL jobs 如何通过 S3 事件或 AWS Lambda 触发 Glue ETL Pyspark 作业? - How to Trigger Glue ETL Pyspark job through S3 Events or AWS Lambda? 如何使用 AWS Glue 从 S3 存储桶合并 CSV 文件并将其保存回 S3 - How to merge CSV file from S3 bucket and save it back into S3 using AWS Glue 从 S3 存储桶读取的 AWS Glue 限制数据 - AWS Glue Limit data read from S3 Bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM