Support Questions

Find answers, ask questions, and share your expertise

Use of SIZE function in SUBSTRING for PIG

avatar

I have a simple data covering the salary in USD like "$36200" as chararray. I am trying to remove the leading $ symbol through the SUBSTRING function as below:

D = FOREACH C GENERATE SUBSTRING(wage, 1, SIZE(wage)) as wage_new;

I am getting an error like this:

ERROR org.apache.pig.tools.grunt.Grunt - 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.

However, if I am using the StopIndex of the SUBSTRING function explicitly, then the code compiles. But I would like to get to the end of the string dynamically.

Can somebody help me ?

1 ACCEPTED SOLUTION

avatar

Hi @Subhasis Roy,

Substring wants Integer parameters while Size returns Long. Try casting the size to Int like this:

D = FOREACH C GENERATE SUBSTRING(wage, 1, (int)SIZE(wage)) as wage_new;

View solution in original post

2 REPLIES 2

avatar

Hi @Subhasis Roy,

Substring wants Integer parameters while Size returns Long. Try casting the size to Int like this:

D = FOREACH C GENERATE SUBSTRING(wage, 1, (int)SIZE(wage)) as wage_new;

avatar

Great !! Thanks a lot for the help. It works now.