Search in sources :

Example 6 with TestPerson

use of com.twitter.elephantbird.thrift.test.TestPerson in project parquet-mr by apache.

the class TestParquetWriteProtocol method testStructInMap.

@Test
public void testStructInMap() throws Exception {
    String[] expectations = { "startMessage()", "startField(name, 0)", "addBinary(map_name)", "endField(name, 0)", "startField(names, 1)", "startGroup()", "startField(map, 0)", "startGroup()", "startField(key, 0)", "addBinary(foo)", "endField(key, 0)", "startField(value, 1)", "startGroup()", "startField(name, 0)", "startGroup()", "startField(first_name, 0)", "addBinary(john)", "endField(first_name, 0)", "startField(last_name, 1)", "addBinary(johnson)", "endField(last_name, 1)", "endGroup()", "endField(name, 0)", "startField(phones, 1)", "startGroup()", "endGroup()", "endField(phones, 1)", "endGroup()", "endField(value, 1)", "endGroup()", "endField(map, 0)", "endGroup()", "endField(names, 1)", "startField(name_to_id, 2)", "startGroup()", "startField(map, 0)", "startGroup()", "startField(key, 0)", "addBinary(bar)", "endField(key, 0)", "startField(value, 1)", "addInt(10)", "endField(value, 1)", "endGroup()", "endField(map, 0)", "endGroup()", "endField(name_to_id, 2)", "endMessage()" };
    final Map<String, TestPerson> map = new HashMap<String, TestPerson>();
    map.put("foo", new TestPerson(new TestName("john", "johnson"), new HashMap<TestPhoneType, String>()));
    final Map<String, Integer> stringToIntMap = Collections.singletonMap("bar", 10);
    TestStructInMap testMap = new TestStructInMap("map_name", map, stringToIntMap);
    validatePig(expectations, testMap);
    validateThrift(expectations, testMap);
}
Also used : TestName(com.twitter.elephantbird.thrift.test.TestName) HashMap(java.util.HashMap) TestPerson(com.twitter.elephantbird.thrift.test.TestPerson) TestStructInMap(com.twitter.elephantbird.thrift.test.TestStructInMap) Test(org.junit.Test)

Example 7 with TestPerson

use of com.twitter.elephantbird.thrift.test.TestPerson in project elephant-bird by twitter.

the class TestErrorsInInput method TestMultiFormatLoaderWithEmptyRecords.

@Test
public void TestMultiFormatLoaderWithEmptyRecords() throws Exception {
    Assume.assumeTrue(pigServer != null);
    // initalize
    String testDir = System.getProperty("test.build.data") + "/TestEmptyRecords";
    final File inDir = new File(testDir, "in");
    inDir.mkdirs();
    // block writer
    RawBlockWriter blk_writer = new RawBlockWriter(createLzoOut(new File(inDir, "1-block.lzo"), conf));
    // b64 writer
    OutputStream b64_writer = createLzoOut(new File(inDir, "2-b64.lzo"), conf);
    Base64 base64 = Codecs.createStandardBase64();
    for (TestPerson rec : records) {
        // write a regular record and an empty record
        byte[] bytes = tConverter.toBytes(rec);
        blk_writer.write(bytes);
        blk_writer.write(new byte[0]);
        b64_writer.write(base64.encode(bytes));
        b64_writer.write(Protobufs.NEWLINE_UTF8_BYTE);
        // empty line.
        b64_writer.write(Protobufs.NEWLINE_UTF8_BYTE);
    }
    blk_writer.close();
    b64_writer.close();
    // end of initialization.
    pigServer.registerQuery(String.format("A = load '%s' using %s('%s');\n", inDir.toURI().toString(), MultiFormatLoader.class.getName(), TestPerson.class.getName()));
    Iterator<Tuple> rows = pigServer.openIterator("A");
    // verify:
    for (int i = 0; i < 2; i++) {
        for (TestPerson person : records) {
            String expected = personToString(person);
            Assert.assertEquals(expected, rows.next().toString());
        }
    }
    FileUtil.fullyDelete(new File(testDir));
}
Also used : Base64(org.apache.commons.codec.binary.Base64) RawBlockWriter(com.twitter.elephantbird.mapreduce.io.RawBlockWriter) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TestPerson(com.twitter.elephantbird.thrift.test.TestPerson) File(java.io.File) Tuple(org.apache.pig.data.Tuple) Test(org.junit.Test)

Example 8 with TestPerson

use of com.twitter.elephantbird.thrift.test.TestPerson in project elephant-bird by twitter.

the class TestThriftMultiFormatLoader method testMultiFormatLoader.

@Test
public void testMultiFormatLoader() throws Exception {
    // setUp might not have run because of missing lzo native libraries
    Assume.assumeTrue(pigServer != null);
    pigServer.registerQuery(String.format("A = load '%s' using %s('%s');\n", inputDir.toURI().toString(), MultiFormatLoader.class.getName(), TestPerson.class.getName()));
    Iterator<Tuple> rows = pigServer.openIterator("A");
    // verify:
    for (int i = 0; i < 2; i++) {
        for (TestPerson person : records) {
            String expected = personToString(person);
            Assert.assertEquals(expected, rows.next().toString());
        }
    }
    FileUtil.fullyDelete(inputDir);
}
Also used : TestPerson(com.twitter.elephantbird.thrift.test.TestPerson) Tuple(org.apache.pig.data.Tuple) Test(org.junit.Test)

Aggregations

TestPerson (com.twitter.elephantbird.thrift.test.TestPerson)8 Test (org.junit.Test)6 TestName (com.twitter.elephantbird.thrift.test.TestName)4 TestStructInMap (com.twitter.elephantbird.thrift.test.TestStructInMap)3 HashMap (java.util.HashMap)3 RawBlockWriter (com.twitter.elephantbird.mapreduce.io.RawBlockWriter)2 File (java.io.File)2 Configuration (org.apache.hadoop.conf.Configuration)2 Tuple (org.apache.pig.data.Tuple)2 ThriftBlockWriter (com.twitter.elephantbird.mapreduce.io.ThriftBlockWriter)1 ThriftWritable (com.twitter.elephantbird.mapreduce.io.ThriftWritable)1 Name (com.twitter.elephantbird.thrift.test.Name)1 Person (com.twitter.elephantbird.thrift.test.Person)1 PhoneNumber (com.twitter.elephantbird.thrift.test.PhoneNumber)1 TestUnion (com.twitter.elephantbird.thrift.test.TestUnion)1 DataOutputStream (java.io.DataOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Random (java.util.Random)1