Grokbase Groups Pig user August 2010
FAQ
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

Search Discussions

  • Bill Graham at Aug 9, 2010 at 9:46 pm
    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
    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


Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriespig, hadoop
postedAug 9, '10 at 9:27p
activeAug 9, '10 at 9:46p
posts2
users2
websitepig.apache.org

People

Translate

site design / logo © 2022 Grokbase