![](/img/trans.png)
[英]How to write one Json file for each row from the dataframe in Scala/Spark and rename the files
[英]How to write each row of a spark dataframe to different Hive tables (using Scala)?
我有一個火花數據框,如下所示。 第一列包含聚會文本文件的內容(使用sc.wholeTextfile讀取)。 第二行包含標識符文本文件的內容。 現在,我必須遍歷以下數據框的每一行,並寫入不同的配置單元表。 第一行應寫入Party表,第二行應寫入Identifier表,依此類推。
當我使用dataframe.foreaach遍歷此數據幀時,無法使用spark會話,因為spark會話不可序列化。
+--------------------+--------------+
| content| TblNm|
+--------------------+--------------+
|DSP_ID|DSP_PARTY_...| Party|
|DSP_ID|DSP_Party_...| Identifier|
|DSP_ID|DSP_Party_...| Communication|
|DSP_ID|DSP_Party_...| Individual|
|DSP_ID|DSP_Party_...| Language|
|DSP_ID|DSP_Party_...| Name|
|DSP_ID|DSP_Party_...| Certification|
|DSP_ID|DSP_Party_...|Classification|
|DSP_Id|DSP_Party_...| Organization|
|DSP_ID|DSP_Party_...| Address|
|DSP_Id|DSP_Party_...| Specialty|
|DSP_ID|Parent_DSP...| Relationship|
|DSP_ID|DSP_Party_...| Role|
+--------------------+--------------+
緩存數據幀並使用N df.write ...語句-帶有過濾器。
實際上,可序列化意味着Spark無法以這種方式工作,因為您注意到使用Hadoop的Spark會話的表,從jdbc到mysql的表等。您可以使用foreach等,但不能通過df.write。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.