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