use of org.apache.hadoop.hive.serde2.objectinspector.CrossMapEqualComparer 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.CrossMapEqualComparer 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.CrossMapEqualComparer in project hive by apache.
the class TestCrossMapEqualComparer method testCompatibleType.
@Test
public void testCompatibleType() throws SerDeException, IOException {
// empty maps
TextStringMapHolder o1 = new TextStringMapHolder();
StructObjectInspector oi1 = (StructObjectInspector) ObjectInspectorFactory.getReflectionObjectInspector(TextStringMapHolder.class, ObjectInspectorOptions.JAVA);
LazySimpleSerDe serde = new LazySimpleSerDe();
Configuration conf = new Configuration();
Properties tbl = new Properties();
tbl.setProperty(serdeConstants.LIST_COLUMNS, ObjectInspectorUtils.getFieldNames(oi1));
tbl.setProperty(serdeConstants.LIST_COLUMN_TYPES, ObjectInspectorUtils.getFieldTypes(oi1));
LazySerDeParameters serdeParams = new LazySerDeParameters(conf, tbl, LazySimpleSerDe.class.getName());
serde.initialize(conf, tbl, null);
ObjectInspector oi2 = serde.getObjectInspector();
Object o2 = serializeAndDeserialize(o1, oi1, serde, serdeParams);
int rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi2, new CrossMapEqualComparer());
assertEquals(0, rc);
// equal maps
o1.mMap.put(new Text("42"), "The answer to Life, Universe And Everything");
o1.mMap.put(new Text("1729"), "A taxi cab number");
o2 = serializeAndDeserialize(o1, oi1, serde, serdeParams);
rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi2, new CrossMapEqualComparer());
assertEquals(0, rc);
// unequal maps
o1.mMap.put(new Text("1729"), "Hardy-Ramanujan Number");
rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi2, new CrossMapEqualComparer());
assertFalse(0 == rc);
}
use of org.apache.hadoop.hive.serde2.objectinspector.CrossMapEqualComparer in project hive by apache.
the class TestCrossMapEqualComparer method testIncompatibleType.
@Test
public void testIncompatibleType() throws SerDeException, IOException {
// empty maps
StringTextMapHolder o1 = new StringTextMapHolder();
StructObjectInspector oi1 = (StructObjectInspector) ObjectInspectorFactory.getReflectionObjectInspector(StringTextMapHolder.class, ObjectInspectorOptions.JAVA);
LazySimpleSerDe serde = new LazySimpleSerDe();
Configuration conf = new Configuration();
Properties tbl = new Properties();
tbl.setProperty(serdeConstants.LIST_COLUMNS, ObjectInspectorUtils.getFieldNames(oi1));
tbl.setProperty(serdeConstants.LIST_COLUMN_TYPES, ObjectInspectorUtils.getFieldTypes(oi1));
LazySerDeParameters serdeParams = new LazySerDeParameters(conf, tbl, LazySimpleSerDe.class.getName());
serde.initialize(conf, tbl, null);
ObjectInspector oi2 = serde.getObjectInspector();
Object o2 = serializeAndDeserialize(o1, oi1, serde, serdeParams);
int rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi2, new CrossMapEqualComparer());
assertEquals(0, rc);
// equal maps
o1.mMap.put("42", new Text("The answer to Life, Universe And Everything"));
o1.mMap.put("1729", new Text("A taxi cab number"));
o2 = serializeAndDeserialize(o1, oi1, serde, serdeParams);
rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi2, new CrossMapEqualComparer());
assertEquals(0, rc);
// unequal maps
o1.mMap.put("1729", new Text("Hardy-Ramanujan Number"));
rc = ObjectInspectorUtils.compare(o1, oi1, o2, oi2, new CrossMapEqualComparer());
assertFalse(0 == rc);
}
use of org.apache.hadoop.hive.serde2.objectinspector.CrossMapEqualComparer in project hive by apache.
the class TestLazyBinaryColumnarSerDe method testSerDe.
@Test
public void testSerDe() throws SerDeException {
StructObjectInspector oi = (StructObjectInspector) ObjectInspectorFactory.getReflectionObjectInspector(OuterStruct.class, ObjectInspectorOptions.JAVA);
String cols = ObjectInspectorUtils.getFieldNames(oi);
Properties props = new Properties();
props.setProperty(serdeConstants.LIST_COLUMNS, cols);
props.setProperty(serdeConstants.LIST_COLUMN_TYPES, ObjectInspectorUtils.getFieldTypes(oi));
LazyBinaryColumnarSerDe serde = new LazyBinaryColumnarSerDe();
serde.initialize(new Configuration(), props, null);
OuterStruct outerStruct = new OuterStruct();
outerStruct.mByte = 1;
outerStruct.mShort = 2;
outerStruct.mInt = 3;
outerStruct.mLong = 4l;
outerStruct.mFloat = 5.01f;
outerStruct.mDouble = 6.001d;
outerStruct.mString = "seven";
outerStruct.mBA = new byte[] { '2' };
InnerStruct is1 = new InnerStruct(8, 9l);
InnerStruct is2 = new InnerStruct(10, 11l);
outerStruct.mArray = new ArrayList<InnerStruct>(2);
outerStruct.mArray.add(is1);
outerStruct.mArray.add(is2);
outerStruct.mMap = new TreeMap<String, InnerStruct>();
outerStruct.mMap.put(new String("twelve"), new InnerStruct(13, 14l));
outerStruct.mMap.put(new String("fifteen"), new InnerStruct(16, 17l));
outerStruct.mStruct = new InnerStruct(18, 19l);
BytesRefArrayWritable braw = (BytesRefArrayWritable) serde.serialize(outerStruct, oi);
ObjectInspector out_oi = serde.getObjectInspector();
Object out_o = serde.deserialize(braw);
if (0 != ObjectInspectorUtils.compare(outerStruct, oi, out_o, out_oi, new CrossMapEqualComparer())) {
System.out.println("expected = " + SerDeUtils.getJSONString(outerStruct, oi));
System.out.println("actual = " + SerDeUtils.getJSONString(out_o, out_oi));
fail("Deserialized object does not compare");
}
}
Aggregations