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

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


  }

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

      Tuple nestedTuple = tuple(bag(tuple("c"), tuple("d")));
      data.set("foo", "myBag:bag{t:(l:chararray)}",
        tuple(bag(tuple("a"), tuple("b"), nestedTuple, tuple("e"))));

    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",bag(tuple("c"), tuple("d")), "e"), out.get(0).get(0));

  }
View Full Code Here


  }

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

      data.set("foo", "myBag:bag{t:(l:chararray)}",
        tuple(bag()));

    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");
      // empty bag will generate empty tuple
      assertEquals(tuple(), out.get(0).get(0));

  }
View Full Code Here

  }

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

    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 BagToString(myBag) as myBag;");
      pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

      pigServer.registerQuery("C = FOREACH A GENERATE BagToString(myBag, '==') as myBag;");
      pigServer.registerQuery("STORE C INTO 'baz' USING mock.Storage();");

      List<Tuple> out = data.get("bar");
      assertEquals(schema("myBag:chararray"), data.getSchema("bar"));
      assertEquals(tuple("a_b_c"), out.get(0));

      out = data.get("baz");
      assertEquals(tuple("a==b==c"), out.get(0));
  }
View Full Code Here

  }

  @Test
  public void testPigScriptMultipleElmementsPerTupleForBagToStringUDF() 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 BagToString(myBag) as myBag;");
    pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

    pigServer.registerQuery("C = FOREACH A GENERATE BagToString(myBag, '^') as myBag;");
    pigServer.registerQuery("STORE C INTO 'baz' USING mock.Storage();");

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

      out = data.get("baz");
      assertEquals(tuple("a^b^c^d^e^f"), out.get(0));
  }
View Full Code Here

  }

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

      Tuple nestedTuple = tuple(bag(tuple("c"), tuple("d")));
      data.set("foo", "myBag:bag{t:(l:chararray)}",
        tuple(bag(tuple("a"), tuple("b"), nestedTuple, tuple("e"))));

    pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE BagToString(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"), out.get(0));

  }
View Full Code Here

  }

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

      data.set("foo", "myBag:bag{t:(l:chararray)}",
        tuple(bag()));

    pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage();");
    pigServer.registerQuery("B = FOREACH A GENERATE BagToString(myBag) as myBag;");
      pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

      List<Tuple> out = data.get("bar");
      // empty bag will generate empty string
      assertEquals(tuple(""), out.get(0));

  }
View Full Code Here

        pigServer = new PigServer(ExecType.LOCAL);
    }

    @Test
    public void testArithExpressions() throws IOException, ExecException {
        Data data = resetData(pigServer);
        data.set("foo", tuple(10, 11.0));

        pigServer.registerQuery("a = load 'foo' using mock.Storage() as (x:int, y:double);");
        pigServer.registerQuery("b = foreach a generate x + null, x * null, x / null, x - null, null % x, " +
                "y + null, y * null, y / null, y - null;");
        Iterator<Tuple> it = pigServer.openIterator("b");
View Full Code Here

        }
    }

    @Test
    public void testBinCond() throws IOException, ExecException {
        Data data = resetData(pigServer);
        data.set("foo", tuple(10, 11.0));

        pigServer.registerQuery("a = load 'foo' using mock.Storage() as (x:int, y:double);");
        pigServer.registerQuery("b = foreach a generate (2 > 1? null : 1), ( 2 < 1 ? null : 1), (2 > 1 ? 1 : null), ( 2 < 1 ? 1 : null);");
        Iterator<Tuple> it = pigServer.openIterator("b");
        Tuple t = it.next();
View Full Code Here

        }
    }

    @Test
    public void testForeachGenerate() throws ExecException, IOException {
        Data data = resetData(pigServer);
        data.set("foo", tuple(10, 11.0));

        pigServer.registerQuery("a = load 'foo' using mock.Storage() as (x:int, y:double);");
        pigServer.registerQuery("b = foreach a generate x, null, y, null;");
        Iterator<Tuple> it = pigServer.openIterator("b");
        Tuple t = it.next();
View Full Code Here

        }
    }

    @Test
    public void testOuterJoin() throws IOException, ExecException {
        Data data = resetData(pigServer);
        data.set("foo_left", tuple(10, "will_join"), tuple(11, "will_not_join"));
        data.set("foo_right", tuple(10, "will_join"), tuple(12, "will_not_join"));
        pigServer.registerQuery("a = load 'foo_left' using mock.Storage() as (x:int, y:chararray);");
        pigServer.registerQuery("b = load 'foo_right' using mock.Storage() as (u:int, v:chararray);");
        pigServer.registerQuery("c = cogroup a by x, b by u;");
        pigServer.registerQuery("d = foreach c generate flatten((SIZE(a) == 0 ? null: a)), flatten((SIZE(b) == 0 ? null : b));");
        Iterator<Tuple> it = pigServer.openIterator("d");
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.