You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Junior Tsire <ja...@yahoo.fr> on 2014/04/03 13:54:52 UTC
Embedded pig in java
Hi everybody,
I have been following a tutorial on how to embed pig in java because I am currently learning it. I used the sample code that I found on http://pig.apache.org/docs/r0.11.0/cont.html to teach myself and here is the code that I took and paste it on netbeans
package idlocal;
import java.io.IOException;
import org.apache.pig.PigServer;
public class Idlocal{
public static void main(String[] args) {
try {
PigServer pigServer = new PigServer("local");
runIdQuery(pigServer, "passwd");
}
catch(Exception e) {
}
}
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
pigServer.registerQuery("A = load '" + inputFile + "' using PigStorage(':');");
pigServer.registerQuery("B = foreach A generate $0 as id;");
pigServer.store("B", "id.out");
}
}
I managed to compile it on cygwin by doing javac -cp <path>pig.jar idlocal.java. It successfully created the class file. Now when I tried to run it (on cygwin) by doing java -cp <path>pig.jar idlocal, it gave me the this Error: Could not find or load main class Idlocal.
I really need some help because I don't know what is going on :(
Re: Embedded pig in java
Posted by Junior Tsire <ja...@yahoo.fr>.
thanks for your help :)
Le Vendredi 4 avril 2014 2h36, Jay Vyas <ja...@gmail.com> a écrit :
You can run the maven profile on bigpetstore as an example as well:
(see PigCSVCleaner.java):
https://github.com/jayunit100/bigpetstore/
And for a visual demo you can watch how we use maven to run local pig tasks
w/ PigServer in maven (somewhere in the middle of the video) here:
https://www.youtube.com/watch?v=OVB3nEKN94k
On Thu, Apr 3, 2014 at 7:23 AM, David LaBarbera <
davidlabarbera@localresponse.com> wrote:
> Try running with
> java -cp <path>pig.jar idlocal.Idlocal
>
> David
>
> On Apr 3, 2014, at 7:54 AM, Junior Tsire <ja...@yahoo.fr> wrote:
>
> > Hi everybody,
> >
> > I have been following a tutorial on how to embed pig in java because I
> am currently learning it. I used the sample code that I found on
> http://pig.apache.org/docs/r0.11.0/cont.html to teach myself and here is
> the code that I took and paste it on netbeans
> >
> > package idlocal;
> >
> > import java.io.IOException;
> >
> > import org.apache.pig.PigServer;
> >
> > public class Idlocal{
> > public static void main(String[] args) {
> >
> > try {
> > PigServer pigServer = new PigServer("local");
> > runIdQuery(pigServer, "passwd");
> > }
> > catch(Exception e) {
> > }
> > }
> >
> > public static void runIdQuery(PigServer pigServer, String inputFile)
> throws IOException {
> > pigServer.registerQuery("A = load '" + inputFile + "' using
> PigStorage(':');");
> > pigServer.registerQuery("B = foreach A generate $0 as id;");
> > pigServer.store("B", "id.out");
> > }
> > }
> >
> > I managed to compile it on cygwin by doing javac -cp <path>pig.jar
> idlocal.java. It successfully created the class file. Now when I tried to
> run it (on cygwin) by doing java -cp <path>pig.jar idlocal, it gave me the
> this Error: Could not find or load main class Idlocal.
> > I really need some help because I don't know what is going on :(
>
>
--
Jay Vyas
http://jayunit100.blogspot.com
Re: Embedded pig in java
Posted by Jay Vyas <ja...@gmail.com>.
You can run the maven profile on bigpetstore as an example as well:
(see PigCSVCleaner.java):
https://github.com/jayunit100/bigpetstore/
And for a visual demo you can watch how we use maven to run local pig tasks
w/ PigServer in maven (somewhere in the middle of the video) here:
https://www.youtube.com/watch?v=OVB3nEKN94k
On Thu, Apr 3, 2014 at 7:23 AM, David LaBarbera <
davidlabarbera@localresponse.com> wrote:
> Try running with
> java -cp <path>pig.jar idlocal.Idlocal
>
> David
>
> On Apr 3, 2014, at 7:54 AM, Junior Tsire <ja...@yahoo.fr> wrote:
>
> > Hi everybody,
> >
> > I have been following a tutorial on how to embed pig in java because I
> am currently learning it. I used the sample code that I found on
> http://pig.apache.org/docs/r0.11.0/cont.html to teach myself and here is
> the code that I took and paste it on netbeans
> >
> > package idlocal;
> >
> > import java.io.IOException;
> >
> > import org.apache.pig.PigServer;
> >
> > public class Idlocal{
> > public static void main(String[] args) {
> >
> > try {
> > PigServer pigServer = new PigServer("local");
> > runIdQuery(pigServer, "passwd");
> > }
> > catch(Exception e) {
> > }
> > }
> >
> > public static void runIdQuery(PigServer pigServer, String inputFile)
> throws IOException {
> > pigServer.registerQuery("A = load '" + inputFile + "' using
> PigStorage(':');");
> > pigServer.registerQuery("B = foreach A generate $0 as id;");
> > pigServer.store("B", "id.out");
> > }
> > }
> >
> > I managed to compile it on cygwin by doing javac -cp <path>pig.jar
> idlocal.java. It successfully created the class file. Now when I tried to
> run it (on cygwin) by doing java -cp <path>pig.jar idlocal, it gave me the
> this Error: Could not find or load main class Idlocal.
> > I really need some help because I don't know what is going on :(
>
>
--
Jay Vyas
http://jayunit100.blogspot.com
Re: Embedded pig in java
Posted by David LaBarbera <da...@localresponse.com>.
Try running with
java -cp <path>pig.jar idlocal.Idlocal
David
On Apr 3, 2014, at 7:54 AM, Junior Tsire <ja...@yahoo.fr> wrote:
> Hi everybody,
>
> I have been following a tutorial on how to embed pig in java because I am currently learning it. I used the sample code that I found on http://pig.apache.org/docs/r0.11.0/cont.html to teach myself and here is the code that I took and paste it on netbeans
>
> package idlocal;
>
> import java.io.IOException;
>
> import org.apache.pig.PigServer;
>
> public class Idlocal{
> public static void main(String[] args) {
>
> try {
> PigServer pigServer = new PigServer("local");
> runIdQuery(pigServer, "passwd");
> }
> catch(Exception e) {
> }
> }
>
> public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
> pigServer.registerQuery("A = load '" + inputFile + "' using PigStorage(':');");
> pigServer.registerQuery("B = foreach A generate $0 as id;");
> pigServer.store("B", "id.out");
> }
> }
>
> I managed to compile it on cygwin by doing javac -cp <path>pig.jar idlocal.java. It successfully created the class file. Now when I tried to run it (on cygwin) by doing java -cp <path>pig.jar idlocal, it gave me the this Error: Could not find or load main class Idlocal.
> I really need some help because I don't know what is going on :(