use of org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry in project carbondata by apache.
the class StoreCreator method createTable.
private static CarbonTable createTable() throws IOException {
TableInfo tableInfo = new TableInfo();
tableInfo.setDatabaseName(identifier.getCarbonTableIdentifier().getDatabaseName());
TableSchema tableSchema = new TableSchema();
tableSchema.setTableName(identifier.getCarbonTableIdentifier().getTableName());
List<ColumnSchema> columnSchemas = new ArrayList<ColumnSchema>();
ArrayList<Encoding> encodings = new ArrayList<>();
encodings.add(Encoding.DICTIONARY);
ColumnSchema id = new ColumnSchema();
id.setColumnName("ID");
id.setColumnar(true);
id.setDataType(DataTypes.INT);
id.setEncodingList(encodings);
id.setColumnUniqueId(UUID.randomUUID().toString());
id.setDimensionColumn(true);
id.setColumnGroup(1);
columnSchemas.add(id);
ColumnSchema date = new ColumnSchema();
date.setColumnName("date");
date.setColumnar(true);
date.setDataType(DataTypes.STRING);
date.setEncodingList(encodings);
date.setColumnUniqueId(UUID.randomUUID().toString());
date.setDimensionColumn(true);
date.setColumnGroup(2);
columnSchemas.add(date);
ColumnSchema country = new ColumnSchema();
country.setColumnName("country");
country.setColumnar(true);
country.setDataType(DataTypes.STRING);
country.setEncodingList(encodings);
country.setColumnUniqueId(UUID.randomUUID().toString());
country.setDimensionColumn(true);
country.setColumnGroup(3);
columnSchemas.add(country);
ColumnSchema name = new ColumnSchema();
name.setColumnName("name");
name.setColumnar(true);
name.setDataType(DataTypes.STRING);
name.setEncodingList(encodings);
name.setColumnUniqueId(UUID.randomUUID().toString());
name.setDimensionColumn(true);
name.setColumnGroup(4);
columnSchemas.add(name);
ColumnSchema phonetype = new ColumnSchema();
phonetype.setColumnName("phonetype");
phonetype.setColumnar(true);
phonetype.setDataType(DataTypes.STRING);
phonetype.setEncodingList(encodings);
phonetype.setColumnUniqueId(UUID.randomUUID().toString());
phonetype.setDimensionColumn(true);
phonetype.setColumnGroup(5);
columnSchemas.add(phonetype);
ColumnSchema serialname = new ColumnSchema();
serialname.setColumnName("serialname");
serialname.setColumnar(true);
serialname.setDataType(DataTypes.STRING);
serialname.setEncodingList(encodings);
serialname.setColumnUniqueId(UUID.randomUUID().toString());
serialname.setDimensionColumn(true);
serialname.setColumnGroup(6);
columnSchemas.add(serialname);
ColumnSchema salary = new ColumnSchema();
salary.setColumnName("salary");
salary.setColumnar(true);
salary.setDataType(DataTypes.INT);
salary.setEncodingList(new ArrayList<Encoding>());
salary.setColumnUniqueId(UUID.randomUUID().toString());
salary.setDimensionColumn(false);
salary.setColumnGroup(7);
columnSchemas.add(salary);
tableSchema.setListOfColumns(columnSchemas);
SchemaEvolution schemaEvol = new SchemaEvolution();
schemaEvol.setSchemaEvolutionEntryList(new ArrayList<SchemaEvolutionEntry>());
tableSchema.setSchemaEvalution(schemaEvol);
tableSchema.setTableId(UUID.randomUUID().toString());
tableInfo.setTableUniqueName(identifier.getCarbonTableIdentifier().getTableUniqueName());
tableInfo.setLastUpdatedTime(System.currentTimeMillis());
tableInfo.setFactTable(tableSchema);
tableInfo.setTablePath(identifier.getTablePath());
String schemaFilePath = CarbonTablePath.getSchemaFilePath(identifier.getTablePath());
String schemaMetadataPath = CarbonTablePath.getFolderContainingFile(schemaFilePath);
CarbonMetadata.getInstance().loadTableMetadata(tableInfo);
SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
org.apache.carbondata.format.TableInfo thriftTableInfo = schemaConverter.fromWrapperToExternalTableInfo(tableInfo, tableInfo.getDatabaseName(), tableInfo.getFactTable().getTableName());
org.apache.carbondata.format.SchemaEvolutionEntry schemaEvolutionEntry = new org.apache.carbondata.format.SchemaEvolutionEntry(tableInfo.getLastUpdatedTime());
thriftTableInfo.getFact_table().getSchema_evolution().getSchema_evolution_history().add(schemaEvolutionEntry);
FileFactory.FileType fileType = FileFactory.getFileType(schemaMetadataPath);
if (!FileFactory.isFileExist(schemaMetadataPath, fileType)) {
FileFactory.mkdirs(schemaMetadataPath, fileType);
}
ThriftWriter thriftWriter = new ThriftWriter(schemaFilePath, false);
thriftWriter.open();
thriftWriter.write(thriftTableInfo);
thriftWriter.close();
return CarbonMetadata.getInstance().getCarbonTable(tableInfo.getTableUniqueName());
}
use of org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry in project carbondata by apache.
the class ThriftWrapperSchemaConverterImpl method fromWrapperToExternalSchemaEvolutionEntry.
/* (non-Javadoc)
* Converts from wrapper to thrift schema evolution entry
*/
@Override
public org.apache.carbondata.format.SchemaEvolutionEntry fromWrapperToExternalSchemaEvolutionEntry(SchemaEvolutionEntry wrapperSchemaEvolutionEntry) {
org.apache.carbondata.format.SchemaEvolutionEntry thriftSchemaEvolutionEntry = new org.apache.carbondata.format.SchemaEvolutionEntry(wrapperSchemaEvolutionEntry.getTimeStamp());
if (null != wrapperSchemaEvolutionEntry.getAdded()) {
List<org.apache.carbondata.format.ColumnSchema> thriftAddedColumns = new ArrayList<org.apache.carbondata.format.ColumnSchema>();
for (ColumnSchema wrapperColumnSchema : wrapperSchemaEvolutionEntry.getAdded()) {
thriftAddedColumns.add(fromWrapperToExternalColumnSchema(wrapperColumnSchema));
}
thriftSchemaEvolutionEntry.setAdded(thriftAddedColumns);
}
if (null != wrapperSchemaEvolutionEntry.getRemoved()) {
List<org.apache.carbondata.format.ColumnSchema> thriftRemovedColumns = new ArrayList<org.apache.carbondata.format.ColumnSchema>();
for (ColumnSchema wrapperColumnSchema : wrapperSchemaEvolutionEntry.getRemoved()) {
thriftRemovedColumns.add(fromWrapperToExternalColumnSchema(wrapperColumnSchema));
}
thriftSchemaEvolutionEntry.setRemoved(thriftRemovedColumns);
}
return thriftSchemaEvolutionEntry;
}
Aggregations