use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector in project hive by apache.
the class TestKuduSerDe method testSerDeRoundTrip.
@Test
public void testSerDeRoundTrip() throws Exception {
KuduSerDe serDe = new KuduSerDe();
serDe.initialize(BASE_CONF, TBL_PROPS, null);
PartialRow before = SCHEMA.newPartialRow();
before.addByte("key", (byte) 1);
before.addShort("int16", (short) 1);
before.addInt("int32", 1);
before.addLong("int64", 1L);
before.addBoolean("bool", true);
before.addFloat("float", 1.1f);
before.addDouble("double", 1.1d);
before.addString("string", "one");
before.addBinary("binary", "one".getBytes(UTF_8));
before.addTimestamp("timestamp", new Timestamp(NOW_MS));
before.addDecimal("decimal", new BigDecimal("1.111"));
before.setNull("null");
before.addInt("default", 1);
KuduWritable beforeWritable = new KuduWritable(before);
Object object = serDe.deserialize(beforeWritable);
// Capitalized `key` field to check for field case insensitivity.
List<String> fieldNames = Arrays.asList("KEY", "int16", "int32", "int64", "bool", "float", "double", "string", "binary", "timestamp", "decimal", "null", "default");
List<ObjectInspector> ois = Arrays.asList(PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.writableBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableBinaryObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector);
StandardStructObjectInspector objectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, ois);
KuduWritable afterWritable = serDe.serialize(object, objectInspector);
PartialRow after = afterWritable.getPartialRow();
for (int i = 0; i < SCHEMA.getColumnCount(); i++) {
if (SCHEMA.getColumnByIndex(i).getType() == Type.BINARY) {
assertArrayEquals("Columns not equal at index: " + i, before.getBinaryCopy(i), after.getBinaryCopy(i));
} else {
assertEquals("Columns not equal at index: " + i, before.getObject(i), after.getObject(i));
}
}
}
Aggregations