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

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


        }
    }

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

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


        }
    }

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

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

        }
    }

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

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

        assertNull(((Map<String, Object>)t.get(1)).get("2"));
    }

    @Test(expected = FrontendException.class)
    public void testMapNullKeyFailure() throws IOException {
        Data data = resetData(pigServer);
        data.set("foo", tuple(10, 11.0, "will_join"));

        pigServer.registerQuery("a = load 'foo' using mock.Storage() as (x:int, y:double, str:chararray);");
        pigServer.registerQuery("b = foreach a generate [null#'2'];");
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testWithFilter() 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)
                );

        pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (i:int);");
        pigServer.registerQuery("B = FILTER A BY i IN (1, 2, 3);");
        pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

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

     * @throws Exception
     */
    @Test
    public void testWithBincond() 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)
                );

        pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (i:int);");
        pigServer.registerQuery("B = FOREACH A GENERATE (i IN (1, 3, 5) ? 'ODD' : 'EVEN');");
        pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

        List<Tuple> out = data.get("bar");
        assertEquals(5, out.size());
        assertEquals(tuple("ODD"), out.get(0));
        assertEquals(tuple("EVEN"), out.get(1));
        assertEquals(tuple("ODD"), out.get(2));
        assertEquals(tuple("EVEN"), out.get(3));
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testWithSplit() 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)
                );

        pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (i:int);");
        pigServer.registerQuery("SPLIT A INTO B IF i IN (1, 3, 5), C OTHERWISE;");
        pigServer.registerQuery("STORE B INTO 'odd' USING mock.Storage();");
        pigServer.registerQuery("STORE C INTO 'even' USING mock.Storage();");

        List<Tuple> out = data.get("odd");
        assertEquals(3, out.size());
        assertEquals(tuple(1), out.get(0));
        assertEquals(tuple(3), out.get(1));
        assertEquals(tuple(5), out.get(2));

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

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

        data.set("foo",
                tuple("a","x",1),
                tuple("a","y",2),
                tuple("b","x",3),
                tuple("b","y",4),
                tuple("c","x",5),
                tuple("c","y",6)
                );

        pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (k1:chararray, k2:chararray, i:int);");
        pigServer.registerQuery("B = GROUP A BY (k1, k2);");
        pigServer.registerQuery("C = FILTER B BY group.k1 IN ('a', 'b') AND group.k2 IN ('x');");
        pigServer.registerQuery("STORE C INTO 'bar' USING mock.Storage();");

        List<Tuple> out = data.get("bar");
        assertEquals(2, out.size());
        assertEquals(tuple(tuple("a","x"),bag(tuple("a","x",1))), out.get(0));
        assertEquals(tuple(tuple("b","x"),bag(tuple("b","x",3))), out.get(1));
    }
View Full Code Here

     * @throws Exception
     */
    @Test(expected = FrontendException.class)
    public void testMissingRhsOperand() 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

  }

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

        data.set("foo",
            tuple("a", 1, "b"),
            tuple("b", 2, "c"),
            tuple("c", 3, "d")
            );

        pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);");
        pigServer.registerQuery("B = order A by f1,f2,f3 DESC;");
        pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");

        List<Tuple> out = data.get("bar");
        assertEquals(tuple("a", 1, "b"), out.get(0));
        assertEquals(tuple("b", 2, "c"), out.get(1));
        assertEquals(tuple("c", 3, "d"), out.get(2));
    }
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.