Search in sources :

Example 6 with Index

use of org.apache.carbondata.core.index.dev.Index in project carbondata by apache.

the class TableIndex method prune.

/**
 * This method is used from any machine after it is distributed. It takes the distributable object
 * to prune the filters.
 *
 * @param distributable
 * @param filterExp
 * @return
 */
public List<ExtendedBlocklet> prune(List<Index> indices, IndexInputSplit distributable, FilterResolverIntf filterExp, List<PartitionSpec> partitions) throws IOException {
    List<ExtendedBlocklet> detailedBlocklets = new ArrayList<>();
    List<Blocklet> blocklets = new ArrayList<>();
    Set<Path> partitionsToPrune = getPartitionLocations(partitions);
    SegmentProperties segmentProperties = segmentPropertiesFetcher.getSegmentProperties(distributable.getSegment(), partitionsToPrune);
    FilterExecutor filterExecutor = FilterUtil.getFilterExecutorTree(filterExp, segmentProperties, null, table.getMinMaxCacheColumns(segmentProperties), false);
    for (Index index : indices) {
        blocklets.addAll(index.prune(filterExp, segmentProperties, filterExecutor, table));
    }
    BlockletSerializer serializer = new BlockletSerializer();
    String writePath = identifier.getTablePath() + CarbonCommonConstants.FILE_SEPARATOR + indexSchema.getIndexName();
    if (indexFactory.getIndexLevel() == IndexLevel.FG) {
        FileFactory.mkdirs(writePath);
    }
    for (Blocklet blocklet : blocklets) {
        ExtendedBlocklet detailedBlocklet = blockletDetailsFetcher.getExtendedBlocklet(blocklet, distributable.getSegment());
        if (indexFactory.getIndexLevel() == IndexLevel.FG) {
            String blockletWritePath = writePath + CarbonCommonConstants.FILE_SEPARATOR + System.nanoTime();
            detailedBlocklet.setIndexWriterPath(blockletWritePath);
            serializer.serializeBlocklet((FineGrainBlocklet) blocklet, blockletWritePath);
        }
        detailedBlocklet.setSegment(distributable.getSegment());
        detailedBlocklets.add(detailedBlocklet);
    }
    return detailedBlocklets;
}
Also used : Path(org.apache.hadoop.fs.Path) ExtendedBlocklet(org.apache.carbondata.core.indexstore.ExtendedBlocklet) Blocklet(org.apache.carbondata.core.indexstore.Blocklet) FineGrainBlocklet(org.apache.carbondata.core.index.dev.fgindex.FineGrainBlocklet) FilterExecutor(org.apache.carbondata.core.scan.filter.executer.FilterExecutor) ArrayList(java.util.ArrayList) Index(org.apache.carbondata.core.index.dev.Index) BlockIndex(org.apache.carbondata.core.indexstore.blockletindex.BlockIndex) CoarseGrainIndex(org.apache.carbondata.core.index.dev.cgindex.CoarseGrainIndex) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties) BlockletSerializer(org.apache.carbondata.core.index.dev.BlockletSerializer) ExtendedBlocklet(org.apache.carbondata.core.indexstore.ExtendedBlocklet)

Example 7 with Index

use of org.apache.carbondata.core.index.dev.Index in project carbondata by apache.

the class TableIndex method pruneWithFilter.

