【发布时间】:2018-04-26 05:20:57
【问题描述】:
我有一个包含两个字符串列(术语、代码)的 CSV 文件。代码列具有特殊格式[num]-[two_letters]-[text],其中text 还可以包含破折号-。我想使用 Spark 将这个文件读入一个正好有四列(term、num、two_letters、text)的数据框。
Input
+---------------------------------+
| term | code |
+---------------------------------+
| term01 | 12-AB-some text |
| term02 | 130-CD-some-other-text |
+---------------------------------+
Output
+------------------------------------------+
| term | num | letters | text |
+------------------------------------------+
| term01 | 12 | AB | some text |
| term02 | 130 | CD | some-other-text |
+------------------------------------------+
当code 部分中没有破折号时,我可以将code 列拆分为三列,但是我如何才能实现解决所有情况的解决方案(例如将两个破折号后的所有文本放入一列)?
将一列分成三列的代码在答案here中得到了很好的说明
【问题讨论】:
标签: scala apache-spark