Search in sources :

Example 11 with BitSetGroup

use of org.apache.carbondata.core.util.BitSetGroup in project carbondata by apache.

the class AndFilterExecuterImpl method applyFilter.

@Override
public BitSetGroup applyFilter(BlocksChunkHolder blockChunkHolder) throws FilterUnsupportedException, IOException {
    BitSetGroup leftFilters = leftExecuter.applyFilter(blockChunkHolder);
    if (leftFilters.isEmpty()) {
        return leftFilters;
    }
    BitSetGroup rightFilter = rightExecuter.applyFilter(blockChunkHolder);
    if (rightFilter.isEmpty()) {
        return rightFilter;
    }
    leftFilters.and(rightFilter);
    return leftFilters;
}
Also used : BitSetGroup(org.apache.carbondata.core.util.BitSetGroup)

Example 12 with BitSetGroup

use of org.apache.carbondata.core.util.BitSetGroup in project carbondata by apache.

the class FilterUtil method createBitSetGroupWithDefaultValue.

/**
   * This method will create default bitset group. Applicable for restructure scenarios.
   *
   * @param pageCount
   * @param totalRowCount
   * @param defaultValue
   * @return
   */
public static BitSetGroup createBitSetGroupWithDefaultValue(int pageCount, int totalRowCount, boolean defaultValue) {
    BitSetGroup bitSetGroup = new BitSetGroup(pageCount);
    int numberOfRows = Integer.parseInt(CarbonV3DataFormatConstants.NUMBER_OF_ROWS_PER_BLOCKLET_COLUMN_PAGE_DEFAULT);
    int pagesTobeFullFilled = totalRowCount / numberOfRows;
    int rowCountForLastPage = totalRowCount % numberOfRows;
    for (int i = 0; i < pagesTobeFullFilled; i++) {
        BitSet bitSet = new BitSet(numberOfRows);
        bitSet.set(0, numberOfRows, defaultValue);
        bitSetGroup.setBitSet(bitSet, i);
    }
    // create and fill bitset for the last page if any records are left
    if (rowCountForLastPage > 0) {
        BitSet bitSet = new BitSet(rowCountForLastPage);
        bitSet.set(0, rowCountForLastPage, defaultValue);
        bitSetGroup.setBitSet(bitSet, pagesTobeFullFilled);
    }
    return bitSetGroup;
}
Also used : BitSetGroup(org.apache.carbondata.core.util.BitSetGroup) BitSet(java.util.BitSet)

Example 13 with BitSetGroup

use of org.apache.carbondata.core.util.BitSetGroup in project carbondata by apache.

the class RowLevelFilterExecuterImpl method applyFilter.

@Override
public BitSetGroup applyFilter(BlocksChunkHolder blockChunkHolder) throws FilterUnsupportedException, IOException {
    readBlocks(blockChunkHolder);
    // CHECKSTYLE:ON
    int[] numberOfRows = null;
    int pageNumbers = 0;
    if (dimColEvaluatorInfoList.size() > 0) {
        if (isDimensionPresentInCurrentBlock[0]) {
            pageNumbers = blockChunkHolder.getDimensionRawDataChunk()[dimensionBlocksIndex[0]].getPagesCount();
            numberOfRows = blockChunkHolder.getDimensionRawDataChunk()[dimensionBlocksIndex[0]].getRowCount();
        } else {
            // specific for restructure case where default values need to be filled
            pageNumbers = blockChunkHolder.getDataBlock().numberOfPages();
            numberOfRows = new int[] { blockChunkHolder.getDataBlock().nodeSize() };
        }
    }
    if (msrColEvalutorInfoList.size() > 0) {
        if (isMeasurePresentInCurrentBlock[0]) {
            pageNumbers = blockChunkHolder.getMeasureRawDataChunk()[measureBlocksIndex[0]].getPagesCount();
            numberOfRows = blockChunkHolder.getMeasureRawDataChunk()[measureBlocksIndex[0]].getRowCount();
        } else {
            // specific for restructure case where default values need to be filled
            pageNumbers = blockChunkHolder.getDataBlock().numberOfPages();
            numberOfRows = new int[] { blockChunkHolder.getDataBlock().nodeSize() };
        }
    }
    BitSetGroup bitSetGroup = new BitSetGroup(pageNumbers);
    for (int i = 0; i < pageNumbers; i++) {
        BitSet set = new BitSet(numberOfRows[i]);
        RowIntf row = new RowImpl();
        boolean invalidRowsPresent = false;
        for (int index = 0; index < numberOfRows[i]; index++) {
            createRow(blockChunkHolder, row, i, index);
            Boolean rslt = false;
            try {
                rslt = exp.evaluate(row).getBoolean();
            }// too much log inforation only once the log will be printed.
             catch (FilterIllegalMemberException e) {
                FilterUtil.logError(e, invalidRowsPresent);
            }
            if (null != rslt && rslt) {
                set.set(index);
            }
        }
        bitSetGroup.setBitSet(set, i);
    }
    return bitSetGroup;
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) BitSetGroup(org.apache.carbondata.core.util.BitSetGroup) BitSet(java.util.BitSet) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 14 with BitSetGroup

