Search in sources :

Example 6 with ThriftWrapperSchemaConverterImpl

use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl in project carbondata by apache.

the class SchemaReader method getTableInfo.

/**
 * the method returns the Wrapper TableInfo
 *
 * @param identifier
 * @return
 */
public static TableInfo getTableInfo(AbsoluteTableIdentifier identifier) throws IOException {
    org.apache.carbondata.format.TableInfo thriftTableInfo = CarbonUtil.readSchemaFile(CarbonTablePath.getSchemaFilePath(identifier.getTablePath()));
    ThriftWrapperSchemaConverterImpl thriftWrapperSchemaConverter = new ThriftWrapperSchemaConverterImpl();
    CarbonTableIdentifier carbonTableIdentifier = identifier.getCarbonTableIdentifier();
    return thriftWrapperSchemaConverter.fromExternalToWrapperTableInfo(thriftTableInfo, carbonTableIdentifier.getDatabaseName(), carbonTableIdentifier.getTableName(), identifier.getTablePath());
}
Also used : CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)

Example 7 with ThriftWrapperSchemaConverterImpl

use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl 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());
}
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) 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)

Example 8 with ThriftWrapperSchemaConverterImpl

use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl in project carbondata by apache.

the class CarbonWriterBuilder method persistSchemaFile.

/**
 * Save the schema of the {@param table} to {@param persistFilePath}
 * @param table table object containing schema
 * @param persistFilePath absolute file path with file name
 */
private void persistSchemaFile(CarbonTable table, String persistFilePath) throws IOException {
    TableInfo tableInfo = table.getTableInfo();
    String schemaMetadataPath = CarbonTablePath.getFolderContainingFile(persistFilePath);
    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(persistFilePath, false);
    thriftWriter.open();
    thriftWriter.write(thriftTableInfo);
    thriftWriter.close();
}
Also used : FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory) 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)

Example 9 with ThriftWrapperSchemaConverterImpl

use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl in project carbondata by apache.

the class AbstractFactDataWriter method getColumnSchemaListAndCardinality.

public static List<org.apache.carbondata.format.ColumnSchema> getColumnSchemaListAndCardinality(List<Integer> cardinality, int[] dictionaryColumnCardinality, List<ColumnSchema> wrapperColumnSchemaList) {
    List<org.apache.carbondata.format.ColumnSchema> columnSchemaList = new ArrayList<org.apache.carbondata.format.ColumnSchema>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
    int counter = 0;
    for (int i = 0; i < wrapperColumnSchemaList.size(); i++) {
        columnSchemaList.add(schemaConverter.fromWrapperToExternalColumnSchema(wrapperColumnSchemaList.get(i)));
        if (CarbonUtil.hasEncoding(wrapperColumnSchemaList.get(i).getEncodingList(), org.apache.carbondata.core.metadata.encoder.Encoding.DICTIONARY)) {
            cardinality.add(dictionaryColumnCardinality[counter]);
            counter++;
        } else if (!wrapperColumnSchemaList.get(i).isDimensionColumn()) {
            continue;
        } else {
            cardinality.add(-1);
        }
    }
    return columnSchemaList;
}
Also used : ArrayList(java.util.ArrayList) SchemaConverter(org.apache.carbondata.core.metadata.converter.SchemaConverter) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)

Example 10 with ThriftWrapperSchemaConverterImpl

use of org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl in project carbondata by apache.

the class SchemaReader method inferSchema.

public static TableInfo inferSchema(AbsoluteTableIdentifier identifier) throws IOException {
    // This routine is going to infer schema from the carbondata file footer
    // Convert the ColumnSchema -> TableSchema -> TableInfo.
    // Return the TableInfo.
    org.apache.carbondata.format.TableInfo tableInfo = CarbonUtil.inferSchema(identifier.getTablePath(), identifier, false);
    SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
    TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, identifier.getDatabaseName(), identifier.getTableName(), identifier.getTablePath());
    return wrapperTableInfo;
}
Also used : SchemaConverter(org.apache.carbondata.core.metadata.converter.SchemaConverter) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo)

Aggregations

ThriftWrapperSchemaConverterImpl (org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)12 SchemaConverter (org.apache.carbondata.core.metadata.converter.SchemaConverter)9 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)9 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)6 ArrayList (java.util.ArrayList)4 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)4 SchemaEvolution (org.apache.carbondata.core.metadata.schema.SchemaEvolution)4 SchemaEvolutionEntry (org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry)4 TableSchema (org.apache.carbondata.core.metadata.schema.table.TableSchema)4 ThriftWriter (org.apache.carbondata.core.writer.ThriftWriter)4 IOException (java.io.IOException)3 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)3 ThriftReader (org.apache.carbondata.core.reader.ThriftReader)3 CarbonTableIdentifier (org.apache.carbondata.core.metadata.CarbonTableIdentifier)2 CarbonHeaderReader (org.apache.carbondata.core.reader.CarbonHeaderReader)2 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)2 FileHeader (org.apache.carbondata.format.FileHeader)2 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 CarbonDataWriterException (org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)1 InvalidConfigurationException (org.apache.carbondata.core.exception.InvalidConfigurationException)1