use of org.apache.carbondata.core.metadata.datatype.DecimalType in project carbondata by apache.
the class CarbonUtil method thriftColumnSchmeaToWrapperColumnSchema.
public static ColumnSchema thriftColumnSchmeaToWrapperColumnSchema(org.apache.carbondata.format.ColumnSchema externalColumnSchema) {
ColumnSchema wrapperColumnSchema = new ColumnSchema();
wrapperColumnSchema.setColumnUniqueId(externalColumnSchema.getColumn_id());
wrapperColumnSchema.setColumnName(externalColumnSchema.getColumn_name());
wrapperColumnSchema.setColumnar(externalColumnSchema.isColumnar());
DataType dataType = thriftDataTyopeToWrapperDataType(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.setColumnGroup(externalColumnSchema.getColumn_group_id());
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.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 ColumnSchema method readFields.
@Override
public void readFields(DataInput in) throws IOException {
int id = in.readShort();
this.dataType = DataTypes.valueOf(id);
this.columnName = in.readUTF();
this.columnUniqueId = in.readUTF();
this.columnReferenceId = in.readUTF();
int encodingListSize = in.readShort();
this.encodingList = new ArrayList<>(encodingListSize);
for (int i = 0; i < encodingListSize; i++) {
id = in.readShort();
encodingList.add(Encoding.valueOf(id));
}
this.isDimensionColumn = in.readBoolean();
this.scale = in.readInt();
this.precision = in.readInt();
if (DataTypes.isDecimal(dataType)) {
DecimalType decimalType = (DecimalType) dataType;
decimalType.setPrecision(precision);
decimalType.setScale(scale);
}
this.schemaOrdinal = in.readInt();
this.numberOfChild = in.readInt();
this.defaultValue = WritableUtil.readByteArray(in);
int mapSize = in.readShort();
this.columnProperties = new HashMap<>(mapSize);
for (int i = 0; i < mapSize; i++) {
String key = in.readUTF();
String value = in.readUTF();
this.columnProperties.put(key, value);
}
this.invisible = in.readBoolean();
this.isSortColumn = in.readBoolean();
this.aggFunction = in.readUTF();
this.timeSeriesFunction = in.readUTF();
boolean isParentTableColumnRelationExists = in.readBoolean();
if (isParentTableColumnRelationExists) {
short parentColumnTableRelationSize = in.readShort();
this.parentColumnTableRelations = new ArrayList<>(parentColumnTableRelationSize);
for (int i = 0; i < parentColumnTableRelationSize; i++) {
ParentColumnTableRelation parentColumnTableRelation = new ParentColumnTableRelation(null, null, null);
parentColumnTableRelation.readFields(in);
parentColumnTableRelations.add(parentColumnTableRelation);
}
}
this.isLocalDictColumn = in.readBoolean();
}
use of org.apache.carbondata.core.metadata.datatype.DecimalType in project carbondata by apache.
the class CSVCarbonWriterTest method testWriteJsonSchemaWithCustomDecimalAndSpace.
@Test
public void testWriteJsonSchemaWithCustomDecimalAndSpace() {
String jsonSchema = new StringBuilder().append("[ \n").append(" {\"name\":\"string\"},\n").append(" {\"age\":\"int\"},\n").append(" {\"height\":\"double\"},\n").append(" {\"decimalField\":\"decimal( 17, 3)\"}\n").append("]").toString();
Schema schema = Schema.parseJson(jsonSchema);
assert (17 == ((DecimalType) schema.getFields()[3].getDataType()).getPrecision());
assert (3 == ((DecimalType) schema.getFields()[3].getDataType()).getScale());
}
use of org.apache.carbondata.core.metadata.datatype.DecimalType in project carbondata by apache.
the class CSVCarbonWriterTest method testWriteJsonSchemaWithCustomDecimal.
@Test
public void testWriteJsonSchemaWithCustomDecimal() {
String jsonSchema = new StringBuilder().append("[ \n").append(" {\"name\":\"string\"},\n").append(" {\"age\":\"int\"},\n").append(" {\"height\":\"double\"},\n").append(" {\"decimalField\":\"decimal(17,3)\"}\n").append("]").toString();
Schema schema = Schema.parseJson(jsonSchema);
assert (17 == ((DecimalType) schema.getFields()[3].getDataType()).getPrecision());
assert (3 == ((DecimalType) schema.getFields()[3].getDataType()).getScale());
}
use of org.apache.carbondata.core.metadata.datatype.DecimalType in project carbondata by apache.
the class ColumnPageEncoderMeta method writeMinMax.
private void writeMinMax(DataOutput out) throws IOException {
DataType dataType = columnSpec.getSchemaDataType();
if (dataType == DataTypes.BOOLEAN || dataType == DataTypes.BYTE) {
out.writeByte((byte) getMaxValue());
out.writeByte((byte) getMinValue());
// unique value is obsoleted, maintain for compatibility
out.writeLong(0L);
} else if (dataType == DataTypes.SHORT) {
out.writeShort((short) getMaxValue());
out.writeShort((short) getMinValue());
// unique value is obsoleted, maintain for compatibility
out.writeLong(0L);
} else if (dataType == DataTypes.INT) {
out.writeInt((int) getMaxValue());
out.writeInt((int) getMinValue());
// unique value is obsoleted, maintain for compatibility
out.writeLong(0L);
} else if (dataType == DataTypes.LONG || dataType == DataTypes.TIMESTAMP) {
out.writeLong((Long) getMaxValue());
out.writeLong((Long) getMinValue());
// unique value is obsoleted, maintain for compatibility
out.writeLong(0L);
} else if (dataType == DataTypes.DOUBLE) {
out.writeDouble((Double) getMaxValue());
out.writeDouble((Double) getMinValue());
// unique value is obsoleted, maintain for compatibility
out.writeDouble(0d);
} else if (dataType == DataTypes.FLOAT) {
out.writeFloat((Float) getMaxValue());
out.writeFloat((Float) getMinValue());
// unique value is obsoleted, maintain for compatibility
out.writeFloat(0f);
} else if (DataTypes.isDecimal(dataType)) {
byte[] maxAsBytes = getMaxAsBytes(columnSpec.getSchemaDataType());
byte[] minAsBytes = getMinAsBytes(columnSpec.getSchemaDataType());
byte[] unique = DataTypeUtil.bigDecimalToByte(BigDecimal.ZERO);
out.writeShort((short) maxAsBytes.length);
out.write(maxAsBytes);
out.writeShort((short) minAsBytes.length);
out.write(minAsBytes);
// unique value is obsoleted, maintain for compatibility
out.writeShort((short) unique.length);
out.write(unique);
if (DataTypes.isDecimal(dataType)) {
DecimalType decimalType = (DecimalType) dataType;
out.writeInt(decimalType.getScale());
out.writeInt(decimalType.getPrecision());
} else {
out.writeInt(-1);
out.writeInt(-1);
}
} else if (dataType == DataTypes.BYTE_ARRAY || dataType == DataTypes.BINARY) {
// for complex type, it will come here, ignoring stats for complex type
// TODO: support stats for complex type
} else {
throw new IllegalArgumentException("invalid data type: " + storeDataType);
}
}
Aggregations