Search in sources :

Example 1 with TypeInfoFactory.varcharTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.varcharTypeInfo in project carbondata by apache.

the class HiveDataTypeUtils method convertCarbonDataTypeToHive.

public static TypeInfo convertCarbonDataTypeToHive(CarbonColumn column) {
    int id = column.getDataType().getId();
    if (id == DataTypes.STRING.getId()) {
        return TypeInfoFactory.stringTypeInfo;
    } else if (id == DataTypes.DATE.getId()) {
        return TypeInfoFactory.dateTypeInfo;
    } else if (id == DataTypes.TIMESTAMP.getId()) {
        return TypeInfoFactory.timestampTypeInfo;
    } else if (id == DataTypes.BOOLEAN.getId()) {
        return TypeInfoFactory.booleanTypeInfo;
    } else if (id == DataTypes.BYTE.getId()) {
        return TypeInfoFactory.byteTypeInfo;
    } else if (id == DataTypes.SHORT.getId()) {
        return TypeInfoFactory.shortTypeInfo;
    } else if (id == DataTypes.INT.getId()) {
        return TypeInfoFactory.intTypeInfo;
    } else if (id == DataTypes.LONG.getId()) {
        return TypeInfoFactory.longTypeInfo;
    } else if (id == DataTypes.FLOAT.getId()) {
        return TypeInfoFactory.floatTypeInfo;
    } else if (id == DataTypes.DOUBLE.getId()) {
        return TypeInfoFactory.doubleTypeInfo;
    } else if (id == DataTypes.DECIMAL_TYPE_ID) {
        DecimalType type = (DecimalType) column.getDataType();
        return new DecimalTypeInfo(type.getPrecision(), type.getScale());
    } else if (id == DataTypes.BINARY.getId()) {
        return TypeInfoFactory.binaryTypeInfo;
    } else if (id == DataTypes.ARRAY_TYPE_ID) {
        ListTypeInfo typeInfo = new ListTypeInfo();
        if (!(column instanceof CarbonDimension)) {
            throw new RuntimeException("Failed to get child columns of column: " + column.getColName());
        }
        typeInfo.setListElementTypeInfo(convertCarbonDataTypeToHive(((CarbonDimension) column).getListOfChildDimensions().get(0)));
        return typeInfo;
    } else if (id == DataTypes.STRUCT_TYPE_ID) {
        StructTypeInfo typeInfo = new StructTypeInfo();
        if (!(column instanceof CarbonDimension)) {
            throw new RuntimeException("Failed to get child columns of column: " + column.getColName());
        }
        List<CarbonDimension> listOfChildDimensions = ((CarbonDimension) column).getListOfChildDimensions();
        ArrayList<String> allStructFieldNames = new ArrayList<>(listOfChildDimensions.size());
        ArrayList<TypeInfo> allStructFieldTypeInfos = new ArrayList<>(listOfChildDimensions.size());
        typeInfo.setAllStructFieldNames(allStructFieldNames);
        typeInfo.setAllStructFieldTypeInfos(allStructFieldTypeInfos);
        for (CarbonDimension dimension : listOfChildDimensions) {
            String[] columnsNames = dimension.getColName().split("\\.");
            allStructFieldNames.add(columnsNames[columnsNames.length - 1]);
            allStructFieldTypeInfos.add(convertCarbonDataTypeToHive(dimension));
        }
        return typeInfo;
    } else if (id == DataTypes.MAP_TYPE_ID) {
        MapTypeInfo typeInfo = new MapTypeInfo();
        List<CarbonDimension> listOfChildDimensions = ((CarbonDimension) column).getListOfChildDimensions().get(0).getListOfChildDimensions();
        typeInfo.setMapKeyTypeInfo(convertCarbonDataTypeToHive(listOfChildDimensions.get(0)));
        typeInfo.setMapValueTypeInfo(convertCarbonDataTypeToHive(listOfChildDimensions.get(1)));
        return typeInfo;
    } else if (id == DataTypes.VARCHAR.getId()) {
        return TypeInfoFactory.varcharTypeInfo;
    } else {
        throw new RuntimeException("convert DataType with invalid id: " + id);
    }
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) ArrayList(java.util.ArrayList) DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) List(java.util.List) ArrayList(java.util.ArrayList) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 DecimalType (org.apache.carbondata.core.metadata.datatype.DecimalType)1 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)1 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)1 ListTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo)1 MapTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo)1 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)1