val df = spark.read.option("multiline", "true").json("/FileStore/tables/config-5.json")
df.show()
输出:
+--------------+-------------------+
| List-col| Matrics|
+--------------+-------------------+
|[number, word]|ApproxCountDistinct|
|[number, word]| Completeness|
+--------------+-------------------+
代码:
for (row <- df.rdd.collect) {
var List_col =(row(0))
var Matricsdynamic = row(1)
List_col.foreach(c =>print(c) )
//MatricsCal.ApproxCountDistinct_func(listofStr)
}
因为list col应该是一个字符串列表,所以我得到wrappedarray(number,word)wrappedarray(number,word)。我需要列表(字符串)。
2条答案
按热度按时间bfrts1fy1#
您应该能够使用
toList
方法WrappedArray
.假设您的json文件如下所示:
您可以获取一个记录数组,每个记录都是一个
List[String]
.hec6srdp2#
我假设您需要从list col中获取第二个元素,这样您就可以得到: