0
votes

This is my input file

a1,hello.VDF
a2,rim.VIM
a3.dr.VDD

I need output as below

a1,VDF
a2,VIM
a3,VDD

My script is the following:

myinput = LOAD 'file' USING PigStorage(',') AS(t1:chararray,t2:chararray); foreached= FOREACH myinput GENERATE t1,SUBSTRING(t2,INDEXOF(t2,'.',1),SIZE(t2));

It's throwing some error. Please help

2
Please define some error.merours

2 Answers

0
votes

SIZE returns long, but SUBSTRING takes integers, so you need to do conversion:

foreached = 
  FOREACH myinput GENERATE t1,SUBSTRING(t2,INDEXOF(t2,'.',1)+1,(int)SIZE(t2));
0
votes

Try this:

output = foreach myinput generate ((t1 matches '(.*)\\.(.*)'?SUBSTRING(t1, 0, 2):t1), (t1 matches '(.*)\\.(.*)'?SUBSTRING(t1, INDEXOF(t1,'.',0)+1, (int)SIZE(t1)):t2));