You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Bill Graham <bi...@gmail.com> on 2010/08/09 23:46:09 UTC

Re: how to convert java program to pig UDF, and important statements in the pig script

http://hadoop.apache.org/pig/docs/r0.7.0/udf.html#How+to+Write+a+Simple+Eval+Function

Replace 'return str.toUpperCase()' in the example with 'return str + "*"'
and you have a star UDF.

On Mon, Aug 9, 2010 at 1:40 PM, Ifeanyichukwu Osuji
<os...@potsdam.edu>wrote:

> i have a simple java file that adds a star to a word and prints the
> result.(this is the simplest java program i could think of)
>
> import java.util.*;
>
> public class Star {
>
>    public static void main (String[] args) {
>        if (args.length == 1) {
>            addStar(args[0]);
>        }else
>            System.exit(1);
>
>    }
>    public static void addStar (String word) {
>        String str = "";
>        str += word + "*";
>        System.out.println(str);
>    }
>
> }
>
>    How can i use pig to execute this java program? The answer i can come
> up with on my own is converting method addStar to a UDF but i dont
> know how to do it(please help). The documentation wasn't that helpful.
>
>    Re-wording the question: Lets say i have a file words.log that
> contains a column of words (all of which i want to add star to). I
> would like to use pig to pass each word in the log through the java
> program above. How can i do this?
>
>    If i were to write a pig script, would it be like this?
> myscript.pig
>
> a = load 'words.log' as (word:chararray);
> b = foreach a generate star(word);... (I dont know what to do, please help)
> dump b;
>
> ubuntu-user
> ife
>
>
>
>