use of org.apache.hadoop.hive.common.type.HiveDecimalV1 in project hive by apache.
the class TestAvroSerializer method canSerializeUnions.
@Test
public void canSerializeUnions() throws SerDeException, IOException {
String field = "{ \"name\":\"union1\", \"type\":[\"float\", \"boolean\", \"string\"," + " {\"type\":\"bytes\", \"logicalType\":\"decimal\", \"precision\":5, \"scale\":4}] }";
GenericRecord r = serializeAndDeserialize(field, "union1", 424.4f);
assertEquals(424.4f, r.get("union1"));
r = serializeAndDeserialize(field, "union1", true);
assertEquals(true, r.get("union1"));
r = serializeAndDeserialize(field, "union1", "hello");
assertEquals("hello", r.get("union1"));
HiveDecimal dec = HiveDecimal.create("3.1415926");
r = serializeAndDeserialize(field, "union1", AvroSerdeUtils.getBufferFromDecimal(dec, 4));
HiveDecimal dec1 = AvroSerdeUtils.getHiveDecimalFromByteBuffer((ByteBuffer) r.get("union1"), 4);
// For now, old class.
HiveDecimalV1 oldDec = HiveDecimalV1.create(dec.bigDecimalValue());
assertEquals(oldDec.setScale(4).toString(), dec1.toString());
}
Aggregations