Search in sources :

Example 11 with TableInfo

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());
}
Also used : TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) Test(org.junit.Test)

Example 12 with TableInfo

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;
}
Also used : KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException) IndexBuilderException(org.apache.carbondata.core.datastore.exception.IndexBuilderException) IOException(java.io.IOException) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) ThriftReader(org.apache.carbondata.core.reader.ThriftReader) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) SchemaConverter(org.apache.carbondata.core.metadata.converter.SchemaConverter) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)

Example 13 with TableInfo

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());
}
Also used : TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding) SchemaEvolution(org.apache.carbondata.core.metadata.schema.SchemaEvolution) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory) SchemaEvolutionEntry(org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) SchemaConverter(org.apache.carbondata.core.metadata.converter.SchemaConverter) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl) ThriftWriter(org.apache.carbondata.core.writer.ThriftWriter)

Aggregations

TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)13 TableSchema (org.apache.carbondata.core.metadata.schema.table.TableSchema)10 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)7 ArrayList (java.util.ArrayList)6 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)5 CarbonMetadata (org.apache.carbondata.core.metadata.CarbonMetadata)4 SchemaConverter (org.apache.carbondata.core.metadata.converter.SchemaConverter)4 ThriftWrapperSchemaConverterImpl (org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)4 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)4 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)3 SchemaEvolution (org.apache.carbondata.core.metadata.schema.SchemaEvolution)3 SchemaEvolutionEntry (org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry)3 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)3 Before (org.junit.Before)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 MockUp (mockit.MockUp)2 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)2 ThriftReader (org.apache.carbondata.core.reader.ThriftReader)2 ThriftWriter (org.apache.carbondata.core.writer.ThriftWriter)2