Search in sources :

Example 41 with Converter

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter in project drill by apache.

the class HiveFieldConverter method create.

public static HiveFieldConverter create(TypeInfo typeInfo, FragmentContext fragmentContext) throws IllegalAccessException, InstantiationException {
    switch(typeInfo.getCategory()) {
        case PRIMITIVE:
            final PrimitiveCategory pCat = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory();
            if (pCat != PrimitiveCategory.DECIMAL) {
                Class<? extends HiveFieldConverter> clazz = primMap.get(pCat);
                if (clazz != null) {
                    return clazz.newInstance();
                }
            } else {
                // For decimal, based on precision return appropriate converter.
                DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo;
                int precision = decimalTypeInfo.precision();
                int scale = decimalTypeInfo.scale();
                if (precision <= 9) {
                    return new Decimal9(precision, scale);
                } else if (precision <= 18) {
                    return new Decimal18(precision, scale);
                } else if (precision <= 28) {
                    return new Decimal28(precision, scale, fragmentContext);
                } else {
                    return new Decimal38(precision, scale, fragmentContext);
                }
            }
            throwUnsupportedHiveDataTypeError(pCat.toString());
            break;
        case LIST:
        case MAP:
        case STRUCT:
        case UNION:
        default:
            throwUnsupportedHiveDataTypeError(typeInfo.getCategory().toString());
    }
    return null;
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)20 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)17 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)16 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)13 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)10 ArrayList (java.util.ArrayList)8 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)8 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)6 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)6 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)5 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)5 Test (org.junit.Test)5 List (java.util.List)4 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)4 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)4 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)4 PrimitiveConverter (org.apache.parquet.io.api.PrimitiveConverter)4 Properties (java.util.Properties)3 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3