Search in sources :

Example 6 with SegmentIndexFileStore

use of org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore in project carbondata by apache.

the class CarbonIndexFileMergeWriter method writeMergeIndexFileBasedOnSegmentFile.

private String writeMergeIndexFileBasedOnSegmentFile(String segmentId, List<String> indexFileNamesTobeAdded, SegmentFileStore sfs, CarbonFile[] indexFiles) throws IOException {
    SegmentIndexFileStore fileStore = new SegmentIndexFileStore();
    fileStore.readAllIIndexOfSegment(sfs.getSegmentFile(), sfs.getTablePath(), SegmentStatus.SUCCESS, true);
    Map<String, byte[]> indexMap = fileStore.getCarbonIndexMapWithFullPath();
    Map<String, Map<String, byte[]>> indexLocationMap = new HashMap<>();
    for (Map.Entry<String, byte[]> entry : indexMap.entrySet()) {
        Path path = new Path(entry.getKey());
        Map<String, byte[]> map = indexLocationMap.get(path.getParent().toString());
        if (map == null) {
            map = new HashMap<>();
            indexLocationMap.put(path.getParent().toString(), map);
        }
        map.put(path.getName(), entry.getValue());
    }
    for (Map.Entry<String, Map<String, byte[]>> entry : indexLocationMap.entrySet()) {
        String mergeIndexFile = writeMergeIndexFile(indexFileNamesTobeAdded, entry.getKey(), entry.getValue());
        for (Map.Entry<String, SegmentFileStore.FolderDetails> segentry : sfs.getLocationMap().entrySet()) {
            String location = segentry.getKey();
            if (segentry.getValue().isRelative()) {
                location = sfs.getTablePath() + CarbonCommonConstants.FILE_SEPARATOR + location;
            }
            if (new Path(entry.getKey()).equals(new Path(location))) {
                segentry.getValue().setMergeFileName(mergeIndexFile);
                break;
            }
        }
    }
    String uniqueId = String.valueOf(System.currentTimeMillis());
    String newSegmentFileName = SegmentFileStore.genSegmentFileName(segmentId, String.valueOf(uniqueId)) + CarbonTablePath.SEGMENT_EXT;
    String path = CarbonTablePath.getSegmentFilesLocation(table.getTablePath()) + CarbonCommonConstants.FILE_SEPARATOR + newSegmentFileName;
    SegmentFileStore.writeSegmentFile(sfs.getSegmentFile(), path);
    SegmentFileStore.updateSegmentFile(table.getTablePath(), segmentId, newSegmentFileName);
    for (CarbonFile file : indexFiles) {
        file.delete();
    }
    return uniqueId;
}
Also used : CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) Path(org.apache.hadoop.fs.Path) CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) SegmentIndexFileStore(org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with SegmentIndexFileStore

use of org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore in project carbondata by apache.

the class SegmentFileStore method getSegmentFileForPhysicalDataPartitions.

/**
 * It provides segment file only for the partitions which has physical index files.
 *
 * @param partitionSpecs
 */
public static SegmentFile getSegmentFileForPhysicalDataPartitions(String tablePath, List<PartitionSpec> partitionSpecs) throws IOException {
    SegmentFile segmentFile = null;
    for (PartitionSpec spec : partitionSpecs) {
        String location = spec.getLocation().toString();
        CarbonFile carbonFile = FileFactory.getCarbonFile(location);
        CarbonFile[] listFiles = carbonFile.listFiles(new CarbonFileFilter() {

            @Override
            public boolean accept(CarbonFile file) {
                return CarbonTablePath.isCarbonIndexFile(file.getAbsolutePath());
            }
        });
        if (listFiles != null && listFiles.length > 0) {
            boolean isRelative = false;
            if (location.startsWith(tablePath)) {
                location = location.substring(tablePath.length(), location.length());
                isRelative = true;
            }
            SegmentFile localSegmentFile = new SegmentFile();
            FolderDetails folderDetails = new FolderDetails();
            folderDetails.setRelative(isRelative);
            folderDetails.setPartitions(spec.getPartitions());
            folderDetails.setStatus(SegmentStatus.SUCCESS.getMessage());
            for (CarbonFile file : listFiles) {
                if (file.getName().endsWith(CarbonTablePath.MERGE_INDEX_FILE_EXT)) {
                    List<String> indexFiles = new SegmentIndexFileStore().getIndexFilesFromMergeFile(file.getAbsolutePath());
                    folderDetails.getFiles().addAll(indexFiles);
                    folderDetails.setMergeFileName(file.getName());
                } else {
                    folderDetails.getFiles().add(file.getName());
                }
            }
            localSegmentFile.addPath(location, folderDetails);
            if (segmentFile == null) {
                segmentFile = localSegmentFile;
            } else {
                segmentFile = segmentFile.merge(localSegmentFile);
            }
        }
    }
    return segmentFile;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) SegmentIndexFileStore(org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore) PartitionSpec(org.apache.carbondata.core.indexstore.PartitionSpec)

Example 8 with SegmentIndexFileStore

use of org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore in project carbondata by apache.

the class BlockletDataMapIndexStore method get.

@Override
public BlockletDataMap get(TableBlockIndexUniqueIdentifier identifier) throws IOException {
    String lruCacheKey = identifier.getUniqueTableSegmentIdentifier();
    BlockletDataMap dataMap = (BlockletDataMap) lruCache.get(lruCacheKey);
    if (dataMap == null) {
        try {
            SegmentIndexFileStore indexFileStore = new SegmentIndexFileStore();
            Set<String> filesRead = new HashSet<>();
            Map<String, BlockMetaInfo> blockMetaInfoMap = getBlockMetaInfoMap(identifier, indexFileStore, filesRead);
            dataMap = loadAndGetDataMap(identifier, indexFileStore, blockMetaInfoMap);
        } catch (MemoryException e) {
            LOGGER.error("memory exception when loading datamap: " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return dataMap;
}
Also used : MemoryException(org.apache.carbondata.core.memory.MemoryException) SegmentIndexFileStore(org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore) BlockletDataMap(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap) HashSet(java.util.HashSet)

Aggregations

SegmentIndexFileStore (org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 BlockletDataMap (org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap)2 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)2 DataFileFooterConverter (org.apache.carbondata.core.util.DataFileFooterConverter)2 List (java.util.List)1 Segment (org.apache.carbondata.core.datamap.Segment)1 CarbonFileFilter (org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)1 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)1 PartitionSpec (org.apache.carbondata.core.indexstore.PartitionSpec)1 MemoryException (org.apache.carbondata.core.memory.MemoryException)1 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)1 PartitionInfo (org.apache.carbondata.core.metadata.schema.PartitionInfo)1 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)1 Expression (org.apache.carbondata.core.scan.expression.Expression)1