private List<ExtendedBlocklet> pruneWithFilter(List<Segment> segments, IndexFilter filter, Set<Path> partitionLocations, List<ExtendedBlocklet> blocklets, Map<Segment, List<Index>> indexes) throws IOException {
    Set<String> missingSISegments = filter.getMissingSISegments();
    for (Segment segment : segments) {
        List<Index> segmentIndices = indexes.get(segment);
        if (segment == null || segmentIndices == null || segmentIndices.isEmpty()) {
            continue;
        }
        boolean isExternalOrMissingSISegment = segment.isExternalSegment() || (missingSISegments != null && missingSISegments.contains(segment.getSegmentNo()));
        List<Blocklet> pruneBlocklets = new ArrayList<>();
        SegmentProperties segmentProperties;
        if (segmentIndices.get(0) instanceof BlockIndex) {
            segmentProperties = segmentPropertiesFetcher.getSegmentPropertiesFromIndex(segmentIndices.get(0));
        } else {
            segmentProperties = segmentPropertiesFetcher.getSegmentProperties(segment, partitionLocations);
        }
        if (filter.isResolvedOnSegment(segmentProperties)) {
            FilterExecutor filterExecutor;
            if (!isExternalOrMissingSISegment) {
                filterExecutor = FilterUtil.getFilterExecutorTree(filter.getResolver(), segmentProperties, null, table.getMinMaxCacheColumns(segmentProperties), false);
            } else {
                filterExecutor = FilterUtil.getFilterExecutorTree(filter.getExternalSegmentResolver(), segmentProperties, null, table.getMinMaxCacheColumns(segmentProperties), false);
            }
            for (Index index : segmentIndices) {
                if (!isExternalOrMissingSISegment) {
                    pruneBlocklets.addAll(index.prune(filter.getResolver(), segmentProperties, filterExecutor, this.table));
                } else {
                    pruneBlocklets.addAll(index.prune(filter.getExternalSegmentResolver(), segmentProperties, filterExecutor, this.table));
                }
            }
        } else {
            FilterExecutor filterExecutor;
            Expression expression = filter.getExpression();
            if (!isExternalOrMissingSISegment) {
                filterExecutor = FilterUtil.getFilterExecutorTree(new IndexFilter(segmentProperties, table, expression).getResolver(), segmentProperties, null, table.getMinMaxCacheColumns(segmentProperties), false);
            } else {
                filterExecutor = FilterUtil.getFilterExecutorTree(new IndexFilter(segmentProperties, table, expression).getExternalSegmentResolver(), segmentProperties, null, table.getMinMaxCacheColumns(segmentProperties), false);
            }
            for (Index index : segmentIndices) {
                if (!isExternalOrMissingSISegment) {
                    pruneBlocklets.addAll(index.prune(filter.getExpression(), segmentProperties, table, filterExecutor));
                } else {
                    pruneBlocklets.addAll(index.prune(filter.getExternalSegmentFilter(), segmentProperties, table, filterExecutor));
                }
            }
        }
        blocklets.addAll(addSegmentId(blockletDetailsFetcher.getExtendedBlocklets(pruneBlocklets, segment), segment));
    }
    return blocklets;
}
Also used : FilterExecutor(org.apache.carbondata.core.scan.filter.executer.FilterExecutor) ArrayList(java.util.ArrayList) Index(org.apache.carbondata.core.index.dev.Index) BlockIndex(org.apache.carbondata.core.indexstore.blockletindex.BlockIndex) CoarseGrainIndex(org.apache.carbondata.core.index.dev.cgindex.CoarseGrainIndex) BlockIndex(org.apache.carbondata.core.indexstore.blockletindex.BlockIndex) ExtendedBlocklet(org.apache.carbondata.core.indexstore.ExtendedBlocklet) Blocklet(org.apache.carbondata.core.indexstore.Blocklet) FineGrainBlocklet(org.apache.carbondata.core.index.dev.fgindex.FineGrainBlocklet) Expression(org.apache.carbondata.core.scan.expression.Expression) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties)

Example 8 with Index

use of org.apache.carbondata.core.index.dev.Index in project carbondata by apache.

the class IndexUtil method pruneIndexes.

static List<ExtendedBlocklet> pruneIndexes(CarbonTable table, FilterResolverIntf filterResolverIntf, List<Segment> segmentsToLoad, List<PartitionSpec> partitions, List<ExtendedBlocklet> blocklets, IndexLevel indexLevel, IndexChooser indexChooser) throws IOException {
    IndexExprWrapper indexExprWrapper = indexChooser.chooseIndex(indexLevel, filterResolverIntf);
    if (indexExprWrapper != null) {
        List<ExtendedBlocklet> extendedBlocklets = new ArrayList<>();
        // Prune segments from already pruned blocklets
        for (IndexInputSplitWrapper wrapper : indexExprWrapper.toDistributable(segmentsToLoad)) {
            TableIndex index = IndexStoreManager.getInstance().getIndex(table, wrapper.getDistributable().getIndexSchema());
            List<Index> indices = index.getTableIndexes(wrapper.getDistributable());
            List<ExtendedBlocklet> prunedBlocklet = new ArrayList<>();
            if (table.isTransactionalTable()) {
                prunedBlocklet.addAll(index.prune(indices, wrapper.getDistributable(), indexExprWrapper.getFilterResolverIntf(wrapper.getUniqueId()), partitions));
            } else {
                prunedBlocklet.addAll(index.prune(segmentsToLoad, new IndexFilter(filterResolverIntf), partitions));
            }
            // For all blocklets initialize the detail info so that it can be serialized to the driver.
            for (ExtendedBlocklet blocklet : prunedBlocklet) {
                blocklet.getDetailInfo();
                blocklet.setIndexUniqueId(wrapper.getUniqueId());
                blocklet.setCgIndexPresent(true);
            }
            extendedBlocklets.addAll(prunedBlocklet);
        }
        return indexExprWrapper.pruneBlocklets(extendedBlocklets);
    }
    return blocklets;
}
Also used : IndexInputSplitWrapper(org.apache.carbondata.core.index.dev.expr.IndexInputSplitWrapper) ArrayList(java.util.ArrayList) Index(org.apache.carbondata.core.index.dev.Index) ExtendedBlocklet(org.apache.carbondata.core.indexstore.ExtendedBlocklet) IndexExprWrapper(org.apache.carbondata.core.index.dev.expr.IndexExprWrapper)

