简体   繁体   English

处理输入文件模式时如何在 apache 光束中的 DoFn 中获取文件名

[英]How to get fileName inside DoFn in apache beam while processing input file pattern

I am processing large no of files which are inside one directory.我正在处理一个目录中的大量文件。 I want to add fileName in metadata of processed data output.我想在已处理数据 output 的元数据中添加文件名。 So that if something goes wrong while processing, we can check that what is input file for the processed record.因此,如果在处理过程中出现问题,我们可以检查处理记录的输入文件是什么。

Is there a way i can get file name inside my DoFn.有没有办法我可以在我的 DoFn 中获取文件名。 I am using apache beam 2.19.0 version我用的是apache梁2.19.0版

Input file location - gs://bucket/extracted-files/*输入文件位置 - gs://bucket/extracted-files/*

You can use transforms available in FileIO class for this purpose.为此,您可以使用FileIO class中可用的转换。

Specially you can use FileIO.match() followed by FileIO.readMatches() which results in a PCollection of ReadableFile objects.特别是您可以使用FileIO.match()后跟FileIO.readMatches() ,这会导致ReadableFile对象的PCollection For each ReadableFile you have access to a byte channel for reading as well as a Metadata object that contains the name of the file.对于每个ReadableFile ,您都可以访问一个字节通道进行读取,以及一个包含文件名称的Metadata object。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM