json - 使用 pyspark 将 Outlook 电子邮件转换为 json 文件格式
问题描述
我有大约 1 封 lac Outlook 电子邮件,并希望使用 pyspark 的分布式功能将它们转换为 json 格式。Outlook 电子邮件首先以 .msg 格式保存,然后执行将其转换为 json 格式的 python 算法。由于邮件的数量很大,有没有办法利用 pyspark 的实现,利用 spark 的分布式计算优势,将所有的 msg 文件转换为 json?
解决方案
你确实可以用 pyspark 做到这一点,但我不能保证性能。
# first, acquire your data as a whole
rdd = sc.wholeTextFile("/path/to/files.msg")
# each line of your rdd will be a (key,value) pair where key is the path and value is the content of the file
# you need then to apply your python function to the "value"
json_rdd = rdd.map(lamba x : msg_to_json(x[1])
# json_rdd should now contain a json on each line, you just need to write it down
json_rdd.saveAsTextFile("/path/to/save/files.json")
在您这边,您只需要准备将msg_to_json
msg 文件的内容作为条目中的字符串并返回 json 文件的函数。
编辑:
使用您的库,它将是:
import extract_msg
rdd = sc.binaryFiles("/path/to/files.msg")
rdd = rdd.map(extract_msg.Message)
推荐阅读
- angular - 使用 Angular jasmine 测试获取请求返回未定义
- c# - 如何在我自己的 UWP 应用程序中从边缘原生应用程序重新创建反馈窗口?
- haskell - 什么是 setup.Cabal?为什么我会收到构建错误?
- javascript - http-proxy-middleware React Python Flask 未按预期工作
- php - 如何显示以空格和逗号分隔的参数值?
- javascript - 隐藏透明 div 后面的元素但不是背景
- php - Axios 无法在 Mac 上运行 - 安装在 Vue 中的 Safari / chrome
- c - 在 Linux 上的 C 程序中屏蔽密码字符
- android - 为什么只有某些用户的 EditText 中缺少粘贴选项?
- react-native - 保持来自其他应用程序的背景音频活着,react-native-video IOS