I managed to embed pig in java. I ran the program and it worked fine by creating a folder in my working directory that retrieve the info from the olympics.txt via the pig query.
import java.io.IOException;
import org.apache.pig.PigServer;
public class olympics {
public static void main(String[] args) {
try {
PigServer pigServer = new PigServer("local");
runIdQuery(pigServer, "olympics1");
}
catch(Exception e) {
} }
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
pigServer.registerQuery("A = LOAD 'olympics1.txt' as (Name:chararray, Age:int, Country:chararray);");
pigServer.registerQuery("B = GROUP A BY (Name,Age,Country);");
pigServer.registerQuery("C = FILTER A BY Age > 25;");
pigServer.registerQuery("D = FOREACH C GENERATE $0 AS Name, Age, Country;");
pigServer.store("D", "myfile.out");
} }
The issue that I have is by changing the pig query and running the program, it creates an empty file. Here is the pig query that I tried to do and I guess that something is probably wrong with it (I'm a new to apache pig). Can anyone tell me what is going on please?
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
pigServer.registerQuery("A = LOAD 'olympics1.txt' AS (Name:chararray, Year:int, Sport:chararray);");
pigServer.registerQuery("B = GROUP A BY (Name,Year,Sport);");
pigServer.registerQuery("C = FILTER A BY Sport == 'Swimming';");
pigServer.registerQuery("D = FOREACH C GENERATE $0 AS Name, Year, Sport;");
pigServer.store("D", "win.out");
} }
import java.io.IOException;
import org.apache.pig.PigServer;
public class olympics {
public static void main(String[] args) {
try {
PigServer pigServer = new PigServer("local");
runIdQuery(pigServer, "olympics1");
}
catch(Exception e) {
} }
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
pigServer.registerQuery("A = LOAD 'olympics1.txt' as (Name:chararray, Age:int, Country:chararray);");
pigServer.registerQuery("B = GROUP A BY (Name,Age,Country);");
pigServer.registerQuery("C = FILTER A BY Age > 25;");
pigServer.registerQuery("D = FOREACH C GENERATE $0 AS Name, Age, Country;");
pigServer.store("D", "myfile.out");
} }
The issue that I have is by changing the pig query and running the program, it creates an empty file. Here is the pig query that I tried to do and I guess that something is probably wrong with it (I'm a new to apache pig). Can anyone tell me what is going on please?
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
pigServer.registerQuery("A = LOAD 'olympics1.txt' AS (Name:chararray, Year:int, Sport:chararray);");
pigServer.registerQuery("B = GROUP A BY (Name,Year,Sport);");
pigServer.registerQuery("C = FILTER A BY Sport == 'Swimming';");
pigServer.registerQuery("D = FOREACH C GENERATE $0 AS Name, Year, Sport;");
pigServer.store("D", "win.out");
} }