use of org.apache.carbondata.core.util.BitSetGroup in project carbondata by apache.

the class FilterScanner method fillScannedResult.

/**
   * This method will process the data in below order
   * 1. first apply min max on the filter tree and check whether any of the filter
   * is fall on the range of min max, if not then return empty result
   * 2. If filter falls on min max range then apply filter on actual
   * data and get the filtered row index
   * 3. if row index is empty then return the empty result
   * 4. if row indexes is not empty then read only those blocks(measure or dimension)
   * which was present in the query but not present in the filter, as while applying filter
   * some of the blocks where already read and present in chunk holder so not need to
   * read those blocks again, this is to avoid reading of same blocks which was already read
   * 5. Set the blocks and filter indexes to result
   *
   * @param blocksChunkHolder
   * @throws FilterUnsupportedException
   */
private AbstractScannedResult fillScannedResult(BlocksChunkHolder blocksChunkHolder) throws FilterUnsupportedException, IOException {
    long startTime = System.currentTimeMillis();
    QueryStatistic totalBlockletStatistic = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.TOTAL_BLOCKLET_NUM);
    totalBlockletStatistic.addCountStatistic(QueryStatisticsConstants.TOTAL_BLOCKLET_NUM, totalBlockletStatistic.getCount() + 1);
    // apply filter on actual data
    BitSetGroup bitSetGroup = this.filterExecuter.applyFilter(blocksChunkHolder);
    // if indexes is empty then return with empty result
    if (bitSetGroup.isEmpty()) {
        CarbonUtil.freeMemory(blocksChunkHolder.getDimensionRawDataChunk(), blocksChunkHolder.getMeasureRawDataChunk());
        QueryStatistic scanTime = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.SCAN_BLOCKlET_TIME);
        scanTime.addCountStatistic(QueryStatisticsConstants.SCAN_BLOCKlET_TIME, scanTime.getCount() + (System.currentTimeMillis() - startTime));
        QueryStatistic scannedPages = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.PAGE_SCANNED);
        scannedPages.addCountStatistic(QueryStatisticsConstants.PAGE_SCANNED, scannedPages.getCount() + bitSetGroup.getScannedPages());
        return createEmptyResult();
    }
    AbstractScannedResult scannedResult = new FilterQueryScannedResult(blockExecutionInfo);
    scannedResult.setBlockletId(blockExecutionInfo.getBlockId() + CarbonCommonConstants.FILE_SEPARATOR + blocksChunkHolder.getDataBlock().nodeNumber());
    // valid scanned blocklet
    QueryStatistic validScannedBlockletStatistic = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.VALID_SCAN_BLOCKLET_NUM);
    validScannedBlockletStatistic.addCountStatistic(QueryStatisticsConstants.VALID_SCAN_BLOCKLET_NUM, validScannedBlockletStatistic.getCount() + 1);
    // adding statistics for valid number of pages
    QueryStatistic validPages = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.VALID_PAGE_SCANNED);
    validPages.addCountStatistic(QueryStatisticsConstants.VALID_PAGE_SCANNED, validPages.getCount() + bitSetGroup.getValidPages());
    QueryStatistic scannedPages = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.PAGE_SCANNED);
    scannedPages.addCountStatistic(QueryStatisticsConstants.PAGE_SCANNED, scannedPages.getCount() + bitSetGroup.getScannedPages());
    int[] rowCount = new int[bitSetGroup.getNumberOfPages()];
    // get the row indexes from bot set
    int[][] indexesGroup = new int[bitSetGroup.getNumberOfPages()][];
    for (int k = 0; k < indexesGroup.length; k++) {
        BitSet bitSet = bitSetGroup.getBitSet(k);
        if (bitSet != null && !bitSet.isEmpty()) {
            int[] indexes = new int[bitSet.cardinality()];
            int index = 0;
            for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
                indexes[index++] = i;
            }
            rowCount[k] = indexes.length;
            indexesGroup[k] = indexes;
        }
    }
    // loading delete data cache in blockexecutioninfo instance
    DeleteDeltaCacheLoaderIntf deleteCacheLoader = new BlockletDeleteDeltaCacheLoader(scannedResult.getBlockletId(), blocksChunkHolder.getDataBlock(), blockExecutionInfo.getAbsoluteTableIdentifier());
    deleteCacheLoader.loadDeleteDeltaFileDataToCache();
    scannedResult.setBlockletDeleteDeltaCache(blocksChunkHolder.getDataBlock().getDeleteDeltaDataCache());
    FileHolder fileReader = blocksChunkHolder.getFileReader();
    int[][] allSelectedDimensionBlocksIndexes = blockExecutionInfo.getAllSelectedDimensionBlocksIndexes();
    long dimensionReadTime = System.currentTimeMillis();
    DimensionRawColumnChunk[] projectionListDimensionChunk = blocksChunkHolder.getDataBlock().getDimensionChunks(fileReader, allSelectedDimensionBlocksIndexes);
    dimensionReadTime = System.currentTimeMillis() - dimensionReadTime;
    DimensionRawColumnChunk[] dimensionRawColumnChunks = new DimensionRawColumnChunk[blockExecutionInfo.getTotalNumberDimensionBlock()];
    // read dimension chunk blocks from file which is not present
    for (int i = 0; i < dimensionRawColumnChunks.length; i++) {
        if (null != blocksChunkHolder.getDimensionRawDataChunk()[i]) {
            dimensionRawColumnChunks[i] = blocksChunkHolder.getDimensionRawDataChunk()[i];
        }
    }
    for (int i = 0; i < allSelectedDimensionBlocksIndexes.length; i++) {
        for (int j = allSelectedDimensionBlocksIndexes[i][0]; j <= allSelectedDimensionBlocksIndexes[i][1]; j++) {
            dimensionRawColumnChunks[j] = projectionListDimensionChunk[j];
        }
    }
    long dimensionReadTime1 = System.currentTimeMillis();
    /**
     * in case projection if the projected dimension are not loaded in the dimensionColumnDataChunk
     * then loading them
     */
    int[] projectionListDimensionIndexes = blockExecutionInfo.getProjectionListDimensionIndexes();
    int projectionListDimensionIndexesLength = projectionListDimensionIndexes.length;
    for (int i = 0; i < projectionListDimensionIndexesLength; i++) {
        if (null == dimensionRawColumnChunks[projectionListDimensionIndexes[i]]) {
            dimensionRawColumnChunks[projectionListDimensionIndexes[i]] = blocksChunkHolder.getDataBlock().getDimensionChunk(fileReader, projectionListDimensionIndexes[i]);
        }
    }
    dimensionReadTime += (System.currentTimeMillis() - dimensionReadTime1);
    dimensionReadTime1 = System.currentTimeMillis();
    MeasureRawColumnChunk[] measureRawColumnChunks = new MeasureRawColumnChunk[blockExecutionInfo.getTotalNumberOfMeasureBlock()];
    int[][] allSelectedMeasureBlocksIndexes = blockExecutionInfo.getAllSelectedMeasureBlocksIndexes();
    MeasureRawColumnChunk[] projectionListMeasureChunk = blocksChunkHolder.getDataBlock().getMeasureChunks(fileReader, allSelectedMeasureBlocksIndexes);
    dimensionReadTime += System.currentTimeMillis() - dimensionReadTime1;
    // read the measure chunk blocks which is not present
    for (int i = 0; i < measureRawColumnChunks.length; i++) {
        if (null != blocksChunkHolder.getMeasureRawDataChunk()[i]) {
            measureRawColumnChunks[i] = blocksChunkHolder.getMeasureRawDataChunk()[i];
        }
    }
    for (int i = 0; i < allSelectedMeasureBlocksIndexes.length; i++) {
        for (int j = allSelectedMeasureBlocksIndexes[i][0]; j <= allSelectedMeasureBlocksIndexes[i][1]; j++) {
            measureRawColumnChunks[j] = projectionListMeasureChunk[j];
        }
    }
    dimensionReadTime1 = System.currentTimeMillis();
    /**
     * in case projection if the projected measure are not loaded in the measureColumnDataChunk
     * then loading them
     */
    int[] projectionListMeasureIndexes = blockExecutionInfo.getProjectionListMeasureIndexes();
    int projectionListMeasureIndexesLength = projectionListMeasureIndexes.length;
    for (int i = 0; i < projectionListMeasureIndexesLength; i++) {
        if (null == measureRawColumnChunks[projectionListMeasureIndexes[i]]) {
            measureRawColumnChunks[projectionListMeasureIndexes[i]] = blocksChunkHolder.getDataBlock().getMeasureChunk(fileReader, projectionListMeasureIndexes[i]);
        }
    }
    dimensionReadTime += System.currentTimeMillis() - dimensionReadTime1;
    DimensionColumnDataChunk[][] dimensionColumnDataChunks = new DimensionColumnDataChunk[dimensionRawColumnChunks.length][indexesGroup.length];
    MeasureColumnDataChunk[][] measureColumnDataChunks = new MeasureColumnDataChunk[measureRawColumnChunks.length][indexesGroup.length];
    for (int i = 0; i < dimensionRawColumnChunks.length; i++) {
        for (int j = 0; j < indexesGroup.length; j++) {
            if (dimensionRawColumnChunks[i] != null) {
                dimensionColumnDataChunks[i][j] = dimensionRawColumnChunks[i].convertToDimColDataChunk(j);
            }
        }
    }
    for (int i = 0; i < measureRawColumnChunks.length; i++) {
        for (int j = 0; j < indexesGroup.length; j++) {
            if (measureRawColumnChunks[i] != null) {
                measureColumnDataChunks[i][j] = measureRawColumnChunks[i].convertToMeasureColDataChunk(j);
            }
        }
    }
    scannedResult.setDimensionChunks(dimensionColumnDataChunks);
    scannedResult.setIndexes(indexesGroup);
    scannedResult.setMeasureChunks(measureColumnDataChunks);
    scannedResult.setRawColumnChunks(dimensionRawColumnChunks);
    scannedResult.setNumberOfRows(rowCount);
    // adding statistics for carbon scan time
    QueryStatistic scanTime = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.SCAN_BLOCKlET_TIME);
    scanTime.addCountStatistic(QueryStatisticsConstants.SCAN_BLOCKlET_TIME, scanTime.getCount() + (System.currentTimeMillis() - startTime - dimensionReadTime));
    QueryStatistic readTime = queryStatisticsModel.getStatisticsTypeAndObjMap().get(QueryStatisticsConstants.READ_BLOCKlET_TIME);
    readTime.addCountStatistic(QueryStatisticsConstants.READ_BLOCKlET_TIME, readTime.getCount() + dimensionReadTime);
    return scannedResult;
}
Also used : FilterQueryScannedResult(org.apache.carbondata.core.scan.result.impl.FilterQueryScannedResult) DimensionColumnDataChunk(org.apache.carbondata.core.datastore.chunk.DimensionColumnDataChunk) BitSet(java.util.BitSet) DeleteDeltaCacheLoaderIntf(org.apache.carbondata.core.mutate.data.DeleteDeltaCacheLoaderIntf) BlockletDeleteDeltaCacheLoader(org.apache.carbondata.core.mutate.data.BlockletDeleteDeltaCacheLoader) MeasureColumnDataChunk(org.apache.carbondata.core.datastore.chunk.MeasureColumnDataChunk) FileHolder(org.apache.carbondata.core.datastore.FileHolder) BitSetGroup(org.apache.carbondata.core.util.BitSetGroup) MeasureRawColumnChunk(org.apache.carbondata.core.datastore.chunk.impl.MeasureRawColumnChunk) DimensionRawColumnChunk(org.apache.carbondata.core.datastore.chunk.impl.DimensionRawColumnChunk) AbstractScannedResult(org.apache.carbondata.core.scan.result.AbstractScannedResult) QueryStatistic(org.apache.carbondata.core.stats.QueryStatistic)

