Search in sources :

Example 71 with ObjectInspectorFactory.getReflectionObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getReflectionObjectInspector 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 72 with ObjectInspectorFactory.getReflectionObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getReflectionObjectInspector 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)

Example 73 with ObjectInspectorFactory.getReflectionObjectInspector

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

the class SimpleMapEqualComparerTest method testSameType.

@Test
public void testSameType() {
    // empty maps
    IntegerStringMapHolder o1 = new IntegerStringMapHolder();
    IntegerStringMapHolder o2 = new IntegerStringMapHolder();
    ObjectInspector oi1 = ObjectInspectorFactory.getReflectionObjectInspector(IntegerStringMapHolder.class);
    int rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi1, new SimpleMapEqualComparer());
    Assert.assertEquals(0, rc);
    // equal maps
    o1.mMap.put(42, "The answer to Life, Universe And Everything");
    o2.mMap.put(42, "The answer to Life, Universe And Everything");
    o1.mMap.put(1729, "A taxi cab number");
    o2.mMap.put(1729, "A taxi cab number");
    rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi1, new SimpleMapEqualComparer());
    Assert.assertEquals(0, rc);
    // unequal maps
    o2.mMap.put(1729, "Hardy-Ramanujan Number");
    rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi1, new SimpleMapEqualComparer());
    Assert.assertFalse(0 == rc);
}
Also used : StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) SimpleMapEqualComparer(org.apache.hadoop.hive.serde2.objectinspector.SimpleMapEqualComparer) Test(org.junit.Test)

Example 74 with ObjectInspectorFactory.getReflectionObjectInspector

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

the class StandardObjectInspectorsTest method testStandardSetObjectInspector.

@Test
public void testStandardSetObjectInspector() throws Throwable {
    try {
        ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(new TypeToken<Set<Integer>>() {
        }.getType());
        Assert.assertTrue(oi instanceof StandardListObjectInspector);
        StandardListObjectInspector loi = (StandardListObjectInspector) oi;
        // metadata
        Assert.assertEquals(Category.LIST, loi.getCategory());
        Assert.assertEquals(PrimitiveObjectInspectorFactory.javaIntObjectInspector, loi.getListElementObjectInspector());
        // Test set inspection
        HashSet<Integer> set = new HashSet<>();
        set.add(0);
        set.add(1);
        set.add(2);
        set.add(3);
        Assert.assertEquals(4, loi.getList(set).size());
        Assert.assertEquals(4, loi.getListLength(set));
        Assert.assertEquals(0, loi.getListElement(set, 0));
        Assert.assertEquals(3, loi.getListElement(set, 3));
        Assert.assertNull(loi.getListElement(set, -1));
        Assert.assertNull(loi.getListElement(set, 4));
        // Settable
        List<String> list = (List<String>) loi.set(set, 0, 5);
        Assert.assertFalse(set.contains(5));
        Assert.assertTrue(list.contains(5));
        list = (List<String>) loi.resize(set, 5);
        Assert.assertEquals(4, set.size());
        Assert.assertEquals(5, list.size());
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with ObjectInspectorFactory.getReflectionObjectInspector

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

the class StandardObjectInspectorsTest method testStandardQueueObjectInspector.

@Test
public void testStandardQueueObjectInspector() throws Throwable {
    try {
        ObjectInspector oi = ObjectInspectorFactory.getReflectionObjectInspector(new TypeToken<Queue<Integer>>() {
        }.getType());
        Assert.assertTrue(oi instanceof StandardListObjectInspector);
        StandardListObjectInspector loi = (StandardListObjectInspector) oi;
        // metadata
        Assert.assertEquals(Category.LIST, loi.getCategory());
        Assert.assertEquals(PrimitiveObjectInspectorFactory.javaIntObjectInspector, loi.getListElementObjectInspector());
        // Test queue inspection
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(0);
        queue.add(1);
        queue.add(2);
        queue.add(3);
        Assert.assertEquals(4, loi.getList(queue).size());
        Assert.assertEquals(4, loi.getListLength(queue));
        Assert.assertEquals(0, loi.getListElement(queue, 0));
        Assert.assertEquals(3, loi.getListElement(queue, 3));
        Assert.assertNull(loi.getListElement(queue, -1));
        Assert.assertNull(loi.getListElement(queue, 4));
        // Settable
        List<String> list = (List<String>) loi.set(queue, 0, 5);
        Assert.assertFalse(queue.contains(5));
        Assert.assertTrue(list.contains(5));
        list = (List<String>) loi.resize(queue, 5);
        Assert.assertEquals(4, queue.size());
        Assert.assertEquals(5, list.size());
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Aggregations

StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)73 Test (org.junit.Test)64 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)60 Configuration (org.apache.hadoop.conf.Configuration)25 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)25 InputSplit (org.apache.hadoop.mapred.InputSplit)25 BinaryObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector)24 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)23 Properties (java.util.Properties)20 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)20 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)18 BooleanObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector)18 ByteObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector)18 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)18 FloatObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector)18 HiveDecimalObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector)18 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)18 ShortObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector)18 TimestampObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector)18 RecordWriter (org.apache.hadoop.mapred.RecordWriter)18