Java Code Examples for org.apache.pig.PigServer#getExamples()

The following examples show how to use org.apache.pig.PigServer#getExamples() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilter3() throws Exception {

    PigServer pigserver = new PigServer(pigContext);

    String query = "A = load " + A
            + " using PigStorage() as (x : int, y : int);\n";
    pigserver.registerQuery(query);
    query = "B = filter A by x > 10;";
    pigserver.registerQuery(query);
    query = "C = FOREACH B GENERATE (x+1) as x1, (y+1) as y1;";
    pigserver.registerQuery(query);
    query = "D = FOREACH C GENERATE (x1+1) as x2, (y1+1) as y2;";
    pigserver.registerQuery(query);
    query = "E = DISTINCT D;";
    pigserver.registerQuery(query);
    Map<Operator, DataBag> derivedData = pigserver.getExamples("E");

    assertNotNull(derivedData);

}
 
Example 2
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterGroupCountStore() throws Exception {
    File out = File.createTempFile("testFilterGroupCountStoreOutput", "");
    out.deleteOnExit();
    out.delete();

    PigServer pigServer = new PigServer(pigContext);
    pigServer.setBatchOn();
    pigServer.registerQuery("A = load " + A.toString() + " as (x, y);");
    pigServer.registerQuery("B = filter A by x < 5;");
    pigServer.registerQuery("C = group B by x;");
    pigServer.registerQuery("D = foreach C generate group as x, COUNT(B) as the_count;");
    pigServer.registerQuery("store D into '" +  Util.encodeEscape(out.getAbsolutePath()) + "';");
    Map<Operator, DataBag> derivedData = pigServer.getExamples(null);

    assertNotNull(derivedData);
}
 
Example 3
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testLimit() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x, y);");
    pigServer.registerQuery("B = limit A 5;");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("B");

    assertNotNull(derivedData);
}
 
Example 4
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testDistinct() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x, y);");
    pigServer.registerQuery("B = DISTINCT A;");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("B");

    assertNotNull(derivedData);
}
 
Example 5
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterWithIsNull() throws ExecException, IOException {
    PigServer pigServer = new PigServer(pigContext);

    pigServer.registerQuery("A = load " + A
            + " using PigStorage() as (x : int, y : int);");
    pigServer.registerQuery("B = filter A by x is not null;");

    Map<Operator, DataBag> derivedData = pigServer.getExamples("B");

    assertNotNull(derivedData);
}
 
Example 6
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testForEachNestedBlock2() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x:int, y:int);");
    pigServer.registerQuery("B = group A by x;");
    pigServer.registerQuery("C = foreach B { FA = filter A by y == 6; DA = DISTINCT FA; generate group, COUNT(DA);};");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("C");

    assertNotNull(derivedData);

}
 
Example 7
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testForEachNestedBlock() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x:int, y:int);");
    pigServer.registerQuery("B = group A by x;");
    pigServer.registerQuery("C = foreach B { FA = filter A by y == 6; generate group, COUNT(FA);};");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("C");

    assertNotNull(derivedData);

}
 
Example 8
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterWithUDF() throws ExecException, IOException {
    PigServer pigServer = new PigServer(pigContext);

    pigServer.registerQuery("A = load " + A
            + " using PigStorage() as (x : int, y : int);");
    pigServer.registerQuery("B = group A by x;");
    pigServer.registerQuery("C = filter B by NOT IsEmpty(A.y);");

    Map<Operator, DataBag> derivedData = pigServer.getExamples("C");

    assertNotNull(derivedData);
}
 
Example 9
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testGroup3() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x:int, y:int);");
    pigServer.registerQuery("B = FILTER A by x  > 3;");
    pigServer.registerQuery("C = group B by y;");
    pigServer.registerQuery("D = foreach C generate group, COUNT(B);");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("D");

    assertNotNull(derivedData);

}
 
Example 10
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testGroup2() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x:int, y:int);");
    pigServer.registerQuery("B = group A by x;");
    pigServer.registerQuery("C = foreach B generate group, COUNT(A);");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("C");

    assertNotNull(derivedData);

}
 
