Pig Latin:chararray中的过滤器编号<5和> = 5(文本和数字)

问题描述 投票:-1回答:1

如何过滤或分组少于5年的人和超过5年的人。我是Pig Latin的新手。 ID,例如BUS2003应保持原样。

输入数据

ID,Experience
BUS2003,More than 17 years teaching experience
BUS1303,2 years teaching experience
BUS4543,13 plus years of teaching experience; 4 plus years of corporate experience
BUS2103,4 year + 6 years in business
BUS2913,8 yrs teaching experience

我知道如何将数据加载到PigStorage或CSVloader,但是,由于单词和数字在一起,我很难解决经验问题。

期望的结果:

**Less than five years**
BUS1303,2 years teaching experience
BUS2103,4 year + 6 years in business

**Equal or greater than five years**
BUS2003,More than 17 years teaching experience
BUS4543,13 plus years of teaching experience; 4 plus years of corporate experience
BUS2913,8 yrs teaching experience

提前致谢。

apache-pig
1个回答
1
投票

你必须提取数字,然后拆分。这应该得到你想要的

A = LOAD 'input.txt' USING PigStorage(',') AS (a1:chararray,a2:chararray);
B = FOREACH A GENERATE a1,a2,REGEX_EXTRACT(a2,'(\\d*)',1) as exp:int;
C = SPLIT B INTO C1 IF B.exp < 5, C2 IF B.exp >= 5;
DUMP C1;
DUMP C2;
© www.soinside.com 2019 - 2024. All rights reserved.