我有这样一个结构的数据帧:星火据帧 - 如何从一列的特定领域连续
root
|-- npaDetails: struct (nullable = true)
| |-- additionalInformation: struct (nullable = true)
| |-- npaStatus: struct (nullable = true)
| |-- npaDetails: struct (nullable = true)
|-- npaHeaderData: struct (nullable = true)
| |-- npaNumber: string (nullable = true)
| |-- npaDownloadDate: string (nullable = true)
| |-- npaDownloadTime: string (nullable = true)
我想从数据帧中的所有行检索所有npaNumber
。
我的方法是迭代数据帧中的所有行,以便为每个数据提取存储在列npaHeaderData
(字段npaNumber
)中的值。因此,我将以下代码行:
parquetFileDF.foreach { newRow =>
//To retrieve the second column
val column = newRow.get(1)
//The following line is not allowed
//val npaNumber= column.getAs[String]("npaNumber")
println(column)
}
在每次迭代中印刷的列的内容是这样的:
[207400956,27FEB17,09.30.00]
但是column
是键入Any并且我不能提取它的任何字段。任何人都可以告诉我做错了什么,或者我应该遵循什么方法而不是这个?
感谢
做一个新的数据帧,是点? –
@MehdiBenHamida我需要在我的算法的第一步,从列中检索一个字段,因为我将使用该值作为今后opperations参考。所以我需要保留所有列。但是,对于这一步,你是对的,我可以选择我的第二列。 –