Search in sources :

Example 1 with BlockletDetailInfo

use of org.apache.carbondata.core.indexstore.BlockletDetailInfo in project carbondata by apache.

the class AbstractQueryExecutor method initQuery.

/**
 * Below method will be used to fill the executor properties based on query
 * model it will parse the query model and get the detail and fill it in
 * query properties
 *
 * @param queryModel
 */
protected void initQuery(QueryModel queryModel) throws IOException {
    StandardLogService.setThreadName(StandardLogService.getPartitionID(queryModel.getAbsoluteTableIdentifier().getCarbonTableIdentifier().getTableName()), queryModel.getQueryId());
    LOGGER.info("Query will be executed on table: " + queryModel.getAbsoluteTableIdentifier().getCarbonTableIdentifier().getTableName());
    // add executor service for query execution
    queryProperties.executorService = Executors.newCachedThreadPool();
    // Initializing statistics list to record the query statistics
    // creating copy on write to handle concurrent scenario
    queryProperties.queryStatisticsRecorder = CarbonTimeStatisticsFactory.createExecutorRecorder(queryModel.getQueryId());
    queryModel.setStatisticsRecorder(queryProperties.queryStatisticsRecorder);
    QueryStatistic queryStatistic = new QueryStatistic();
    // sort the block info
    // so block will be loaded in sorted order this will be required for
    // query execution
    Collections.sort(queryModel.getTableBlockInfos());
    if (queryModel.getTableBlockInfos().get(0).getDetailInfo() != null) {
        List<AbstractIndex> indexList = new ArrayList<>();
        Map<String, List<TableBlockInfo>> listMap = new LinkedHashMap<>();
        for (TableBlockInfo blockInfo : queryModel.getTableBlockInfos()) {
            List<TableBlockInfo> tableBlockInfos = listMap.get(blockInfo.getFilePath());
            if (tableBlockInfos == null) {
                tableBlockInfos = new ArrayList<>();
                listMap.put(blockInfo.getFilePath(), tableBlockInfos);
            }
            BlockletDetailInfo blockletDetailInfo = blockInfo.getDetailInfo();
            // the blocklet information from block file
            if (blockletDetailInfo.getBlockletInfo() == null) {
                readAndFillBlockletInfo(blockInfo, tableBlockInfos, blockletDetailInfo);
            } else {
                tableBlockInfos.add(blockInfo);
            }
        }
        for (List<TableBlockInfo> tableBlockInfos : listMap.values()) {
            indexList.add(new IndexWrapper(tableBlockInfos));
        }
        queryProperties.dataBlocks = indexList;
    } else {
        // get the table blocks
        CacheProvider cacheProvider = CacheProvider.getInstance();
        BlockIndexStore<TableBlockUniqueIdentifier, AbstractIndex> cache = (BlockIndexStore) cacheProvider.createCache(CacheType.EXECUTOR_BTREE);
        // remove the invalid table blocks, block which is deleted or compacted
        cache.removeTableBlocks(queryModel.getInvalidSegmentIds(), queryModel.getAbsoluteTableIdentifier());
        List<TableBlockUniqueIdentifier> tableBlockUniqueIdentifiers = prepareTableBlockUniqueIdentifier(queryModel.getTableBlockInfos(), queryModel.getAbsoluteTableIdentifier());
        cache.removeTableBlocksIfHorizontalCompactionDone(queryModel);
        queryProperties.dataBlocks = cache.getAll(tableBlockUniqueIdentifiers);
    }
    queryStatistic.addStatistics(QueryStatisticsConstants.LOAD_BLOCKS_EXECUTOR, System.currentTimeMillis());
    queryProperties.queryStatisticsRecorder.recordStatistics(queryStatistic);
    // calculating the total number of aggeragted columns
    int measureCount = queryModel.getProjectionMeasures().size();
    int currentIndex = 0;
    DataType[] dataTypes = new DataType[measureCount];
    for (ProjectionMeasure carbonMeasure : queryModel.getProjectionMeasures()) {
        // adding the data type and aggregation type of all the measure this
        // can be used
        // to select the aggregator
        dataTypes[currentIndex] = carbonMeasure.getMeasure().getDataType();
        currentIndex++;
    }
    queryProperties.measureDataTypes = dataTypes;
    // as aggregation will be executed in following order
    // 1.aggregate dimension expression
    // 2. expression
    // 3. query measure
    // so calculating the index of the expression start index
    // and measure column start index
    queryProperties.filterMeasures = new HashSet<>();
    queryProperties.complexFilterDimension = new HashSet<>();
    QueryUtil.getAllFilterDimensions(queryModel.getFilterExpressionResolverTree(), queryProperties.complexFilterDimension, queryProperties.filterMeasures);
    CarbonTable carbonTable = queryModel.getTable();
    TableProvider tableProvider = new SingleTableProvider(carbonTable);
    queryStatistic = new QueryStatistic();
    // dictionary column unique column id to dictionary mapping
    // which will be used to get column actual data
    queryProperties.columnToDictionaryMapping = QueryUtil.getDimensionDictionaryDetail(queryModel.getProjectionDimensions(), queryProperties.complexFilterDimension, queryModel.getAbsoluteTableIdentifier(), tableProvider);
    queryStatistic.addStatistics(QueryStatisticsConstants.LOAD_DICTIONARY, System.currentTimeMillis());
    queryProperties.queryStatisticsRecorder.recordStatistics(queryStatistic);
    queryModel.setColumnToDictionaryMapping(queryProperties.columnToDictionaryMapping);
}
Also used : TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BlockIndexStore(org.apache.carbondata.core.datastore.BlockIndexStore) ProjectionMeasure(org.apache.carbondata.core.scan.model.ProjectionMeasure) BlockletDetailInfo(org.apache.carbondata.core.indexstore.BlockletDetailInfo) TableBlockUniqueIdentifier(org.apache.carbondata.core.datastore.block.TableBlockUniqueIdentifier) DataType(org.apache.carbondata.core.metadata.datatype.DataType) List(java.util.List) ArrayList(java.util.ArrayList) QueryStatistic(org.apache.carbondata.core.stats.QueryStatistic) TableProvider(org.apache.carbondata.core.scan.filter.TableProvider) SingleTableProvider(org.apache.carbondata.core.scan.filter.SingleTableProvider) CacheProvider(org.apache.carbondata.core.cache.CacheProvider) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) SingleTableProvider(org.apache.carbondata.core.scan.filter.SingleTableProvider) AbstractIndex(org.apache.carbondata.core.datastore.block.AbstractIndex) IndexWrapper(org.apache.carbondata.core.indexstore.blockletindex.IndexWrapper)

