- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Use of SIZE function in SUBSTRING for PIG
- Labels:
-
Apache Pig
Created ‎05-07-2016 08:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
Created ‎05-07-2016 08:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
Created ‎05-07-2016 08:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
Created ‎05-08-2016 07:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great !! Thanks a lot for the help. It works now.
