如何在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屋!
查看全文