Search in sources :

Example 1 with TestMap

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

the class TestParquetReadProtocol method testMap.

@Test
public void testMap() throws Exception {
    final Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "bar");
    TestMap testMap = new TestMap("map_name", map);
    validate(testMap);
}
Also used : HashMap(java.util.HashMap) TestMap(com.twitter.elephantbird.thrift.test.TestMap) Test(org.junit.Test)

Example 2 with TestMap

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

the class TestParquetWriteProtocol method testMap.

@Test
public void testMap() 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)", "addBinary(bar)", "endField(value, 1)", "endGroup()", "startGroup()", "startField(key, 0)", "addBinary(foo2)", "endField(key, 0)", "startField(value, 1)", "addBinary(bar2)", "endField(value, 1)", "endGroup()", "endField(map, 0)", "endGroup()", "endField(names, 1)", "endMessage()" };
    String[] expectationsAlt = { "startMessage()", "startField(name, 0)", "addBinary(map_name)", "endField(name, 0)", "startField(names, 1)", "startGroup()", "startField(map, 0)", "startGroup()", "startField(key, 0)", "addBinary(foo2)", "endField(key, 0)", "startField(value, 1)", "addBinary(bar2)", "endField(value, 1)", "endGroup()", "startGroup()", "startField(key, 0)", "addBinary(foo)", "endField(key, 0)", "startField(value, 1)", "addBinary(bar)", "endField(value, 1)", "endGroup()", "endField(map, 0)", "endGroup()", "endField(names, 1)", "endMessage()" };
    final Map<String, String> map = new TreeMap<String, String>();
    map.put("foo", "bar");
    map.put("foo2", "bar2");
    TestMap testMap = new TestMap("map_name", map);
    try {
        validatePig(expectations, testMap);
    } catch (ComparisonFailure e) {
        // This can happen despite using a stable TreeMap, since ThriftToPig#toPigMap
        // in com.twitter.elephantbird.pig.util creates a HashMap.
        // So we test with the map elements in reverse order
        validatePig(expectationsAlt, testMap);
    }
    validateThrift(expectations, testMap);
}
Also used : TestMap(com.twitter.elephantbird.thrift.test.TestMap) ComparisonFailure(org.junit.ComparisonFailure) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 3 with TestMap

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

the class TestThriftToPigCompatibility method testMap.

public void testMap() throws Exception {
    Map<String, String> map = new TreeMap<String, String>();
    map.put("foo", "bar");
    map.put("foo2", "bar2");
    TestMap testMap = new TestMap("map_name", map);
    validateSameTupleAsEB(testMap);
}
Also used : TestMap(com.twitter.elephantbird.thrift.test.TestMap) TreeMap(java.util.TreeMap)

Example 4 with TestMap

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

the class TestThriftToPig method testMapValueFieldAlias.

/**
 * Tests that thrift map field value has no field schema alias.
 * @throws FrontendException
 */
@Test
public void testMapValueFieldAlias() throws FrontendException {
    ThriftToPig<TestMap> thriftToPig = new ThriftToPig<TestMap>(TestMap.class);
    Schema schema = thriftToPig.toSchema();
    Assert.assertEquals("{name: chararray,names: map[chararray]}", schema.toString());
    Assert.assertNull(schema.getField(1).schema.getField(0).alias);
    schema = ThriftToPig.toSchema(TestMap.class);
    Assert.assertEquals("{name: chararray,names: map[chararray]}", schema.toString());
    Assert.assertNull(schema.getField(1).schema.getField(0).alias);
}
Also used : TestMap(com.twitter.elephantbird.thrift.test.TestMap) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) ResourceSchema(org.apache.pig.ResourceSchema) ThriftToPig(com.twitter.elephantbird.pig.util.ThriftToPig) Test(org.junit.Test)

Aggregations

TestMap (com.twitter.elephantbird.thrift.test.TestMap)4 Test (org.junit.Test)3 TreeMap (java.util.TreeMap)2 ThriftToPig (com.twitter.elephantbird.pig.util.ThriftToPig)1 HashMap (java.util.HashMap)1 ResourceSchema (org.apache.pig.ResourceSchema)1 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)1 ComparisonFailure (org.junit.ComparisonFailure)1