Example 9 with Index

use of org.apache.carbondata.core.index.dev.Index in project carbondata by apache.

the class BlockletIndexFactory method clear.

@Override
public void clear(String segment) {
    SegmentBlockIndexInfo segmentBlockIndexInfo = segmentMap.remove(segment);
    Set<TableBlockIndexUniqueIdentifier> blockIndexes = null;
    if (null != segmentBlockIndexInfo) {
        blockIndexes = segmentBlockIndexInfo.getTableBlockIndexUniqueIdentifiers();
    }
    if (blockIndexes != null) {
        for (TableBlockIndexUniqueIdentifier blockIndex : blockIndexes) {
            TableBlockIndexUniqueIdentifierWrapper blockIndexWrapper = new TableBlockIndexUniqueIdentifierWrapper(blockIndex, this.getCarbonTable());
            BlockletIndexWrapper wrapper = cache.getIfPresent(blockIndexWrapper);
            if (null != wrapper) {
                List<BlockIndex> indexes = wrapper.getIndexes();
                for (Index index : indexes) {
                    if (index != null) {
                        cache.invalidate(blockIndexWrapper);
                        index.clear();
                    }
                }
            }
        }
    }
}
Also used : SegmentBlockIndexInfo(org.apache.carbondata.core.indexstore.SegmentBlockIndexInfo) TableBlockIndexUniqueIdentifierWrapper(org.apache.carbondata.core.indexstore.TableBlockIndexUniqueIdentifierWrapper) TableBlockIndexUniqueIdentifier(org.apache.carbondata.core.indexstore.TableBlockIndexUniqueIdentifier) Index(org.apache.carbondata.core.index.dev.Index) CacheableIndex(org.apache.carbondata.core.index.dev.CacheableIndex) CoarseGrainIndex(org.apache.carbondata.core.index.dev.cgindex.CoarseGrainIndex) BlockletIndexWrapper(org.apache.carbondata.core.indexstore.BlockletIndexWrapper)

Example 10 with Index

use of org.apache.carbondata.core.index.dev.Index in project carbondata by apache.

the class BlockletIndexFactory method getExtendedBlocklet.

private ExtendedBlocklet getExtendedBlocklet(Set<TableBlockIndexUniqueIdentifierWrapper> identifiersWrapper, Blocklet blocklet) throws IOException {
    for (TableBlockIndexUniqueIdentifierWrapper identifierWrapper : identifiersWrapper) {
        BlockletIndexWrapper wrapper = cache.get(identifierWrapper);
        List<BlockIndex> indexes = wrapper.getIndexes();
        for (Index index : indexes) {
            if (((BlockIndex) index).getTableTaskInfo(BlockletIndexRowIndexes.SUMMARY_INDEX_FILE_NAME).startsWith(blocklet.getFilePath())) {
                return ((BlockIndex) index).getDetailedBlocklet(blocklet.getBlockletId());
            }
        }
    }
    throw new IOException("Blocklet not found: " + blocklet.toString());
}
Also used : TableBlockIndexUniqueIdentifierWrapper(org.apache.carbondata.core.indexstore.TableBlockIndexUniqueIdentifierWrapper) Index(org.apache.carbondata.core.index.dev.Index) CacheableIndex(org.apache.carbondata.core.index.dev.CacheableIndex) CoarseGrainIndex(org.apache.carbondata.core.index.dev.cgindex.CoarseGrainIndex) IOException(java.io.IOException) BlockletIndexWrapper(org.apache.carbondata.core.indexstore.BlockletIndexWrapper)

Aggregations

Index (org.apache.carbondata.core.index.dev.Index)10 ArrayList (java.util.ArrayList)7 BlockIndex (org.apache.carbondata.core.indexstore.blockletindex.BlockIndex)7 CoarseGrainIndex (org.apache.carbondata.core.index.dev.cgindex.CoarseGrainIndex)6 ExtendedBlocklet (org.apache.carbondata.core.indexstore.ExtendedBlocklet)5 IOException (java.io.IOException)3 List (java.util.List)3 SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)3 FineGrainBlocklet (org.apache.carbondata.core.index.dev.fgindex.FineGrainBlocklet)3 Blocklet (org.apache.carbondata.core.indexstore.Blocklet)3 FilterExecutor (org.apache.carbondata.core.scan.filter.executer.FilterExecutor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CacheableIndex (org.apache.carbondata.core.index.dev.CacheableIndex)2 BlockletIndexWrapper (org.apache.carbondata.core.indexstore.BlockletIndexWrapper)2 TableBlockIndexUniqueIdentifierWrapper (org.apache.carbondata.core.indexstore.TableBlockIndexUniqueIdentifierWrapper)2 Expression (org.apache.carbondata.core.scan.expression.Expression)2 Path (org.apache.hadoop.fs.Path)2 HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1