Search in sources :

Example 1 with FullMapEqualComparer

use of org.apache.hadoop.hive.serde2.objectinspector.FullMapEqualComparer in project cdap by caskdata.

the class FullMapEqualComparerTest method testTransitivity.

@Test
public void testTransitivity() {
    IntegerIntegerMapHolder o1 = new IntegerIntegerMapHolder();
    IntegerIntegerMapHolder o2 = new IntegerIntegerMapHolder();
    IntegerIntegerMapHolder o3 = new IntegerIntegerMapHolder();
    ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(IntegerIntegerMapHolder.class);
    o1.mMap.put(1, 1);
    o1.mMap.put(99, 99);
    o2.mMap.put(0, 99);
    o2.mMap.put(99, 99);
    o3.mMap.put(0, 1);
    o3.mMap.put(1, 99);
    {
        // non-transitive
        int rc12 = ObjectInspectorUtils.compare(o1, oi, o2, oi, new SimpleMapEqualComparer());
        Assert.assertTrue(rc12 > 0);
        int rc23 = ObjectInspectorUtils.compare(o2, oi, o3, oi, new SimpleMapEqualComparer());
        Assert.assertTrue(rc23 > 0);
        int rc13 = ObjectInspectorUtils.compare(o1, oi, o3, oi, new SimpleMapEqualComparer());
        Assert.assertTrue(rc13 < 0);
    }
    {
        // non-transitive
        int rc12 = ObjectInspectorUtils.compare(o1, oi, o2, oi, new CrossMapEqualComparer());
        Assert.assertTrue(rc12 > 0);
        int rc23 = ObjectInspectorUtils.compare(o2, oi, o3, oi, new CrossMapEqualComparer());
        Assert.assertTrue(rc23 > 0);
        int rc13 = ObjectInspectorUtils.compare(o1, oi, o3, oi, new CrossMapEqualComparer());
        Assert.assertTrue(rc13 < 0);
    }
    {
        // transitive
        int rc12 = ObjectInspectorUtils.compare(o1, oi, o2, oi, new FullMapEqualComparer());
        Assert.assertTrue(rc12 > 0);
        int rc23 = ObjectInspectorUtils.compare(o2, oi, o3, oi, new FullMapEqualComparer());
        Assert.assertTrue(rc23 > 0);
        int rc13 = ObjectInspectorUtils.compare(o1, oi, o3, oi, new FullMapEqualComparer());
        Assert.assertTrue(rc13 > 0);
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) SimpleMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.SimpleMapEqualComparer) FullMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.FullMapEqualComparer) CrossMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.CrossMapEqualComparer) Test(org.junit.Test)

Example 2 with FullMapEqualComparer

use of org.apache.hadoop.hive.serde2.objectinspector.FullMapEqualComparer in project cdap by caskdata.

the class FullMapEqualComparerTest method testAntiSymmetry.

@Test
public void testAntiSymmetry() {
    IntegerIntegerMapHolder o1 = new IntegerIntegerMapHolder();
    IntegerIntegerMapHolder o2 = new IntegerIntegerMapHolder();
    ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(IntegerIntegerMapHolder.class);
    o1.mMap.put(1, 1);
    o2.mMap.put(0, 99);
    {
        // not anti-symmetric
        int rc12 = ObjectInspectorUtils.compare(o1, oi, o2, oi, new SimpleMapEqualComparer());
        Assert.assertTrue(rc12 > 0);
        int rc21 = ObjectInspectorUtils.compare(o2, oi, o1, oi, new SimpleMapEqualComparer());
        Assert.assertTrue(rc21 > 0);
    }
    {
        // not anti-symmetric
        int rc12 = ObjectInspectorUtils.compare(o1, oi, o2, oi, new CrossMapEqualComparer());
        Assert.assertTrue(rc12 > 0);
        int rc21 = ObjectInspectorUtils.compare(o2, oi, o1, oi, new CrossMapEqualComparer());
        Assert.assertTrue(rc21 > 0);
    }
    {
        // anti-symmetric
        int rc12 = ObjectInspectorUtils.compare(o1, oi, o2, oi, new FullMapEqualComparer());
        Assert.assertTrue(rc12 > 0);
        int rc21 = ObjectInspectorUtils.compare(o2, oi, o1, oi, new FullMapEqualComparer());
        Assert.assertTrue(rc21 < 0);
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) SimpleMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.SimpleMapEqualComparer) FullMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.FullMapEqualComparer) CrossMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.CrossMapEqualComparer) Test(org.junit.Test)

Aggregations

CrossMapEqualComparer (org.apache.hadoop.hive.serde2.objectinspector.CrossMapEqualComparer)2 FullMapEqualComparer (org.apache.hadoop.hive.serde2.objectinspector.FullMapEqualComparer)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 SimpleMapEqualComparer (org.apache.hadoop.hive.serde2.objectinspector.SimpleMapEqualComparer)2 Test (org.junit.Test)2