Search in sources :

Example 1 with DecimalType

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;
}
Also used : 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 2 with DecimalType

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();
}
Also used : DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType)

Example 3 with DecimalType

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());
}
Also used : ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType) Test(org.junit.Test)

Example 4 with DecimalType

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());
}
Also used : ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType) Test(org.junit.Test)

Example 5 with DecimalType

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);
    }
}
Also used : DataType(org.apache.carbondata.core.metadata.datatype.DataType) DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType)

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