Search in sources :

Example 1 with HiveDecimalV1

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());
}
Also used : HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) GenericRecord(org.apache.avro.generic.GenericRecord) HiveDecimalV1(org.apache.hadoop.hive.common.type.HiveDecimalV1) Test(org.junit.Test)

Aggregations

GenericRecord (org.apache.avro.generic.GenericRecord)1 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)1 HiveDecimalV1 (org.apache.hadoop.hive.common.type.HiveDecimalV1)1 Test (org.junit.Test)1