0
votes

What is the pig script to find the length of a atom in a relation

say the below is my input file

abcd,10

abc,20

myinput = LOAD 'file' AS(str:chararray,num:int);

sized = FOREACH myinput GENERATE str, LENGTH(str) as my_length ,num;

dump sized;

The above script throw some error

All i need is to find the length of a atom in relation.

Could someone help

1

1 Answers

1
votes

Change

myinput = LOAD 'file' AS(str:chararray,num:int); 

to

myinput = LOAD '/root/stack/data/atom' using PigStorage(',') as (str:chararray,num:int);

reason: the default loading function expect 'tab' as a delimiter.

and

sized = FOREACH myinput GENERATE str, LENGTH(str) as my_length ,num; 

to

 sized = FOREACH myinput GENERATE str, SIZE(str) as my_length ,num;