我是 Pig 的完整初学者。我已经安装了 cdh4 pig 并且连接到了 cdh4 集群。我们需要处理这些大量的 Web 日志文件(这些文件已经被加载到 HDFS)。不幸的是,日志语法非常复杂(不是典型的逗号分隔文件)。一个限制是我目前无法使用其他工具预处理日志文件,因为它们太大并且无法存储副本。这是日志中的原始行:
"2013-07-02 16:17:12 -0700","?c=Thing.Render&d={%22renderType%22:%22Primary%22,%22renderSource%22:%22Folio%22,%22things%22:[ {%22itemId%22:%225442f624492068b7ce7e2dd59339ef35%22,%22userItemId%22:%22873ef2080b337b57896390c9f747db4d%22,%22listId%22:%22bf5bbeaa8eae459a83fb9e2ceb99930d%22,%22ownerId%22:%222a4034e6b2e800c3ff2f128fa4f1b387%22}],%22redirectId%22:%22tgvm %22,%22sourceId%22:%226da6f959-8309-4387-84c6-a5ddc10c22dd%22,%22valid%22:false,%22pageLoadId%22:%224ada55ef-4ea9-4642-ada5-d053c45c00a4%22,%22clientTime%22 :%222013-07-02T23:18:07.243Z%22,%22clientTimeZone%22:5,%22process%22:%22ml.mobileweb.fb%22,%22c%22:%22Thing.Render%22}", "http://m.someurl.com/listthing/5442f624492068b7ce7e2dd59339ef35?rdrId=tgvm&userItemId=873ef2080b337b57896390c9f747db4d&fmlrdr=t&itemId=5442f624492068b7ce7e2dd59339ef35&subListId=bf5bbeaa8eae459a83fb9e2ceb99930d&puid=2a4034e6b2e800c3ff2f128fa4f1b387&mlrdr=t ","Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, 像 Gecko) Mobile/10B329 [FBAN/FBIOS;FBAV/6.2;FBBV/228172;FBDV/iPhone4,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/6.1.3;FBSS/2; FBCR/Sprint;FBID/电话;FBLC/en_US;FBOP/1]","10.nn.nn.nnn","nn.nn.nn.nn, nn.nn.0.20"
您可能注意到那里嵌入了一些 json,但它是 url 编码的。在 url 解码之后(Pig 可以做 url 解码吗?)这是 json 的样子:
{"renderType":"Primary","renderSource":"Folio","things":[{"itemId":"5442f624492068b7ceowner7e2dd59339ef35","userItemId":"873ef2080b337b57896390c9f747db4d","listId":"bf5bbeae2eae4599adf""bf5bbea8eae4599adf" :"2a4034e6b2e800c3ff2f128fa4f1b387"}],"redirectId":"tgvm","sourceId":"6da6f959-8309-4387-84c6-a5ddc10c22dd","valid":false,"pageLoadId":"4ada55ef-4ea9-4642-ada5- d053c45c00a4","clientTime":"2013-07-02T23:18:07.243Z","clientTimeZone":5,"process":"ml.mobileweb.fb","c":"Thing.Render"}
我需要提取 json 中的不同字段和实际上是一个集合的“事物”字段。我还需要提取日志中的其他查询字符串值。Pig 可以直接处理这种源数据吗?如果可以,您能否指导我如何让 Pig 能够解析和加载它?
谢谢!