Example 2 with BlockletDetailInfo

use of org.apache.carbondata.core.indexstore.BlockletDetailInfo in project carbondata by apache.

the class AbstractQueryExecutor method readAndFillBlockletInfo.

/**
 * Read the file footer of block file and get the blocklets to query
 */
private void readAndFillBlockletInfo(TableBlockInfo blockInfo, List<TableBlockInfo> tableBlockInfos, BlockletDetailInfo blockletDetailInfo) throws IOException {
    blockInfo.setBlockOffset(blockletDetailInfo.getBlockFooterOffset());
    blockInfo.setDetailInfo(null);
    DataFileFooter fileFooter = CarbonUtil.readMetadatFile(blockInfo);
    blockInfo.setDetailInfo(blockletDetailInfo);
    List<BlockletInfo> blockletList = fileFooter.getBlockletList();
    short count = 0;
    for (BlockletInfo blockletInfo : blockletList) {
        TableBlockInfo info = blockInfo.copy();
        BlockletDetailInfo detailInfo = info.getDetailInfo();
        detailInfo.setRowCount(blockletInfo.getNumberOfRows());
        // update min and max values in case of old store for measures as min and max is written
        // opposite for measures in old store
        byte[][] maxValues = CarbonUtil.updateMinMaxValues(fileFooter, blockletInfo.getBlockletIndex().getMinMaxIndex().getMaxValues(), blockletInfo.getBlockletIndex().getMinMaxIndex().getMinValues(), false);
        byte[][] minValues = CarbonUtil.updateMinMaxValues(fileFooter, blockletInfo.getBlockletIndex().getMinMaxIndex().getMaxValues(), blockletInfo.getBlockletIndex().getMinMaxIndex().getMinValues(), true);
        blockletInfo.getBlockletIndex().getMinMaxIndex().setMaxValues(maxValues);
        blockletInfo.getBlockletIndex().getMinMaxIndex().setMinValues(minValues);
        detailInfo.setBlockletInfo(blockletInfo);
        detailInfo.setPagesCount((short) blockletInfo.getNumberOfPages());
        detailInfo.setBlockletId(count);
        info.setDataBlockFromOldStore(true);
        tableBlockInfos.add(info);
        count++;
    }
}
Also used : TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) BlockletDetailInfo(org.apache.carbondata.core.indexstore.BlockletDetailInfo) BlockletInfo(org.apache.carbondata.core.metadata.blocklet.BlockletInfo)

Example 3 with BlockletDetailInfo

use of org.apache.carbondata.core.indexstore.BlockletDetailInfo in project carbondata by apache.

the class CarbonInputSplit method readFields.

@Override
public void readFields(DataInput in) throws IOException {
    super.readFields(in);
    this.segmentId = in.readUTF();
    this.version = ColumnarFormatVersion.valueOf(in.readShort());
    this.bucketId = in.readUTF();
    this.blockletId = in.readUTF();
    int numInvalidSegment = in.readInt();
    invalidSegments = new ArrayList<>(numInvalidSegment);
    for (int i = 0; i < numInvalidSegment; i++) {
        invalidSegments.add(in.readUTF());
    }
    int numberOfDeleteDeltaFiles = in.readInt();
    deleteDeltaFiles = new String[numberOfDeleteDeltaFiles];
    for (int i = 0; i < numberOfDeleteDeltaFiles; i++) {
        deleteDeltaFiles[i] = in.readUTF();
    }
    boolean detailInfoExists = in.readBoolean();
    if (detailInfoExists) {
        detailInfo = new BlockletDetailInfo();
        detailInfo.readFields(in);
    }
    boolean dataMapWriterPathExists = in.readBoolean();
    if (dataMapWriterPathExists) {
        dataMapWritePath = in.readUTF();
    }
}
Also used : BlockletDetailInfo(org.apache.carbondata.core.indexstore.BlockletDetailInfo)

