Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Use of SIZE function in SUBSTRING for PIG

avatar
New Member

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
New Member

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