Search in sources :

Example 1 with DataMapExprWrapper

use of org.apache.carbondata.core.datamap.dev.expr.DataMapExprWrapper in project carbondata by apache.

the class CarbonInputFormat method getDataBlocksOfSegment.

/**
 * get data blocks of given segment
 */
protected List<CarbonInputSplit> getDataBlocksOfSegment(JobContext job, CarbonTable carbonTable, FilterResolverIntf resolver, BitSet matchedPartitions, List<Segment> segmentIds, PartitionInfo partitionInfo, List<Integer> oldPartitionIdList) throws IOException {
    QueryStatisticsRecorder recorder = CarbonTimeStatisticsFactory.createDriverRecorder();
    QueryStatistic statistic = new QueryStatistic();
    // get tokens for all the required FileSystem for table path
    TokenCache.obtainTokensForNamenodes(job.getCredentials(), new Path[] { new Path(carbonTable.getTablePath()) }, job.getConfiguration());
    boolean distributedCG = Boolean.parseBoolean(CarbonProperties.getInstance().getProperty(CarbonCommonConstants.USE_DISTRIBUTED_DATAMAP, CarbonCommonConstants.USE_DISTRIBUTED_DATAMAP_DEFAULT));
    DataMapExprWrapper dataMapExprWrapper = DataMapChooser.get().choose(getOrCreateCarbonTable(job.getConfiguration()), resolver);
    DataMapJob dataMapJob = getDataMapJob(job.getConfiguration());
    List<PartitionSpec> partitionsToPrune = getPartitionsToPrune(job.getConfiguration());
    List<ExtendedBlocklet> prunedBlocklets;
    if (distributedCG || dataMapExprWrapper.getDataMapType() == DataMapLevel.FG) {
        DistributableDataMapFormat datamapDstr = new DistributableDataMapFormat(carbonTable, dataMapExprWrapper, segmentIds, partitionsToPrune, BlockletDataMapFactory.class.getName());
        prunedBlocklets = dataMapJob.execute(datamapDstr, resolver);
        // Apply expression on the blocklets.
        prunedBlocklets = dataMapExprWrapper.pruneBlocklets(prunedBlocklets);
    } else {
        prunedBlocklets = dataMapExprWrapper.prune(segmentIds, partitionsToPrune);
    }
    List<CarbonInputSplit> resultFilterredBlocks = new ArrayList<>();
    int partitionIndex = 0;
    List<Integer> partitionIdList = new ArrayList<>();
    if (partitionInfo != null && partitionInfo.getPartitionType() != PartitionType.NATIVE_HIVE) {
        partitionIdList = partitionInfo.getPartitionIds();
    }
    for (ExtendedBlocklet blocklet : prunedBlocklets) {
        long partitionId = CarbonTablePath.DataFileUtil.getTaskIdFromTaskNo(CarbonTablePath.DataFileUtil.getTaskNo(blocklet.getPath()));
        // For other normal query should use newest partitionIdList
        if (partitionInfo != null && partitionInfo.getPartitionType() != PartitionType.NATIVE_HIVE) {
            if (oldPartitionIdList != null) {
                partitionIndex = oldPartitionIdList.indexOf((int) partitionId);
            } else {
                partitionIndex = partitionIdList.indexOf((int) partitionId);
            }
        }
        if (partitionIndex != -1) {
            // if this partition is not required, here will skip it.
            if (matchedPartitions == null || matchedPartitions.get(partitionIndex)) {
                CarbonInputSplit inputSplit = convertToCarbonInputSplit(blocklet);
                if (inputSplit != null) {
                    resultFilterredBlocks.add(inputSplit);
                }
            }
        }
    }
    statistic.addStatistics(QueryStatisticsConstants.LOAD_BLOCKS_DRIVER, System.currentTimeMillis());
    recorder.recordStatisticsForDriver(statistic, job.getConfiguration().get("query.id"));
    return resultFilterredBlocks;
}
Also used : Path(org.apache.hadoop.fs.Path) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) ArrayList(java.util.ArrayList) BlockletDataMapFactory(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapFactory) DataMapExprWrapper(org.apache.carbondata.core.datamap.dev.expr.DataMapExprWrapper) CarbonInputSplit(org.apache.carbondata.hadoop.CarbonInputSplit) PartitionSpec(org.apache.carbondata.core.indexstore.PartitionSpec) QueryStatisticsRecorder(org.apache.carbondata.core.stats.QueryStatisticsRecorder) ExtendedBlocklet(org.apache.carbondata.core.indexstore.ExtendedBlocklet) QueryStatistic(org.apache.carbondata.core.stats.QueryStatistic)

Aggregations

ArrayList (java.util.ArrayList)1 DataMapExprWrapper (org.apache.carbondata.core.datamap.dev.expr.DataMapExprWrapper)1 ExtendedBlocklet (org.apache.carbondata.core.indexstore.ExtendedBlocklet)1 PartitionSpec (org.apache.carbondata.core.indexstore.PartitionSpec)1 BlockletDataMapFactory (org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapFactory)1 QueryStatistic (org.apache.carbondata.core.stats.QueryStatistic)1 QueryStatisticsRecorder (org.apache.carbondata.core.stats.QueryStatisticsRecorder)1 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)1 CarbonInputSplit (org.apache.carbondata.hadoop.CarbonInputSplit)1 Path (org.apache.hadoop.fs.Path)1