Package org.apache.pig.data

Examples of org.apache.pig.data.Tuple


        //col_uft8: (name: chararray,value: chararray),
        //col_uuid: (name: chararray,value: chararray),
        //columns: {(name: chararray,value: chararray)}}
        Iterator<Tuple> it = pig.openIterator("rows");
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), "foo");
            Tuple column = (Tuple) t.get(1);
            Assert.assertEquals(column.get(1), "ascii");
            column = (Tuple) t.get(2);
            Assert.assertEquals(column.get(1), false);
            column = (Tuple) t.get(3);
            Assert.assertEquals(column.get(1), new DataByteArray(Hex.hexToBytes("DEADBEEF")));
            column = (Tuple) t.get(4);
            Assert.assertEquals(column.get(1), 1296705900000L);
            column = (Tuple) t.get(5);
            Assert.assertEquals(column.get(1), "23.345");
            column = (Tuple) t.get(6);
            Assert.assertEquals(column.get(1), 2.7182818284590451d);
            column = (Tuple) t.get(7);
            Assert.assertEquals(column.get(1), 23.45f);
            column = (Tuple) t.get(8);
            Assert.assertEquals(column.get(1), "127.0.0.1");
            column = (Tuple) t.get(9);
            Assert.assertEquals(column.get(1), 23);
            column = (Tuple) t.get(10);
            Assert.assertEquals(column.get(1), 12345);
            column = (Tuple) t.get(11);
            Assert.assertEquals(column.get(1), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f77").array())));
            column = (Tuple) t.get(12);
            Assert.assertEquals(column.get(1), 12345678L);
            column = (Tuple) t.get(13);
            Assert.assertEquals(column.get(1), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f7f").array())));
            column = (Tuple) t.get(14);
            Assert.assertEquals(column.get(1), "hello");
            column = (Tuple) t.get(15);
            Assert.assertEquals(column.get(1), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440000").array())));
        }

        pig.registerQuery("cc_rows = LOAD 'cassandra://thriftKs/CC?" + defaultParameters + "' USING CassandraStorage();");

        //(chuck,{(kick,3)})
        it = pig.openIterator("cc_rows");
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), "chuck");          
            DataBag columns = (DataBag) t.get(1);
            Iterator<Tuple> iter = columns.iterator();
            if(iter.hasNext())
            {
                Tuple column = iter.next();
                Assert.assertEquals(column.get(0), "kick");
                Assert.assertEquals(column.get(1), 3L);
            }
         }
    }
View Full Code Here


        //col_timeuuid: bytearray,
        //col_uuid: chararray,
        //col_varchar: chararray,
        //col_varint: int}
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), 1);
            Assert.assertEquals(t.get(1), "ascii");
            Assert.assertEquals(t.get(2), 12345678L);
            Assert.assertEquals(t.get(3), new DataByteArray(Hex.hexToBytes("23446c6c6f")));
            Assert.assertEquals(t.get(4), false);
            Assert.assertEquals(t.get(5), "23.4567");
            Assert.assertEquals(t.get(6), 12345678.12345678d);
            Assert.assertEquals(t.get(7), 123.12f);
            Assert.assertEquals(t.get(8), "127.0.0.1");
            Assert.assertEquals(t.get(9), 123);
            Assert.assertEquals(t.get(10), "text");
            Assert.assertEquals(t.get(11), 1296705900000L);
            Assert.assertEquals(t.get(12), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f7f").array())));
            Assert.assertEquals(t.get(13), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440000").array())));
            Assert.assertEquals(t.get(14), "varchar");
            Assert.assertEquals(t.get(15), 123);
        }
       
        pig.registerQuery("cc_rows = LOAD 'cql://cql3ks/countertable?" + defaultParameters + "' USING CqlStorage();");
        it = pig.openIterator("cc_rows");
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), 1);
            Assert.assertEquals(t.get(1), 3L);
        }
    }
