Package org.apache.pig.builtin.mock.Storage

Examples of org.apache.pig.builtin.mock.Storage.Data


     * @throws Exception
     */
    @Test(expected = FrontendException.class)
    public void testMissingWhenExpression() throws Exception {
        PigServer pigServer = new PigServer(ExecType.LOCAL);
        Data data = resetData(pigServer);

        data.set("foo",
                tuple(1),
                tuple(2),
                tuple(3),
                tuple(4),
                tuple(5)
View Full Code Here


     * @throws Exception
     */
    @Test(expected = FrontendException.class)
    public void testMissingThenExpression() throws Exception {
        PigServer pigServer = new PigServer(ExecType.LOCAL);
        Data data = resetData(pigServer);

        data.set("foo",
                tuple(1),
                tuple(2),
                tuple(3),
                tuple(4),
                tuple(5)
View Full Code Here

     * @throws Exception
     */
    @Test(expected = FrontendException.class)
    public void testMissingElseExpression() throws Exception {
        PigServer pigServer = new PigServer(ExecType.LOCAL);
        Data data = resetData(pigServer);

        data.set("foo",
                tuple(1),
                tuple(2),
                tuple(3),
                tuple(4),
                tuple(5)
View Full Code Here

    PigServer pigServer = new PigServer(ExecType.LOCAL);

    pigServer.registerCode(tmpScriptFile.getCanonicalPath(), "groovy", "groovyudfs");

    Data data = resetData(pigServer);
    data.set("foo0",
        tuple(1),
        tuple(2),
        tuple(3),
        tuple(4)
        );

    pigServer.registerQuery("A = LOAD 'foo0' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE groovyudfs.square($0);");
    pigServer.registerQuery("STORE B INTO 'bar0' USING mock.Storage();");

    List<Tuple> out = data.get("bar0");
    assertEquals(tuple(1L), out.get(0));
    assertEquals(tuple(4L), out.get(1));
    assertEquals(tuple(9L), out.get(2));
    assertEquals(tuple(16L), out.get(3));
  }
View Full Code Here

    PigServer pigServer = new PigServer(ExecType.LOCAL);

    pigServer.registerCode(tmpScriptFile.getCanonicalPath(), "groovy", "groovyudfs");

    Data data = resetData(pigServer);
    data.set("foo1",
        tuple(1)
        );

    pigServer.registerQuery("A = LOAD 'foo1' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE groovyudfs.mul($0);");
    pigServer.registerQuery("STORE B INTO 'bar1' USING mock.Storage();");

    List<Tuple> out = data.get("bar1");
    assertEquals(tuple(42L), out.get(0));
  }
View Full Code Here

    PigServer pigServer = new PigServer(ExecType.LOCAL);

    pigServer.registerCode(tmpScriptFile.getCanonicalPath(), "groovy", "groovyudfs");

    Data data = resetData(pigServer);
    data.set("foo2",
        tuple(1),
        tuple(2),
        tuple(3),
        tuple(4)
        );

    pigServer.registerQuery("A = LOAD 'foo2' USING mock.Storage();");
    pigServer.registerQuery("B = GROUP A ALL;");
    pigServer.registerQuery("C = FOREACH B GENERATE groovyudfs.sumalg(A);");
    pigServer.registerQuery("STORE C INTO 'bar2' USING mock.Storage();");

    List<Tuple> out = data.get("bar2");
    assertEquals(tuple(10L), out.get(0));
  }
View Full Code Here

    PigServer pigServer = new PigServer(ExecType.LOCAL);

    pigServer.registerCode(tmpScriptFile.getCanonicalPath(), "groovy", "groovyudfs");

    Data data = resetData(pigServer);
    data.set("foo3",
        tuple(1),
        tuple(2),
        tuple(3),
        tuple(4)
        );

    pigServer.registerQuery("A = LOAD 'foo3' USING mock.Storage();");
    pigServer.registerQuery("B = GROUP A ALL;");
    pigServer.registerQuery("C = FOREACH B GENERATE groovyudfs.sumacc(A) AS sum1,groovyudfs.sumacc(A) AS sum2;");
    pigServer.registerQuery("STORE C INTO 'bar3' USING mock.Storage();");

    List<Tuple> out = data.get("bar3");
    assertEquals(tuple(10L,10L), out.get(0));
  }
View Full Code Here

    PigServer pigServer = new PigServer(ExecType.LOCAL);

    pigServer.registerCode(tmpScriptFile.getCanonicalPath(), "groovy", "groovyudfs");

    Data data = resetData(pigServer);
    data.set("foo4",
        tuple(1,1L,1.0F,1.0D),
        tuple(2,2L,2.0F,2.0D)
        );

    pigServer.registerQuery("A = LOAD 'foo4' USING mock.Storage() AS (i: int, l: long, f: float, d: double);");
    pigServer.registerQuery("B = FOREACH A GENERATE groovyudfs.square(i),groovyudfs.square(l),groovyudfs.square(f),groovyudfs.square(d);");
    pigServer.registerQuery("STORE B INTO 'bar4' USING mock.Storage();");

    List<Tuple> out = data.get("bar4");
    // Multiplying two floats leads to a double in Groovy, this is reflected here.
    assertEquals(tuple(1,1L,1.0D,1.0D), out.get(0));
    assertEquals(tuple(4,4L,4.0D,4.0D), out.get(1));
  }
View Full Code Here

  }

  @Test
  public void testPigScriptForBagToTupleUDF() throws Exception {
    PigServer pigServer = new PigServer(ExecType.LOCAL);
    Data data = resetData(pigServer);

    // bag of chararray
    data.set("foo", "myBag:bag{t:(l:chararray)}",
        tuple(bag(tuple("a"), tuple("b"), tuple("c"))));
    pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE BagToTuple(myBag) as myBag;");
      pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

      assertEquals(schema("myBag:(l:chararray)"), data.getSchema("bar"));

      List<Tuple> out = data.get("bar");
      assertEquals(tuple("a", "b","c"), out.get(0).get(0));

      // bag of longs
      data = resetData(pigServer);
    data.set("foo", "myBag:bag{t:(l:long)}",
        tuple(bag(tuple(1), tuple(2), tuple(3))));
    pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE BagToTuple(myBag) as myBag;");
      pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

      out = data.get("bar");
      assertEquals(tuple(1, 2, 3), out.get(0).get(0));
  }
View Full Code Here

  }

  @Test
  public void testPigScriptMultipleElmementsPerTupleForBagTupleUDF() throws Exception {
    PigServer pigServer = new PigServer(ExecType.LOCAL);
    Data data = resetData(pigServer);

    data.set("foo", "myBag:bag{t:(l:chararray)}",
        tuple(bag(tuple("a", "b"), tuple("c", "d"), tuple("e", "f"))));
    pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE BagToTuple(myBag) as myBag;");
    pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

      List<Tuple> out = data.get("bar");
      assertEquals(tuple("a", "b","c", "d", "e", "f"), out.get(0).get(0));
  }
View Full Code Here

TOP

Related Classes of org.apache.pig.builtin.mock.Storage.Data

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.