gpt4 book ai didi

csv - Pig 如何使用过滤器格式化半结构化 CSV

转载 作者:可可西里 更新时间:2023-11-01 15:02:23 26 4
gpt4 key购买 nike

我有半结构化的 CSV ,看起来像这样。

VTS,01,0099,7022606164,SP,GP,33,060646,A,1258.9805,N,07735.9303,E,0.0,278.6,280515,0000,00,4000,11,999,842,4B61
VTS,01,0099,7022606164,NM,GP,20,060637,A,1258.9805,N,07735.9302,E,0.0,278.6,280515,0000,00,4000,11,999,841,7407+++
VTS,66,0065,7022606164,NM,0,GP,22,060648,280515,1258.9804,N,07735.9301,E,04AE+++
VTS,01,0099,7022606164,NM,GP,22,060656,A,1258.9804,N,07735.9301,E,0.0,278.6,280515,0000,00,4000,11,999,843,8FEB+++
VTS,01,0099,7022606164,NM,GP,22,060721,A,1258.9803,N,07735.9304,E,0.0,278.6,280515,0000,00,4000,11,999,845,044D++++++
VTS,99,0065,7022606164,NM,0,A,GP,22,060648,280515,1258.9804,N,07735.9301,E,04AE+++
VTS,99,0065,7022606164,NM,0,A,GP,22,060648,280515,1258.9804,N,07735.9301,E,04AE

我想用这些数据制作三个不同的表格。即一个带有 VTS,01 另一个带有 VTS,99,另一个带有 VTS,66。同样,我还需要删除作为错误附加在每一行的“+++”,为此我编写了这个 pig 脚本。

data = load '/user/simulator/SKYTRACK/27thMay2015' using PigStorage('\n') as (f1:chararray);
splt = foreach data generate FLATTEN(STRSPLIT($0, '\\+++'));
data_pkt = FILTER splt BY $0 MATCHES '.*VTS,01+.*';
sos_pkt = FILTER splt BY $1 MATCHES '.*VTS,99+.*';
health_pkt = FILTER splt BY $2 MATCHES '.*VTS,66+.*';

当我为每个表单独测试此脚本时,只有一个输出,我收到其余没有输出,

转储数据_pkt;
转储 sos_pkt;
转储 health_pkt;

我对 pig 很陌生,所以任何人都可以帮助我解决这个问题..我将不胜感激。

最佳答案

要删除+++,您还需要转义所有“+”,而不仅仅是唯一的一个。您对这些加号的含义不是很具体。您宁愿使用该正则表达式来拆分:

 "\\+{3,}"

因此,在您的 pig 脚本中:

splt = foreach data generate FLATTEN(STRSPLIT($0, '\\+{3,}'));

尽管 Aman 是正确的,但是,我宁愿使用 SPLIT 而不是 FILTER 来分离数据集:

 a = load '/abc.txt';
SPLIT a INTO
b01 IF $1 == 01,
b66 IF $1 == 66,
b99 IF $1 == 69;

关于csv - Pig 如何使用过滤器格式化半结构化 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30615261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com