如何获取Spark数据框中记录的输入文件名? [英] how to get input file name of a record in spark dataframe?
本文介绍了如何获取Spark数据框中记录的输入文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过从s3加载制表符分隔的文件在spark中创建一个数据框.我需要获取数据框中每个记录的输入文件名信息,以进行进一步处理.我尝试过
I am creating a dataframe in spark by loading tab separated files from s3. I need to get the input file name information of each record in the dataframe for further processing. I tried
dataframe.select(inputFileName())
但是我获得了input_file_name的空值.有人请帮助我解决这个问题.
But I am getting null value for input_file_name. somebody please help me to solve this issue.
推荐答案
您可以使用withColumn
和input_file_name()
在数据框中创建新列:
You can create a new column on the data frame using withColumn
and input_file_name()
:
dataframe.withColumn("input_file", input_file_name())
这篇关于如何获取Spark数据框中记录的输入文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文