Search in sources :

Example 1 with DataTypeDeserializer

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

the class CarbonLocalInputSplit method convertSplit.

public static CarbonInputSplit convertSplit(CarbonLocalInputSplit carbonLocalInputSplit) {
    CarbonInputSplit inputSplit = new CarbonInputSplit(carbonLocalInputSplit.getSegmentId(), carbonLocalInputSplit.getBlockletId(), carbonLocalInputSplit.getPath(), carbonLocalInputSplit.getStart(), carbonLocalInputSplit.getLength(), carbonLocalInputSplit.getLocations().toArray(new String[carbonLocalInputSplit.getLocations().size()]), carbonLocalInputSplit.getNumberOfBlocklets(), ColumnarFormatVersion.valueOf(carbonLocalInputSplit.getVersion()), carbonLocalInputSplit.getDeleteDeltaFiles());
    inputSplit.setFormat(carbonLocalInputSplit.getFileFormat());
    if (FileFormat.COLUMNAR_V3.ordinal() == inputSplit.getFileFormat().ordinal() && null != carbonLocalInputSplit.detailInfo && !carbonLocalInputSplit.detailInfo.equalsIgnoreCase("null")) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        // add typeAdapter for DataType Class for deserialization
        gsonBuilder.registerTypeAdapter(DataType.class, new DataTypeDeserializer());
        Gson gson = gsonBuilder.create();
        BlockletDetailInfo blockletDetailInfo = gson.fromJson(carbonLocalInputSplit.detailInfo, BlockletDetailInfo.class);
        if (null == blockletDetailInfo) {
            throw new RuntimeException("Could not read blocklet details");
        }
        try {
            blockletDetailInfo.readColumnSchema(blockletDetailInfo.getColumnSchemaBinary());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        inputSplit.setDetailInfo(blockletDetailInfo);
    }
    return inputSplit;
}
Also used : DataTypeDeserializer(org.apache.carbondata.core.metadata.datatype.DataTypeDeserializer) GsonBuilder(com.google.gson.GsonBuilder) BlockletDetailInfo(org.apache.carbondata.core.indexstore.BlockletDetailInfo) Gson(com.google.gson.Gson) CarbonInputSplit(org.apache.carbondata.hadoop.CarbonInputSplit) IOException(java.io.IOException)

Example 2 with DataTypeDeserializer

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

the class ColumnSchemaTest method testDataTypeOnColumnSchemaObject.

@Test
public void testDataTypeOnColumnSchemaObject() {
    ColumnSchema columnSchema = new ColumnSchema();
    columnSchema.setDataType(DataTypes.createDefaultArrayType());
    // without DataTypeDeserializer, after deserialization, data type is main class type instead
    // of child class type
    Gson gson = new Gson();
    String serializedColumnSchema = gson.toJson(columnSchema);
    ColumnSchema newColumnSchema = gson.fromJson(serializedColumnSchema, ColumnSchema.class);
    Assert.assertFalse(newColumnSchema.getDataType().isComplexType());
    // using DataTypeDeserializer
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(DataType.class, new DataTypeDeserializer());
    Gson newGson = gsonBuilder.create();
    ColumnSchema newColumnSchemaObj = newGson.fromJson(serializedColumnSchema, ColumnSchema.class);
    Assert.assertTrue(newColumnSchemaObj.getDataType().isComplexType());
}
Also used : DataTypeDeserializer(org.apache.carbondata.core.metadata.datatype.DataTypeDeserializer) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 DataTypeDeserializer (org.apache.carbondata.core.metadata.datatype.DataTypeDeserializer)2 IOException (java.io.IOException)1 BlockletDetailInfo (org.apache.carbondata.core.indexstore.BlockletDetailInfo)1 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)1 CarbonInputSplit (org.apache.carbondata.hadoop.CarbonInputSplit)1 Test (org.junit.Test)1