Search in sources :

Example 6 with OrcKey

use of org.apache.orc.mapred.OrcKey in project incubator-gobblin by apache.

the class OrcKeyComparatorTest method testComplexRecordMap.

@Test
public void testComplexRecordMap() throws Exception {
    OrcKeyComparator comparator = new OrcKeyComparator();
    Configuration conf = new Configuration();
    TypeDescription mapFieldSchema = TypeDescription.createMap(TypeDescription.createString(), TypeDescription.createString());
    TypeDescription schema = TypeDescription.createStruct().addField("a", TypeDescription.createInt()).addField("b", mapFieldSchema);
    conf.set(OrcConf.MAPRED_SHUFFLE_KEY_SCHEMA.getAttribute(), schema.toString());
    Assert.assertEquals(conf.get(OrcConf.MAPRED_SHUFFLE_KEY_SCHEMA.getAttribute()), schema.toString());
    comparator.setConf(conf);
    // base record
    OrcStruct record0 = (OrcStruct) OrcStruct.createValue(schema);
    record0.setFieldValue("a", new IntWritable(1));
    OrcMap orcMap = createSimpleOrcMap(new Text("key"), new Text("value"), mapFieldSchema);
    record0.setFieldValue("b", orcMap);
    // key value both differ
    OrcStruct record1 = (OrcStruct) OrcStruct.createValue(schema);
    record1.setFieldValue("a", new IntWritable(1));
    OrcMap orcMap1 = createSimpleOrcMap(new Text("key_key"), new Text("value_value"), mapFieldSchema);
    record1.setFieldValue("b", orcMap1);
    // Key same, value differ
    OrcStruct record2 = (OrcStruct) OrcStruct.createValue(schema);
    record2.setFieldValue("a", new IntWritable(1));
    OrcMap orcMap2 = createSimpleOrcMap(new Text("key"), new Text("value_value"), mapFieldSchema);
    record2.setFieldValue("b", orcMap2);
    // Same as base
    OrcStruct record3 = (OrcStruct) OrcStruct.createValue(schema);
    record3.setFieldValue("a", new IntWritable(1));
    OrcMap orcMap3 = createSimpleOrcMap(new Text("key"), new Text("value"), mapFieldSchema);
    record3.setFieldValue("b", orcMap3);
    // Differ in other field.
    OrcStruct record4 = (OrcStruct) OrcStruct.createValue(schema);
    record4.setFieldValue("a", new IntWritable(2));
    record4.setFieldValue("b", orcMap);
    // Record with map containing multiple entries but inserted in different order.
    OrcStruct record6 = (OrcStruct) OrcStruct.createValue(schema);
    record6.setFieldValue("a", new IntWritable(1));
    OrcMap orcMap6 = createSimpleOrcMap(new Text("key"), new Text("value"), mapFieldSchema);
    orcMap6.put(new Text("keyLater"), new Text("valueLater"));
    record6.setFieldValue("b", orcMap6);
    OrcStruct record7 = (OrcStruct) OrcStruct.createValue(schema);
    record7.setFieldValue("a", new IntWritable(1));
    OrcMap orcMap7 = createSimpleOrcMap(new Text("keyLater"), new Text("valueLater"), mapFieldSchema);
    orcMap7.put(new Text("key"), new Text("value"));
    record7.setFieldValue("b", orcMap7);
    OrcKey orcKey0 = new OrcKey();
    orcKey0.key = record0;
    OrcKey orcKey1 = new OrcKey();
    orcKey1.key = record1;
    OrcKey orcKey2 = new OrcKey();
    orcKey2.key = record2;
    OrcKey orcKey3 = new OrcKey();
    orcKey3.key = record3;
    OrcKey orcKey4 = new OrcKey();
    orcKey4.key = record4;
    OrcKey orcKey6 = new OrcKey();
    orcKey6.key = record6;
    OrcKey orcKey7 = new OrcKey();
    orcKey7.key = record7;
    Assert.assertTrue(comparator.compare(orcKey0, orcKey1) < 0);
    Assert.assertTrue(comparator.compare(orcKey1, orcKey2) > 0);
    Assert.assertTrue(comparator.compare(orcKey2, orcKey3) > 0);
    Assert.assertTrue(comparator.compare(orcKey0, orcKey3) == 0);
    Assert.assertTrue(comparator.compare(orcKey0, orcKey4) < 0);
    Assert.assertTrue(comparator.compare(orcKey6, orcKey7) == 0);
}
Also used : OrcStruct(org.apache.orc.mapred.OrcStruct) Configuration(org.apache.hadoop.conf.Configuration) TypeDescription(org.apache.orc.TypeDescription) Text(org.apache.hadoop.io.Text) OrcKey(org.apache.orc.mapred.OrcKey) IntWritable(org.apache.hadoop.io.IntWritable) OrcMap(org.apache.orc.mapred.OrcMap) Test(org.testng.annotations.Test)

Aggregations

OrcKey (org.apache.orc.mapred.OrcKey)6 OrcStruct (org.apache.orc.mapred.OrcStruct)5 Configuration (org.apache.hadoop.conf.Configuration)4 TypeDescription (org.apache.orc.TypeDescription)4 Test (org.testng.annotations.Test)4 IntWritable (org.apache.hadoop.io.IntWritable)3 OrcList (org.apache.orc.mapred.OrcList)2 DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)1 Text (org.apache.hadoop.io.Text)1 JobConf (org.apache.hadoop.mapred.JobConf)1 OrcMap (org.apache.orc.mapred.OrcMap)1 OrcUnion (org.apache.orc.mapred.OrcUnion)1 OrcValue (org.apache.orc.mapred.OrcValue)1