use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl in project carbondata by apache.
the class CarbonTable method buildFromDataFile.
public static CarbonTable buildFromDataFile(String tableName, String tablePath, String filePath) throws IOException {
CarbonHeaderReader carbonHeaderReader = new CarbonHeaderReader(filePath);
FileHeader fileHeader = carbonHeaderReader.readHeader();
TableSchemaBuilder builder = TableSchema.builder();
ThriftWrapperSchemaConverterImpl schemaConverter = new ThriftWrapperSchemaConverterImpl();
for (org.apache.carbondata.format.ColumnSchema column : fileHeader.getColumn_schema()) {
ColumnSchema columnSchema = schemaConverter.fromExternalToWrapperColumnSchema(column);
builder.addColumn(new StructField(columnSchema.getColumnName(), columnSchema.getDataType()), false);
}
TableSchema tableSchema = builder.tableName(tableName).build();
TableInfo tableInfo = new TableInfo();
tableInfo.setFactTable(tableSchema);
tableInfo.setTablePath(tablePath);
tableInfo.setDatabaseName("default");
tableInfo.setTableUniqueName(CarbonTable.buildUniqueName("default", tableSchema.getTableName()));
return buildFromTableInfo(tableInfo);
}
use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl in project carbondata by apache.
the class CarbonTableReader method parseCarbonMetadata.
/**
* Read the metadata of the given table and cache it in this.carbonCache (CarbonTableReader cache).
*
* @param table name of the given table.
* @return the CarbonTable instance which contains all the needed metadata for a table.
*/
private CarbonTable parseCarbonMetadata(SchemaTableName table) {
CarbonTable result = null;
try {
CarbonTableCacheModel cache = carbonCache.get().get(table);
if (cache == null) {
cache = new CarbonTableCacheModel();
}
if (cache.isValid())
return cache.carbonTable;
// If table is not previously cached, then:
// Step 1: get store path of the table and cache it.
// create table identifier. the table id is randomly generated.
CarbonTableIdentifier carbonTableIdentifier = new CarbonTableIdentifier(table.getSchemaName(), table.getTableName(), UUID.randomUUID().toString());
String storePath = config.getStorePath();
String tablePath = storePath + "/" + carbonTableIdentifier.getDatabaseName() + "/" + carbonTableIdentifier.getTableName();
// Step 2: read the metadata (tableInfo) of the table.
ThriftReader.TBaseCreator createTBase = new ThriftReader.TBaseCreator() {
// TBase is used to read and write thrift objects.
// TableInfo is a kind of TBase used to read and write table information.
// TableInfo is generated by thrift, see schema.thrift under format/src/main/thrift for details.
public TBase create() {
return new org.apache.carbondata.format.TableInfo();
}
};
ThriftReader thriftReader = new ThriftReader(CarbonTablePath.getSchemaFilePath(tablePath), createTBase);
thriftReader.open();
org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
thriftReader.close();
// Step 3: convert format level TableInfo to code level TableInfo
SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
// wrapperTableInfo is the code level information of a table in carbondata core, different from the Thrift TableInfo.
TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, table.getSchemaName(), table.getTableName(), tablePath);
// Step 4: Load metadata info into CarbonMetadata
CarbonMetadata.getInstance().loadTableMetadata(wrapperTableInfo);
cache.carbonTable = CarbonMetadata.getInstance().getCarbonTable(table.getSchemaName(), table.getTableName());
// cache the table
carbonCache.get().put(table, cache);
result = cache.carbonTable;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return result;
}
Aggregations