【发布时间】:2017-06-09 10:32:39
【问题描述】:
我有一个从 JSON 文件导入的 PySpark RDD。 数据元素包含许多具有不需要的字符的值。为了论证,只有那些 string.printable 的字符应该在那些 JSON 文件中。
鉴于有大量包含文本信息的元素,我一直在尝试找到一种将传入的 RDD 映射到函数以清理数据并返回清理后的 RDD 作为输出的方法。 我可以找到从 RDD 中打印清理过的元素而不是整个元素集合然后作为 RDD 返回的方法。
一个示例文档可能如下所示,不需要的字符可能会潜入 userAgent、marketingReference 和 pageTags 元素或任何文本元素中。
{
"documentId": "abcdef12-1234-5678-fedc-cba9876543210",
"documentType": "contentSummary",
"dateTimeCreated": "2017-01-01T03:00:22.478Z"
"body": {
"requestUrl": "http://www.our-web-site.com/en-gb/line-of-business/product-category/irritating-guid/",
"requestMethod": "GET",
"responseCode": "200",
"userAgent": "Mozilla/5.0 etc",
"requestHeaders": {
"connection": "close",
"host": "www.our-web-site.com",
"accept-language": "en-gb",
"via": "1.1 www.our-web-site.com",
"user-agent": "Mozilla/5.0 etc",
"x-forwarded-proto": "https",
"clientIp": "99.99.99.99",
"referer": "http://www.our-web-site.com/en-gb/line-of-business/product-category/irritating-guid/",
"accept-encoding": "gzip, deflate",
"incap-client-ip": "99.99.99.99"
},
"body": {
"pageId": "/content/our-web-site/en-gb/holidays/interstitial",
"pageVersion": "1.0",
"pageClassification": "product-page",
"pageTags": "spark, python, rdd, other words",
"MarketingReference": "BUYMEPLEASE",
"referrer": "http://www.our-web-site.com/en-gb/line-of-business/product-category/irritating-guid/",
"webSessionId": "abcdef12-1234-5678-fedc-cba9876543210"
}
}
}
【问题讨论】:
-
您能否提供 RDD 的样本(例如使用 rdd.take(5))?
-
很遗憾不是因为数据机密性。
-
能否分享一下RDD的格式,可以用“key1”、“value1”等代替真实值。我对数据结构感兴趣,而不是实际内容
-
我已将 RDD 的 JSON 源添加到问题中。 userAgent、pageTags、MarketingReference 和正文中的许多其他标签都受到不良字符的影响。 body 中的所有元素都是 "key":"value" 格式,没有进一步的嵌套。 JSON 文档是从我无法控制或影响的来源接收的。
-
如果您只是在将原始数据转换为 rdd 之前清理它们会怎样?
标签: python-3.x apache-spark pyspark rdd