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;
}
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);
}
}
Aggregations