use of org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo in project hive by apache.
the class TestVectorExpressionWriters method testSetterDecimal.
private void testSetterDecimal(DecimalTypeInfo type) throws HiveException {
DecimalColumnVector dcv = VectorizedRowGroupGenUtil.generateDecimalColumnVector(type, true, false, this.vectorSize, new Random(10));
dcv.isNull[2] = true;
Object[] values = new Object[this.vectorSize];
VectorExpressionWriter vew = getWriter(type);
for (int i = 0; i < vectorSize; i++) {
// setValue() should be able to handle null input
values[i] = null;
values[i] = vew.setValue(values[i], dcv, i);
if (values[i] != null) {
Writable expected = getWritableValue(type, dcv.vector[i].getHiveDecimal());
Assert.assertEquals(expected, values[i]);
} else {
Assert.assertTrue(dcv.isNull[i]);
}
}
}
use of org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo in project hive by apache.
the class TestVectorExpressionWriters method testVectorExpressionWriterDecimal.
@Test
public void testVectorExpressionWriterDecimal() throws HiveException {
DecimalTypeInfo typeInfo = TypeInfoFactory.getDecimalTypeInfo(38, 18);
testWriterDecimal(typeInfo);
}
use of org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo in project hive by apache.
the class TestVectorExpressionWriters method testVectorExpressionSetterDecimal.
@Test
public void testVectorExpressionSetterDecimal() throws HiveException {
DecimalTypeInfo typeInfo = TypeInfoFactory.getDecimalTypeInfo(38, 18);
testSetterDecimal(typeInfo);
}
use of org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo in project hive by apache.
the class VectorUDAFAvgDecimal method init.
@Override
public void init(AggregationDesc desc) throws HiveException {
ExprNodeDesc inputExpr = desc.getParameters().get(0);
DecimalTypeInfo tiInput = (DecimalTypeInfo) inputExpr.getTypeInfo();
this.inputScale = (short) tiInput.scale();
this.inputPrecision = (short) tiInput.precision();
initPartialResultInspector();
}
use of org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo in project hive by apache.
the class TypeInfoToSchema method createAvroPrimitive.
private Schema createAvroPrimitive(TypeInfo typeInfo) {
PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) typeInfo;
Schema schema;
switch(primitiveTypeInfo.getPrimitiveCategory()) {
case STRING:
schema = Schema.create(Schema.Type.STRING);
break;
case CHAR:
schema = AvroSerdeUtils.getSchemaFor("{" + "\"type\":\"" + AvroSerDe.AVRO_STRING_TYPE_NAME + "\"," + "\"logicalType\":\"" + AvroSerDe.CHAR_TYPE_NAME + "\"," + "\"maxLength\":" + ((CharTypeInfo) typeInfo).getLength() + "}");
break;
case VARCHAR:
schema = AvroSerdeUtils.getSchemaFor("{" + "\"type\":\"" + AvroSerDe.AVRO_STRING_TYPE_NAME + "\"," + "\"logicalType\":\"" + AvroSerDe.VARCHAR_TYPE_NAME + "\"," + "\"maxLength\":" + ((VarcharTypeInfo) typeInfo).getLength() + "}");
break;
case BINARY:
schema = Schema.create(Schema.Type.BYTES);
break;
case BYTE:
schema = Schema.create(Schema.Type.INT);
break;
case SHORT:
schema = Schema.create(Schema.Type.INT);
break;
case INT:
schema = Schema.create(Schema.Type.INT);
break;
case LONG:
schema = Schema.create(Schema.Type.LONG);
break;
case FLOAT:
schema = Schema.create(Schema.Type.FLOAT);
break;
case DOUBLE:
schema = Schema.create(Schema.Type.DOUBLE);
break;
case BOOLEAN:
schema = Schema.create(Schema.Type.BOOLEAN);
break;
case DECIMAL:
DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo;
String precision = String.valueOf(decimalTypeInfo.precision());
String scale = String.valueOf(decimalTypeInfo.scale());
schema = AvroSerdeUtils.getSchemaFor("{" + "\"type\":\"bytes\"," + "\"logicalType\":\"decimal\"," + "\"precision\":" + precision + "," + "\"scale\":" + scale + "}");
break;
case DATE:
schema = AvroSerdeUtils.getSchemaFor("{" + "\"type\":\"" + AvroSerDe.AVRO_INT_TYPE_NAME + "\"," + "\"logicalType\":\"" + AvroSerDe.DATE_TYPE_NAME + "\"}");
break;
case TIMESTAMP:
schema = AvroSerdeUtils.getSchemaFor("{" + "\"type\":\"" + AvroSerDe.AVRO_LONG_TYPE_NAME + "\"," + "\"logicalType\":\"" + AvroSerDe.TIMESTAMP_TYPE_NAME + "\"}");
break;
case VOID:
schema = Schema.create(Schema.Type.NULL);
break;
default:
throw new UnsupportedOperationException(typeInfo + " is not supported.");
}
return schema;
}
Aggregations