Example 15 with BitSetGroup

use of org.apache.carbondata.core.util.BitSetGroup in project carbondata by apache.

the class RowLevelRangeLessThanEqualFilterExecuterImpl method applyFilter.

@Override
public BitSetGroup applyFilter(BlocksChunkHolder blockChunkHolder) throws FilterUnsupportedException, IOException {
    // select all rows if dimension does not exists in the current block
    if (!isDimensionPresentInCurrentBlock[0]) {
        int numberOfRows = blockChunkHolder.getDataBlock().nodeSize();
        return FilterUtil.createBitSetGroupWithDefaultValue(blockChunkHolder.getDataBlock().numberOfPages(), numberOfRows, true);
    }
    int blockIndex = segmentProperties.getDimensionOrdinalToBlockMapping().get(dimensionBlocksIndex[0]);
    if (null == blockChunkHolder.getDimensionRawDataChunk()[blockIndex]) {
        blockChunkHolder.getDimensionRawDataChunk()[blockIndex] = blockChunkHolder.getDataBlock().getDimensionChunk(blockChunkHolder.getFileReader(), blockIndex);
    }
    DimensionRawColumnChunk rawColumnChunk = blockChunkHolder.getDimensionRawDataChunk()[blockIndex];
    BitSetGroup bitSetGroup = new BitSetGroup(rawColumnChunk.getPagesCount());
    for (int i = 0; i < rawColumnChunk.getPagesCount(); i++) {
        if (rawColumnChunk.getMinValues() != null) {
            if (isScanRequired(rawColumnChunk.getMinValues()[i], this.filterRangeValues)) {
                BitSet bitSet = getFilteredIndexes(rawColumnChunk.convertToDimColDataChunk(i), rawColumnChunk.getRowCount()[i]);
                bitSetGroup.setBitSet(bitSet, i);
            }
        } else {
            BitSet bitSet = getFilteredIndexes(rawColumnChunk.convertToDimColDataChunk(i), rawColumnChunk.getRowCount()[i]);
            bitSetGroup.setBitSet(bitSet, i);
        }
    }
    return bitSetGroup;
}
Also used : BitSetGroup(org.apache.carbondata.core.util.BitSetGroup) BitSet(java.util.BitSet) DimensionRawColumnChunk(org.apache.carbondata.core.datastore.chunk.impl.DimensionRawColumnChunk)

