Search in sources :

Example 1 with TBaseCreator

use of org.apache.carbondata.core.reader.ThriftReader.TBaseCreator in project carbondata by apache.

the class CarbonUtil method readDataChunk3.

public static DataChunk3 readDataChunk3(InputStream stream) throws IOException {
    TBaseCreator creator = new ThriftReader.TBaseCreator() {

        @Override
        public TBase create() {
            return new DataChunk3();
        }
    };
    TProtocol binaryIn = new TCompactProtocol(new TIOStreamTransport(stream));
    TBase t = creator.create();
    try {
        t.read(binaryIn);
    } catch (TException e) {
        throw new IOException(e);
    }
    return (DataChunk3) t;
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TBaseCreator(org.apache.carbondata.core.reader.ThriftReader.TBaseCreator) DataChunk3(org.apache.carbondata.format.DataChunk3) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TBase(org.apache.thrift.TBase) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 2 with TBaseCreator

use of org.apache.carbondata.core.reader.ThriftReader.TBaseCreator in project carbondata by apache.

the class CarbonUtil method readSchemaFile.

/**
 * This method will read the schema file from a given path
 *
 * @param schemaFilePath
 * @return
 */
public static org.apache.carbondata.format.TableInfo readSchemaFile(String schemaFilePath) throws IOException {
    TBaseCreator createTBase = new ThriftReader.TBaseCreator() {

        public org.apache.thrift.TBase<org.apache.carbondata.format.TableInfo, org.apache.carbondata.format.TableInfo._Fields> create() {
            return new org.apache.carbondata.format.TableInfo();
        }
    };
    ThriftReader thriftReader = new ThriftReader(schemaFilePath, createTBase);
    thriftReader.open();
    org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
    thriftReader.close();
    return tableInfo;
}
Also used : ThriftReader(org.apache.carbondata.core.reader.ThriftReader) TBaseCreator(org.apache.carbondata.core.reader.ThriftReader.TBaseCreator) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo)

Example 3 with TBaseCreator

use of org.apache.carbondata.core.reader.ThriftReader.TBaseCreator in project carbondata by apache.

the class CarbonUtil method inferSchema.

/**
 * This method will read the schema file from a given path
 *
 * @param schemaFilePath
 * @return
 */
public static org.apache.carbondata.format.TableInfo inferSchema(String carbonDataFilePath, AbsoluteTableIdentifier absoluteTableIdentifier, boolean schemaExists) throws IOException {
    TBaseCreator createTBase = new ThriftReader.TBaseCreator() {

        public org.apache.thrift.TBase<org.apache.carbondata.format.TableInfo, org.apache.carbondata.format.TableInfo._Fields> create() {
            return new org.apache.carbondata.format.TableInfo();
        }
    };
    if (schemaExists == false) {
        List<String> filePaths = getFilePathExternalFilePath(carbonDataFilePath + "/Fact/Part0/Segment_null");
        String fistFilePath = null;
        try {
            fistFilePath = filePaths.get(0);
        } catch (Exception e) {
            LOGGER.error("CarbonData file is not present in the table location");
        }
        CarbonHeaderReader carbonHeaderReader = new CarbonHeaderReader(fistFilePath);
        FileHeader fileHeader = carbonHeaderReader.readHeader();
        List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>();
        List<org.apache.carbondata.format.ColumnSchema> table_columns = fileHeader.getColumn_schema();
        for (int i = 0; i < table_columns.size(); i++) {
            ColumnSchema col = thriftColumnSchmeaToWrapperColumnSchema(table_columns.get(i));
            col.setColumnReferenceId(col.getColumnUniqueId());
            columnSchemaList.add(col);
        }
        TableSchema tableSchema = new TableSchema();
        tableSchema.setTableName(absoluteTableIdentifier.getTableName());
        tableSchema.setBucketingInfo(null);
        tableSchema.setSchemaEvalution(null);
        tableSchema.setTableId(UUID.randomUUID().toString());
        tableSchema.setListOfColumns(columnSchemaList);
        ThriftWrapperSchemaConverterImpl thriftWrapperSchemaConverter = new ThriftWrapperSchemaConverterImpl();
        SchemaEvolutionEntry schemaEvolutionEntry = new SchemaEvolutionEntry();
        schemaEvolutionEntry.setTimeStamp(System.currentTimeMillis());
        SchemaEvolution schemaEvol = new SchemaEvolution();
        List<SchemaEvolutionEntry> schEntryList = new ArrayList<>();
        schEntryList.add(schemaEvolutionEntry);
        schemaEvol.setSchemaEvolutionEntryList(schEntryList);
        tableSchema.setSchemaEvalution(schemaEvol);
        org.apache.carbondata.format.TableSchema thriftFactTable = thriftWrapperSchemaConverter.fromWrapperToExternalTableSchema(tableSchema);
        org.apache.carbondata.format.TableInfo tableInfo = new org.apache.carbondata.format.TableInfo(thriftFactTable, new ArrayList<org.apache.carbondata.format.TableSchema>());
        tableInfo.setDataMapSchemas(null);
        return tableInfo;
    } else {
        ThriftReader thriftReader = new ThriftReader(carbonDataFilePath, createTBase);
        thriftReader.open();
        org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
        thriftReader.close();
        return tableInfo;
    }
}
Also used : TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) TBaseCreator(org.apache.carbondata.core.reader.ThriftReader.TBaseCreator) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) SchemaEvolution(org.apache.carbondata.core.metadata.schema.SchemaEvolution) SchemaEvolutionEntry(org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry) ThriftReader(org.apache.carbondata.core.reader.ThriftReader) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) FileHeader(org.apache.carbondata.format.FileHeader) CarbonHeaderReader(org.apache.carbondata.core.reader.CarbonHeaderReader) InvalidConfigurationException(org.apache.carbondata.core.exception.InvalidConfigurationException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) TException(org.apache.thrift.TException) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)

Aggregations

TBaseCreator (org.apache.carbondata.core.reader.ThriftReader.TBaseCreator)3 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)2 ThriftReader (org.apache.carbondata.core.reader.ThriftReader)2 TException (org.apache.thrift.TException)2 CarbonDataWriterException (org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)1 InvalidConfigurationException (org.apache.carbondata.core.exception.InvalidConfigurationException)1 ThriftWrapperSchemaConverterImpl (org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)1 SchemaEvolution (org.apache.carbondata.core.metadata.schema.SchemaEvolution)1 SchemaEvolutionEntry (org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry)1 TableSchema (org.apache.carbondata.core.metadata.schema.table.TableSchema)1 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)1 CarbonHeaderReader (org.apache.carbondata.core.reader.CarbonHeaderReader)1 DataChunk3 (org.apache.carbondata.format.DataChunk3)1 FileHeader (org.apache.carbondata.format.FileHeader)1 TBase (org.apache.thrift.TBase)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)1