Search in sources :

Example 11 with DecimalType

use of org.apache.carbondata.core.metadata.datatype.DecimalType in project carbondata by apache.

the class CarbonUtil method thriftColumnSchemaToWrapperColumnSchema.

public static ColumnSchema thriftColumnSchemaToWrapperColumnSchema(org.apache.carbondata.format.ColumnSchema externalColumnSchema) {
    ColumnSchema wrapperColumnSchema = new ColumnSchema();
    wrapperColumnSchema.setColumnUniqueId(externalColumnSchema.getColumn_id());
    wrapperColumnSchema.setColumnReferenceId(externalColumnSchema.getColumnReferenceId());
    wrapperColumnSchema.setColumnName(externalColumnSchema.getColumn_name());
    DataType dataType = thriftDataTypeToWrapperDataType(externalColumnSchema.data_type);
    if (DataTypes.isDecimal(dataType)) {
        DecimalType decimalType = (DecimalType) dataType;
        decimalType.setPrecision(externalColumnSchema.getPrecision());
        decimalType.setScale(externalColumnSchema.getScale());
    }
    wrapperColumnSchema.setDataType(dataType);
    wrapperColumnSchema.setDimensionColumn(externalColumnSchema.isDimension());
    List<Encoding> encoders = new ArrayList<Encoding>();
    for (org.apache.carbondata.format.Encoding encoder : externalColumnSchema.getEncoders()) {
        encoders.add(fromExternalToWrapperEncoding(encoder));
    }
    wrapperColumnSchema.setEncodingList(encoders);
    wrapperColumnSchema.setNumberOfChild(externalColumnSchema.getNum_child());
    wrapperColumnSchema.setPrecision(externalColumnSchema.getPrecision());
    wrapperColumnSchema.setScale(externalColumnSchema.getScale());
    wrapperColumnSchema.setDefaultValue(externalColumnSchema.getDefault_value());
    wrapperColumnSchema.setSchemaOrdinal(externalColumnSchema.getSchemaOrdinal());
    Map<String, String> properties = externalColumnSchema.getColumnProperties();
    if (properties != null) {
        if (properties.get(CarbonCommonConstants.SORT_COLUMNS) != null) {
            wrapperColumnSchema.setSortColumn(true);
        }
    }
    wrapperColumnSchema.setColumnProperties(properties);
    wrapperColumnSchema.setFunction(externalColumnSchema.getAggregate_function());
    List<org.apache.carbondata.format.ParentColumnTableRelation> parentColumnTableRelation = externalColumnSchema.getParentColumnTableRelations();
    if (null != parentColumnTableRelation) {
        wrapperColumnSchema.setParentColumnTableRelations(fromThriftToWrapperParentTableColumnRelations(parentColumnTableRelation));
    }
    return wrapperColumnSchema;
}
Also used : ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding) ParentColumnTableRelation(org.apache.carbondata.core.metadata.schema.table.column.ParentColumnTableRelation) DataType(org.apache.carbondata.core.metadata.datatype.DataType) DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType)

Example 12 with DecimalType

use of org.apache.carbondata.core.metadata.datatype.DecimalType 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

DecimalType (org.apache.carbondata.core.metadata.datatype.DecimalType)12 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)7 DataType (org.apache.carbondata.core.metadata.datatype.DataType)5 ArrayList (java.util.ArrayList)3 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)3 ParentColumnTableRelation (org.apache.carbondata.core.metadata.schema.table.column.ParentColumnTableRelation)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 TableSpec (org.apache.carbondata.core.datastore.TableSpec)1 StructField (org.apache.carbondata.core.metadata.datatype.StructField)1 StructType (org.apache.carbondata.core.metadata.datatype.StructType)1 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)1 CarbonColumnVectorImpl (org.apache.carbondata.core.scan.result.vector.impl.CarbonColumnVectorImpl)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