Aggregations

BitSetGroup (org.apache.carbondata.core.util.BitSetGroup)15 BitSet (java.util.BitSet)12 DimensionRawColumnChunk (org.apache.carbondata.core.datastore.chunk.impl.DimensionRawColumnChunk)9 DimensionColumnDataChunk (org.apache.carbondata.core.datastore.chunk.DimensionColumnDataChunk)2 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)1 FileHolder (org.apache.carbondata.core.datastore.FileHolder)1 MeasureColumnDataChunk (org.apache.carbondata.core.datastore.chunk.MeasureColumnDataChunk)1 MeasureRawColumnChunk (org.apache.carbondata.core.datastore.chunk.impl.MeasureRawColumnChunk)1 BlockletDeleteDeltaCacheLoader (org.apache.carbondata.core.mutate.data.BlockletDeleteDeltaCacheLoader)1 DeleteDeltaCacheLoaderIntf (org.apache.carbondata.core.mutate.data.DeleteDeltaCacheLoaderIntf)1 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)1 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)1 RowIntf (org.apache.carbondata.core.scan.filter.intf.RowIntf)1 AbstractScannedResult (org.apache.carbondata.core.scan.result.AbstractScannedResult)1 FilterQueryScannedResult (org.apache.carbondata.core.scan.result.impl.FilterQueryScannedResult)1 QueryStatistic (org.apache.carbondata.core.stats.QueryStatistic)1 Test (org.junit.Test)1