How to avoid an error when using "SIZE" with "SUBSTRING" in Pig
I'm trying to extract all but the last character of a string using Pig
0.10, and I'm not understanding the error.
grunt> cat test.txt
abcd
grunt> data = LOAD 'test.txt' USING PigStorage() AS word:chararray;
sub = FOREACH data GENERATE SUBSTRING(word, 0, 3);
DUMP sub
(abc)
len = FOREACH data GENERATE SIZE(word) - 1;
DUMP len
(3)
sub2 = FOREACH data GENERATE SUBSTRING(word, 0, SIZE(word) - 1);
DUMP sub2
ERROR 1045: Could not infer the matching function for
org.apache.pig.builtin.SUBSTRING as multiple or none of them fit. Please
use an explicit cast.
Hi DID u manage to figure out how to overcome it? Please explain
ReplyDeletegeneratedRecords = FOREACH relation3 {
DeleteGENERATE SUBSTRING(log_date, 1, ((int) SIZE(log_date)) - 1) as logDate, SUBSTRING(log_level,1, ((int) SIZE(log_level)) - 1) as logLevel;
};