Example 11
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoaderWithContext() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " using " + UDFContextTestLoaderWithSignature.class.getName() + "('a') as (x, y);");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("A");

    assertNotNull(derivedData);
}
 
Example 12
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testCogroup() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A + " as (x, y);");
    pigServer.registerQuery("B = load " + B + " as (x, y);");
    pigServer.registerQuery("C = cogroup A by x, B by x;");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("C");

    assertNotNull(derivedData);
}
 
Example 13
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testCross() throws Exception {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A = load " + A.toString() + " as (x, y);");
    pigServer.registerQuery("B = load " + B.toString() + " as (x, y);");
    pigServer.registerQuery("C = CROSS A, B;");
    Map<Operator, DataBag> derivedData = pigServer.getExamples("C");

    assertNotNull(derivedData);
}
 
Example 14
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testJoin2() throws IOException, ExecException {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A1 = load " + A + " as (x, y);");
    pigServer.registerQuery("B1 = load " + A + " as (x, y);");

    pigServer.registerQuery("E = join A1 by x, B1 by x;");

    Map<Operator, DataBag> derivedData = pigServer.getExamples("E");

    assertNotNull(derivedData);
}
 
Example 15
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testJoin() throws IOException, ExecException {
    PigServer pigServer = new PigServer(pigContext);
    pigServer.registerQuery("A1 = load " + A + " as (x, y);");
    pigServer.registerQuery("B1 = load " + B + " as (x, y);");

    pigServer.registerQuery("E = join A1 by x, B1 by x;");

    Map<Operator, DataBag> derivedData = pigServer.getExamples("E");

    assertNotNull(derivedData);
}
 
Example 16
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testForeachWithTypeCastCounter() throws ExecException, IOException {
    PigServer pigServer = new PigServer(pigContext);
    //cast error results in counter being incremented and was resulting
    // in a NPE exception in illustrate
    pigServer.registerQuery("A = load " + A
            + " using PigStorage() as (x : int, y : int);");
    pigServer.registerQuery("B = foreach A generate x, (int)'InvalidInt';");

    Map<Operator, DataBag> derivedData = pigServer.getExamples("B");

    assertNotNull(derivedData);
}
 
Example 17
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testForeachBinCondWithBooleanExp() throws ExecException, IOException {
    PigServer pigServer = new PigServer(pigContext);

    pigServer.registerQuery("A = load " + A
            + " using PigStorage() as (x : int, y : int);");
    pigServer.registerQuery("B = foreach A generate  (x + 1 > y ? 0 : 1);");

    Map<Operator, DataBag> derivedData = pigServer.getExamples("B");

    assertNotNull(derivedData);
}
 
Example 18
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilter2() throws Exception {

    PigServer pigserver = new PigServer(pigContext);

    String query = "A = load " + A
            + " using PigStorage() as (x : int, y : int);\n";
    pigserver.registerQuery(query);
    query = "B = filter A by x > 5 AND y < 6;";
    pigserver.registerQuery(query);
    Map<Operator, DataBag> derivedData = pigserver.getExamples("B");

    assertNotNull(derivedData);
}
 
Example 19
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilter() throws Exception {

    PigServer pigserver = new PigServer(pigContext);

    String query = "A = load " + A
            + " using PigStorage() as (x : int, y : int);\n";
    pigserver.registerQuery(query);
    query = "B = filter A by x > 10;";
    pigserver.registerQuery(query);
    Map<Operator, DataBag> derivedData = pigserver.getExamples("B");

    assertNotNull(derivedData);

}
 
Example 20
Source File: TestExampleGenerator.java    From spork with Apache License 2.0 3 votes vote down vote up
@Test
public void testLoad() throws Exception {

    PigServer pigserver = new PigServer(pigContext);

    String query = "A = load " + A
            + " using PigStorage() as (x : int, y : int);\n";
    pigserver.registerQuery(query);
    Map<Operator, DataBag> derivedData = pigserver.getExamples("A");

    assertNotNull(derivedData);

}