且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

迭代 Spark 数据帧中的行和列

更新时间:2023-11-18 21:30:10

您可以使用 toSeqRow 转换为 Seq.一旦转向 Seq,你可以像往常一样使用 foreachmap 或任何你需要的东西

You can convert Row to Seq with toSeq. Once turned to Seq you can iterate over it as usual with foreach, map or whatever you need

    sqlDF.foreach { row => 
           row.toSeq.foreach{col => println(col) }
    }

输出:

Berta
bbb
30
Joe
Andy
aaa
20
ccc
40