Search in sources :

Example 61 with ColumnSchema

use of org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema in project carbondata by apache.

the class SegmentPropertiesTestUtil method getDimensionColumn9.

public static ColumnSchema getDimensionColumn9() {
    ColumnSchema dimColumn = new ColumnSchema();
    dimColumn.setColumnar(false);
    dimColumn.setColumnName("IMEI9");
    dimColumn.setColumnUniqueId(UUID.randomUUID().toString());
    dimColumn.setDataType(DataTypes.STRING);
    dimColumn.setDimensionColumn(true);
    List<Encoding> encodeList = new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    encodeList.add(Encoding.DICTIONARY);
    dimColumn.setEncodingList(encodeList);
    dimColumn.setColumnGroup(1);
    dimColumn.setNumberOfChild(0);
    return dimColumn;
}
Also used : ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding)

Example 62 with ColumnSchema

use of org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema in project carbondata by apache.

the class CarbonUtil method getNumberOfDimensionColumns.

/**
 * Below method will be used to get the number of dimension column
 * in carbon column schema
 *
 * @param columnSchemaList column schema list
 * @return number of dimension column
 */
public static int getNumberOfDimensionColumns(List<ColumnSchema> columnSchemaList) {
    int numberOfDimensionColumns = 0;
    int previousColumnGroupId = -1;
    ColumnSchema columnSchema = null;
    for (int i = 0; i < columnSchemaList.size(); i++) {
        columnSchema = columnSchemaList.get(i);
        if (columnSchema.isDimensionColumn() && columnSchema.isColumnar()) {
            numberOfDimensionColumns++;
        } else if (columnSchema.isDimensionColumn()) {
            if (previousColumnGroupId != columnSchema.getColumnGroupId()) {
                previousColumnGroupId = columnSchema.getColumnGroupId();
                numberOfDimensionColumns++;
            }
        } else {
            break;
        }
    }
    return numberOfDimensionColumns;
}
Also used : ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)

Example 63 with ColumnSchema

use of org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema 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)

Example 64 with ColumnSchema

use of org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema in project carbondata by apache.

the class CarbonUtil method thriftColumnSchmeaToWrapperColumnSchema.

public static ColumnSchema thriftColumnSchmeaToWrapperColumnSchema(org.apache.carbondata.format.ColumnSchema externalColumnSchema) {
    ColumnSchema wrapperColumnSchema = new ColumnSchema();
    wrapperColumnSchema.setColumnUniqueId(externalColumnSchema.getColumn_id());
    wrapperColumnSchema.setColumnName(externalColumnSchema.getColumn_name());
    wrapperColumnSchema.setColumnar(externalColumnSchema.isColumnar());
    DataType dataType = thriftDataTyopeToWrapperDataType(externalColumnSchema.data_type);
    if (DataTypes.isDecimal(dataType)) {
        DecimalType decimalType = (DecimalType) dataType;
        decimalType.setPrecision(externalColumnSchema.getPrecision());
        decimalType.setScale(externalColumnSchema.getScale());
    }
    wrapperColumnSchema.setDataType(dataType);
    wrapperColumnSchema.setDimensionColumn(externalColumnSchema.isDimension());
    List<Encoding> encoders = new ArrayList<Encoding>();
    for (org.apache.carbondata.format.Encoding encoder : externalColumnSchema.getEncoders()) {
        encoders.add(fromExternalToWrapperEncoding(encoder));
    }
    wrapperColumnSchema.setEncodingList(encoders);
    wrapperColumnSchema.setNumberOfChild(externalColumnSchema.getNum_child());
    wrapperColumnSchema.setPrecision(externalColumnSchema.getPrecision());
    wrapperColumnSchema.setColumnGroup(externalColumnSchema.getColumn_group_id());
    wrapperColumnSchema.setScale(externalColumnSchema.getScale());
    wrapperColumnSchema.setDefaultValue(externalColumnSchema.getDefault_value());
    wrapperColumnSchema.setSchemaOrdinal(externalColumnSchema.getSchemaOrdinal());
    Map<String, String> properties = externalColumnSchema.getColumnProperties();
    if (properties != null) {
        if (properties.get(CarbonCommonConstants.SORT_COLUMNS) != null) {
            wrapperColumnSchema.setSortColumn(true);
        }
    }
    wrapperColumnSchema.setFunction(externalColumnSchema.getAggregate_function());
    List<org.apache.carbondata.format.ParentColumnTableRelation> parentColumnTableRelation = externalColumnSchema.getParentColumnTableRelations();
    if (null != parentColumnTableRelation) {
        wrapperColumnSchema.setParentColumnTableRelations(fromThriftToWrapperParentTableColumnRelations(parentColumnTableRelation));
    }
    return wrapperColumnSchema;
}
Also used : ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding) ParentColumnTableRelation(org.apache.carbondata.core.metadata.schema.table.column.ParentColumnTableRelation) DataType(org.apache.carbondata.core.metadata.datatype.DataType) DecimalType(org.apache.carbondata.core.metadata.datatype.DecimalType)

