use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class ThriftWrapperSchemaConverterImplTest method testFromExternalToWrapperTableInfo.
@Test
public void testFromExternalToWrapperTableInfo() {
final List<org.apache.carbondata.format.TableSchema> tableSchemas = new ArrayList();
long time = 1112745600000L;
tableSchemas.add(tabSchema);
new MockUp<org.apache.carbondata.format.TableInfo>() {
@Mock
public org.apache.carbondata.format.TableSchema getFact_table() {
return tabSchema;
}
@Mock
public List<org.apache.carbondata.format.TableSchema> getAggregate_table_list() {
return tableSchemas;
}
};
org.apache.carbondata.format.TableInfo externalTableInfo = new org.apache.carbondata.format.TableInfo();
TableInfo actualResult = thriftWrapperSchemaConverter.fromExternalToWrapperTableInfo(externalTableInfo, "dbName", "tableName", "/path");
assertEquals(time, actualResult.getLastUpdatedTime());
assertEquals("dbName_tableName", actualResult.getTableUniqueName());
}
use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class CarbonTableReader method parseCarbonMetadata.
/**
* parse carbon metadata into cc(CarbonTableReader cache)
*/
public CarbonTable parseCarbonMetadata(SchemaTableName table) {
CarbonTable result = null;
try {
CarbonTableCacheModel cache = cc.getOrDefault(table, new CarbonTableCacheModel());
if (cache.isValid())
return cache.carbonTable;
//Step1: get table meta path, load carbon table param
String storePath = config.getStorePath();
cache.carbonTableIdentifier = new CarbonTableIdentifier(table.getSchemaName(), table.getTableName(), UUID.randomUUID().toString());
cache.carbonTablePath = PathFactory.getInstance().getCarbonTablePath(storePath, cache.carbonTableIdentifier);
cc.put(table, cache);
//Step2: check file existed? read schema file
ThriftReader.TBaseCreator createTBase = new ThriftReader.TBaseCreator() {
public TBase create() {
return new org.apache.carbondata.format.TableInfo();
}
};
ThriftReader thriftReader = new ThriftReader(cache.carbonTablePath.getSchemaFilePath(), createTBase);
thriftReader.open();
org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
thriftReader.close();
// Step3: Transform Format Level TableInfo to Code Level TableInfo
SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, table.getSchemaName(), table.getTableName(), storePath);
wrapperTableInfo.setMetaDataFilepath(CarbonTablePath.getFolderContainingFile(cache.carbonTablePath.getSchemaFilePath()));
// Step4: Load metadata info into CarbonMetadata
CarbonMetadata.getInstance().loadTableMetadata(wrapperTableInfo);
cache.tableInfo = wrapperTableInfo;
cache.carbonTable = CarbonMetadata.getInstance().getCarbonTable(cache.carbonTableIdentifier.getTableUniqueName());
result = cache.carbonTable;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return result;
}
use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class StoreCreator method createTable.
private static CarbonTable createTable() throws IOException {
TableInfo tableInfo = new TableInfo();
tableInfo.setStorePath(absoluteTableIdentifier.getStorePath());
tableInfo.setDatabaseName(absoluteTableIdentifier.getCarbonTableIdentifier().getDatabaseName());
TableSchema tableSchema = new TableSchema();
tableSchema.setTableName(absoluteTableIdentifier.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(DataType.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(DataType.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(DataType.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(DataType.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(DataType.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(DataType.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(DataType.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(absoluteTableIdentifier.getCarbonTableIdentifier().getDatabaseName() + "_" + absoluteTableIdentifier.getCarbonTableIdentifier().getTableName());
tableInfo.setLastUpdatedTime(System.currentTimeMillis());
tableInfo.setFactTable(tableSchema);
tableInfo.setAggregateTableList(new ArrayList<TableSchema>());
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String schemaFilePath = carbonTablePath.getSchemaFilePath();
String schemaMetadataPath = CarbonTablePath.getFolderContainingFile(schemaFilePath);
tableInfo.setMetaDataFilepath(schemaMetadataPath);
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());
}
Aggregations