View Full Code Here

    throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
    {
        pig.registerQuery("set_rows = LOAD 'cql://cql3ks/settable?" + defaultParameters + "' USING CqlStorage();");
        Iterator<Tuple> it = pig.openIterator("set_rows");
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), 1);
            Tuple innerTuple = (Tuple) t.get(1);
            Assert.assertEquals(innerTuple.get(0), "ascii1");
            Assert.assertEquals(innerTuple.get(1), "ascii2");
            innerTuple = (Tuple) t.get(2);
            Assert.assertEquals(innerTuple.get(0), 12345678L);
            Assert.assertEquals(innerTuple.get(1), 12345679L);
            innerTuple = (Tuple) t.get(3);
            Assert.assertEquals(innerTuple.get(0), new DataByteArray(Hex.hexToBytes("68656c6c6e")));
            Assert.assertEquals(innerTuple.get(1), new DataByteArray(Hex.hexToBytes("68656c6c6f")));
            innerTuple = (Tuple) t.get(4);
            Assert.assertEquals(innerTuple.get(0), false);
            Assert.assertEquals(innerTuple.get(1), true);
            innerTuple = (Tuple) t.get(5);
            Assert.assertEquals(innerTuple.get(0), "23.4567");
            Assert.assertEquals(innerTuple.get(1), "23.4568");
            innerTuple = (Tuple) t.get(6);
            Assert.assertEquals(innerTuple.get(0), 12345678.12345678d);
            Assert.assertEquals(innerTuple.get(1), 12345678.12345679d);
            innerTuple = (Tuple) t.get(7);
            Assert.assertEquals(innerTuple.get(0), 123.12f);
            Assert.assertEquals(innerTuple.get(1), 123.13f);
            innerTuple = (Tuple) t.get(8);
            Assert.assertEquals(innerTuple.get(0), "127.0.0.1");
            Assert.assertEquals(innerTuple.get(1), "127.0.0.2");
            innerTuple = (Tuple) t.get(9);
            Assert.assertEquals(innerTuple.get(0), 123);
            Assert.assertEquals(innerTuple.get(1), 124);
            innerTuple = (Tuple) t.get(10);
            Assert.assertEquals(innerTuple.get(0), "text1");
            Assert.assertEquals(innerTuple.get(1), "text2");
            innerTuple = (Tuple) t.get(11);
            Assert.assertEquals(innerTuple.get(0), 1296705900000L);
            Assert.assertEquals(innerTuple.get(1), 1296792300000L);
            innerTuple = (Tuple) t.get(12);
            Assert.assertEquals(innerTuple.get(0), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f77").array())));
            Assert.assertEquals(innerTuple.get(1), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f7f").array())));
            innerTuple = (Tuple) t.get(13);
            Assert.assertEquals(innerTuple.get(0), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440000").array())));
            Assert.assertEquals(innerTuple.get(1), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440001").array())));
            innerTuple = (Tuple) t.get(14);
            Assert.assertEquals(innerTuple.get(0), "varchar1");
            Assert.assertEquals(innerTuple.get(1), "varchar2")
            innerTuple = (Tuple) t.get(15);
            Assert.assertEquals(innerTuple.get(0), 123);
            Assert.assertEquals(innerTuple.get(1), 124);
        }
    }
View Full Code Here

    throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
    {
        pig.registerQuery("list_rows = LOAD 'cql://cql3ks/listtable?" + defaultParameters + "' USING CqlStorage();");
        Iterator<Tuple> it = pig.openIterator("list_rows");
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), 1);
            Tuple innerTuple = (Tuple) t.get(1);
            Assert.assertEquals(innerTuple.get(1), "ascii1");
            Assert.assertEquals(innerTuple.get(0), "ascii2");
            innerTuple = (Tuple) t.get(2);
            Assert.assertEquals(innerTuple.get(1), 12345678L);
            Assert.assertEquals(innerTuple.get(0), 12345679L);
            innerTuple = (Tuple) t.get(3);
            Assert.assertEquals(innerTuple.get(1), new DataByteArray(Hex.hexToBytes("68656c6c6f")));
            Assert.assertEquals(innerTuple.get(0), new DataByteArray(Hex.hexToBytes("68656c6c6e")));
            innerTuple = (Tuple) t.get(4);
            Assert.assertEquals(innerTuple.get(1), false);
            Assert.assertEquals(innerTuple.get(0), true);
            innerTuple = (Tuple) t.get(5);
            Assert.assertEquals(innerTuple.get(1), "23.4567");
            Assert.assertEquals(innerTuple.get(0), "23.4568");
            innerTuple = (Tuple) t.get(6);
            Assert.assertEquals(innerTuple.get(1), 12345678.12345678d);
            Assert.assertEquals(innerTuple.get(0), 12345678.12345679d);
            innerTuple = (Tuple) t.get(7);
            Assert.assertEquals(innerTuple.get(1), 123.12f);
            Assert.assertEquals(innerTuple.get(0), 123.13f);
            innerTuple = (Tuple) t.get(8);
            Assert.assertEquals(innerTuple.get(1), "127.0.0.1");
            Assert.assertEquals(innerTuple.get(0), "127.0.0.2");
            innerTuple = (Tuple) t.get(9);
            Assert.assertEquals(innerTuple.get(1), 123);
            Assert.assertEquals(innerTuple.get(0), 124);
            innerTuple = (Tuple) t.get(10);
            Assert.assertEquals(innerTuple.get(1), "text1");
            Assert.assertEquals(innerTuple.get(0), "text2");
            innerTuple = (Tuple) t.get(11);
            Assert.assertEquals(innerTuple.get(1), 1296705900000L);
            Assert.assertEquals(innerTuple.get(0), 1296792300000L);
            innerTuple = (Tuple) t.get(12);
            Assert.assertEquals(innerTuple.get(1), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f7f").array())));
            Assert.assertEquals(innerTuple.get(0), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f77").array())));
            innerTuple = (Tuple) t.get(13);
            Assert.assertEquals(innerTuple.get(1), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440000").array())));
            Assert.assertEquals(innerTuple.get(0), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440001").array())));
            innerTuple = (Tuple) t.get(14);
            Assert.assertEquals(innerTuple.get(1), "varchar1");
            Assert.assertEquals(innerTuple.get(0), "varchar2")
            innerTuple = (Tuple) t.get(15);
            Assert.assertEquals(innerTuple.get(1), 123);
            Assert.assertEquals(innerTuple.get(0), 124);
        }
    }
View Full Code Here

    throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
    {
        pig.registerQuery("map_rows = LOAD 'cql://cql3ks/maptable?" + defaultParameters + "' USING CqlStorage();");
        Iterator<Tuple> it = pig.openIterator("map_rows");
        if (it.hasNext()) {
            Tuple t = it.next();
            Assert.assertEquals(t.get(0), 1);
            Tuple innerTuple = (Tuple) ((Tuple) t.get(1)).get(0);
            Assert.assertEquals(innerTuple.get(0), "ascii1");
            Assert.assertEquals(innerTuple.get(1), "ascii2");
            innerTuple = (Tuple) ((Tuple) t.get(2)).get(0);
            Assert.assertEquals(innerTuple.get(0), 12345678L);
            Assert.assertEquals(innerTuple.get(1), 12345679L);
            innerTuple = (Tuple) ((Tuple) t.get(3)).get(0);
            Assert.assertEquals(innerTuple.get(0), new DataByteArray(Hex.hexToBytes("68656c6c6f")));
            Assert.assertEquals(innerTuple.get(1), new DataByteArray(Hex.hexToBytes("68656c6c6e")));
            innerTuple = (Tuple) ((Tuple) t.get(4)).get(0);
            Assert.assertEquals(innerTuple.get(0), false);
            Assert.assertEquals(innerTuple.get(1), true);
            innerTuple = (Tuple) ((Tuple) t.get(5)).get(0);
            Assert.assertEquals(innerTuple.get(0), "23.4567");
            Assert.assertEquals(innerTuple.get(1), "23.4568");
            innerTuple = (Tuple) ((Tuple) t.get(6)).get(0);
            Assert.assertEquals(innerTuple.get(0), 12345678.12345678d);
            Assert.assertEquals(innerTuple.get(1), 12345678.12345679d);
            innerTuple = (Tuple) ((Tuple) t.get(7)).get(0);
            Assert.assertEquals(innerTuple.get(0), 123.12f);
            Assert.assertEquals(innerTuple.get(1), 123.13f);
            innerTuple = (Tuple) ((Tuple) t.get(8)).get(0);
            Assert.assertEquals(innerTuple.get(0), "127.0.0.1");
            Assert.assertEquals(innerTuple.get(1), "127.0.0.2");
            innerTuple = (Tuple) ((Tuple) t.get(9)).get(0);
            Assert.assertEquals(innerTuple.get(0), 123);
            Assert.assertEquals(innerTuple.get(1), 124);
            innerTuple = (Tuple) ((Tuple) t.get(10)).get(0);
            Assert.assertEquals(innerTuple.get(0), "text1");
            Assert.assertEquals(innerTuple.get(1), "text2");
            innerTuple = (Tuple) ((Tuple) t.get(11)).get(0);
            Assert.assertEquals(innerTuple.get(0), 1296705900000L);
            Assert.assertEquals(innerTuple.get(1), 1296792300000L);
            innerTuple = (Tuple) ((Tuple) t.get(12)).get(0);
            Assert.assertEquals(innerTuple.get(0), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f7f").array())));
            Assert.assertEquals(innerTuple.get(1), new DataByteArray((TimeUUIDType.instance.fromString("e23f450f-53a6-11e2-7f7f-7f7f7f7f7f77").array())));
            innerTuple = (Tuple) ((Tuple) t.get(13)).get(0);
            Assert.assertEquals(innerTuple.get(0), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440000").array())));
            Assert.assertEquals(innerTuple.get(1), new DataByteArray((UUIDType.instance.fromString("550e8400-e29b-41d4-a716-446655440001").array())));
            innerTuple = (Tuple) ((Tuple) t.get(14)).get(0);
            Assert.assertEquals(innerTuple.get(0), "varchar1");
            Assert.assertEquals(innerTuple.get(1), "varchar2")
            innerTuple = (Tuple) ((Tuple) t.get(15)).get(0);
            Assert.assertEquals(innerTuple.get(0), 123);
            Assert.assertEquals(innerTuple.get(1), 124);
        }
    }
View Full Code Here

    public void testNamedBag() {
        String expected = "{\"bag\":[[{\"first\":\"one\",\"second\":\"two\",\"third\":\"three\"}]," +
                                     "[{\"first\":\"one\",\"second\":\"two\",\"third\":\"three\"}]," +
                                     "[{\"first\":\"one\",\"second\":\"two\",\"third\":\"three\"}]]}";

        Tuple tuple = TupleFactory.getInstance().newTuple(Arrays.asList(new String[] { "one", "two", "three" }));
        assertThat(pigTypeToJson(createTuple(new DefaultDataBag(Arrays.asList(new Tuple[] { tuple, tuple, tuple })),
                createSchema("bag: {t:(first:chararray, second:chararray, third: chararray)}"))), is(expected));
    }
View Full Code Here

    public void testBagWithAnonTuple() {
        String expected = "{\"bag_0\":[[{\"val_0\":\"xxx\",\"val_1\":\"yyy\"}]," +
                                       "[{\"val_0\":\"xxx\",\"val_1\":\"yyy\"}]," +
                                       "[{\"val_0\":\"xxx\",\"val_1\":\"yyy\"}]]}";

        Tuple tuple = TupleFactory.getInstance().newTuple(Arrays.asList(new String[] { "xxx", "yyy" }));

        assertThat(pigTypeToJson(createTuple(new DefaultDataBag(Arrays.asList(new Tuple[] { tuple, tuple, tuple })),
                createSchema("{t:(chararray, chararray)}"))), is(expected));
    }
View Full Code Here

    @Test
    public void testNamedBag() {
        String expected = "{\"bag\":[[\"one\",\"two\",\"three\"],[\"one\",\"two\",\"three\"],[\"one\",\"two\",\"three\"]]}";

        Tuple tuple = TupleFactory.getInstance().newTuple(Arrays.asList(new String[] { "one", "two", "three" }));
        assertThat(pigTypeToJson(createTuple(new DefaultDataBag(Arrays.asList(new Tuple[] { tuple, tuple, tuple })),
                createSchema("bag: {t:(first:chararray, second:chararray, third: chararray)}"))), is(expected));
    }
View Full Code Here

    @Test
    public void testBagWithAnonTuple() {
        String expected = "{\"bag\":[[\"xxx\",\"yyy\"],[\"xxx\",\"yyy\"],[\"xxx\",\"yyy\"]]}";

        Tuple tuple = TupleFactory.getInstance().newTuple(Arrays.asList(new String[] { "xxx", "yyy" }));
        assertThat((pigTypeToJson(createTuple(new DefaultDataBag(Arrays.asList(new Tuple[] { tuple, tuple, tuple })),
                createSchema("bag: {t:(chararray, chararray)}")))), is(expected));
    }
View Full Code Here

    private String[] fields = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};

    @Test
    public void testAllConcat() throws Exception {
        RangeBasedStringConcat rbsc = new RangeBasedStringConcat("ALL", " ");
        Tuple input = new DefaultTuple();
        for (int i = 0; i < fields.length; i++) {
            input.append(fields[i]);
        }
        String result = rbsc.exec(input);
        assertEquals("a b c d e f g h i", result);
        Tuple innerTuple = new DefaultTuple();
        innerTuple.append("j");
        innerTuple.append("k");

        input.append(innerTuple);
        result = rbsc.exec(input);
        assertEquals("a b c d e f g h i j k", result);
        DataBag db = new DefaultDataBag();
        Tuple dbTuple = new DefaultTuple();
        dbTuple.append("l");
        dbTuple.append("m");
        db.add(dbTuple);
        innerTuple.append(db);
        result = rbsc.exec(input);
        assertEquals("a b c d e f g h i j k l m", result);
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.data.Tuple

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.