Example 65 with ColumnSchema

use of org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema in project carbondata by apache.

the class DataFileFooterConverter method readDataFileFooter.

/**
 * Below method will be used to convert thrift file meta to wrapper file meta
 */
@Override
public DataFileFooter readDataFileFooter(TableBlockInfo tableBlockInfo) throws IOException {
    DataFileFooter dataFileFooter = new DataFileFooter();
    FileReader fileReader = null;
    try {
        long completeBlockLength = tableBlockInfo.getBlockLength();
        long footerPointer = completeBlockLength - 8;
        fileReader = FileFactory.getFileHolder(FileFactory.getFileType(tableBlockInfo.getFilePath()));
        long actualFooterOffset = fileReader.readLong(tableBlockInfo.getFilePath(), footerPointer);
        CarbonFooterReader reader = new CarbonFooterReader(tableBlockInfo.getFilePath(), actualFooterOffset);
        FileFooter footer = reader.readFooter();
        dataFileFooter.setVersionId(ColumnarFormatVersion.valueOf((short) footer.getVersion()));
        dataFileFooter.setNumberOfRows(footer.getNum_rows());
        dataFileFooter.setSegmentInfo(getSegmentInfo(footer.getSegment_info()));
        List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>();
        List<org.apache.carbondata.format.ColumnSchema> table_columns = footer.getTable_columns();
        for (int i = 0; i < table_columns.size(); i++) {
            columnSchemaList.add(thriftColumnSchmeaToWrapperColumnSchema(table_columns.get(i)));
        }
        dataFileFooter.setColumnInTable(columnSchemaList);
        List<org.apache.carbondata.format.BlockletIndex> leaf_node_indices_Thrift = footer.getBlocklet_index_list();
        List<BlockletIndex> blockletIndexList = new ArrayList<BlockletIndex>();
        for (int i = 0; i < leaf_node_indices_Thrift.size(); i++) {
            BlockletIndex blockletIndex = getBlockletIndex(leaf_node_indices_Thrift.get(i));
            blockletIndexList.add(blockletIndex);
        }
        List<org.apache.carbondata.format.BlockletInfo> leaf_node_infos_Thrift = footer.getBlocklet_info_list();
        List<BlockletInfo> blockletInfoList = new ArrayList<BlockletInfo>();
        for (int i = 0; i < leaf_node_infos_Thrift.size(); i++) {
            BlockletInfo blockletInfo = getBlockletInfo(leaf_node_infos_Thrift.get(i));
            blockletInfo.setBlockletIndex(blockletIndexList.get(i));
            blockletInfoList.add(blockletInfo);
        }
        dataFileFooter.setBlockletList(blockletInfoList);
        dataFileFooter.setBlockletIndex(getBlockletIndexForDataFileFooter(blockletIndexList));
    } finally {
        if (null != fileReader) {
            fileReader.finish();
        }
    }
    return dataFileFooter;
}
Also used : BlockletIndex(org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex) ArrayList(java.util.ArrayList) BlockletInfo(org.apache.carbondata.core.metadata.blocklet.BlockletInfo) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) FileFooter(org.apache.carbondata.format.FileFooter) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) FileReader(org.apache.carbondata.core.datastore.FileReader) CarbonFooterReader(org.apache.carbondata.core.reader.CarbonFooterReader)

Aggregations

ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)164 ArrayList (java.util.ArrayList)80 Test (org.junit.Test)63 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)61 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)33 MockUp (mockit.MockUp)29 TableSchema (org.apache.carbondata.core.metadata.schema.table.TableSchema)14 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)13 HashMap (java.util.HashMap)12 SchemaEvolutionEntry (org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry)11 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)10 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)10 SchemaEvolution (org.apache.carbondata.core.metadata.schema.SchemaEvolution)9 SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)8 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)8 Map (java.util.Map)7 SegmentInfo (org.apache.carbondata.core.metadata.blocklet.SegmentInfo)7 BlockletInfo (org.apache.carbondata.core.metadata.blocklet.BlockletInfo)6 BlockletIndex (org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex)6 ThriftWrapperSchemaConverterImpl (org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)6