Example 4 with BlockletDetailInfo

use of org.apache.carbondata.core.indexstore.BlockletDetailInfo in project carbondata by apache.

the class CarbonLocalInputSplit method convertSplit.

public static CarbonInputSplit convertSplit(CarbonLocalInputSplit carbonLocalInputSplit) {
    CarbonInputSplit inputSplit = new CarbonInputSplit(carbonLocalInputSplit.getSegmentId(), "0", new Path(carbonLocalInputSplit.getPath()), carbonLocalInputSplit.getStart(), carbonLocalInputSplit.getLength(), carbonLocalInputSplit.getLocations().toArray(new String[carbonLocalInputSplit.getLocations().size()]), carbonLocalInputSplit.getNumberOfBlocklets(), ColumnarFormatVersion.valueOf(carbonLocalInputSplit.getVersion()), carbonLocalInputSplit.getDeleteDeltaFiles());
    Gson gson = new Gson();
    BlockletDetailInfo blockletDetailInfo = gson.fromJson(carbonLocalInputSplit.detailInfo, BlockletDetailInfo.class);
    try {
        blockletDetailInfo.readColumnSchema(blockletDetailInfo.getColumnSchemaBinary());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    inputSplit.setDetailInfo(blockletDetailInfo);
    return inputSplit;
}
Also used : Path(org.apache.hadoop.fs.Path) BlockletDetailInfo(org.apache.carbondata.core.indexstore.BlockletDetailInfo) Gson(com.google.gson.Gson) CarbonInputSplit(org.apache.carbondata.hadoop.CarbonInputSplit) IOException(java.io.IOException)

Example 5 with BlockletDetailInfo

use of org.apache.carbondata.core.indexstore.BlockletDetailInfo in project carbondata by apache.

the class CarbonUtil method getDataFileFooter.

private static DataFileFooter getDataFileFooter(TableBlockInfo tableBlockInfo, boolean forceReadDataFileFooter) throws IOException {
    BlockletDetailInfo detailInfo = tableBlockInfo.getDetailInfo();
    if (detailInfo == null || forceReadDataFileFooter) {
        AbstractDataFileFooterConverter fileFooterConverter = DataFileFooterConverterFactory.getInstance().getDataFileFooterConverter(tableBlockInfo.getVersion());
        return fileFooterConverter.readDataFileFooter(tableBlockInfo);
    } else {
        DataFileFooter fileFooter = new DataFileFooter();
        fileFooter.setSchemaUpdatedTimeStamp(detailInfo.getSchemaUpdatedTimeStamp());
        ColumnarFormatVersion version = ColumnarFormatVersion.valueOf(detailInfo.getVersionNumber());
        AbstractDataFileFooterConverter dataFileFooterConverter = DataFileFooterConverterFactory.getInstance().getDataFileFooterConverter(version);
        List<ColumnSchema> schema = dataFileFooterConverter.getSchema(tableBlockInfo);
        fileFooter.setColumnInTable(schema);
        SegmentInfo segmentInfo = new SegmentInfo();
        segmentInfo.setColumnCardinality(detailInfo.getDimLens());
        fileFooter.setSegmentInfo(segmentInfo);
        return fileFooter;
    }
}
Also used : BlockletDetailInfo(org.apache.carbondata.core.indexstore.BlockletDetailInfo) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) SegmentInfo(org.apache.carbondata.core.metadata.blocklet.SegmentInfo) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) ColumnarFormatVersion(org.apache.carbondata.core.metadata.ColumnarFormatVersion)

Aggregations

BlockletDetailInfo (org.apache.carbondata.core.indexstore.BlockletDetailInfo)6 IOException (java.io.IOException)2 TableBlockInfo (org.apache.carbondata.core.datastore.block.TableBlockInfo)2 BlockletInfo (org.apache.carbondata.core.metadata.blocklet.BlockletInfo)2 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)2 Gson (com.google.gson.Gson)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 CacheProvider (org.apache.carbondata.core.cache.CacheProvider)1 BlockIndexStore (org.apache.carbondata.core.datastore.BlockIndexStore)1 AbstractIndex (org.apache.carbondata.core.datastore.block.AbstractIndex)1 TableBlockUniqueIdentifier (org.apache.carbondata.core.datastore.block.TableBlockUniqueIdentifier)1 ExtendedBlocklet (org.apache.carbondata.core.indexstore.ExtendedBlocklet)1 IndexWrapper (org.apache.carbondata.core.indexstore.blockletindex.IndexWrapper)1 ColumnarFormatVersion (org.apache.carbondata.core.metadata.ColumnarFormatVersion)1 SegmentInfo (org.apache.carbondata.core.metadata.blocklet.SegmentInfo)1 DataType (org.apache.carbondata.core.metadata.datatype.DataType)1