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);
}
}
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);
}
}
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);
}
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;
}
}
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;
}
}
Aggregations