150060275,NON-CRIMINAL,LOST PROPERTY,Monday,01/19/2015,14:00,MISSION,NONE,18TH ST / VALENCIA ST,-122.42158168137,37.7617007179518,"(37.7617007179518, -122.42158168137)",15006027571000
150098210,ROBBERY,"ROBBERY, BODILY FORCE",Sunday,02/01/2015,15:45,TENDERLOIN,NONE,300 Block of LEAVENWORTH ST,-122.414406029855,37.7841907151119,"(37.7841907151119, -122.414406029855)",15009821003074
在第二行中,第三个字段之间有一个',',不应该作为分隔符。我该如何解决这个问题?
如果我使用STRPLIT(),那么它适用于第二行,但会为第一行生成错误的结果。
答案 0 :(得分:0)
将其加载到单个字段中,用|替换逗号和空格然后在每一行上使用strsplit。
A = LOAD 'data.txt' USING TextLoader() AS (line:chararray);
B = FOREACH A GENERATE REPLACE(line,', ','|');
C = FOREACH B GENERATE STRSPLIT(B.$0,',',13);-- Assuming there are 13 fields.
或者,您可以使用CSVExcelStorage和PiggyBank。