Search in sources :

Example 31 with CarbonFileFilter

use of org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter 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 32 with CarbonFileFilter

use of org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter in project carbondata by apache.

the class DiskBasedDMSchemaStorageProvider method retrieveAllSchemas.

@Override
public List<DataMapSchema> retrieveAllSchemas() throws IOException {
    List<DataMapSchema> dataMapSchemas = new ArrayList<>();
    CarbonFile carbonFile = FileFactory.getCarbonFile(storePath);
    CarbonFile[] carbonFiles = carbonFile.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            return file.getName().endsWith(".dmschema");
        }
    });
    for (CarbonFile file : carbonFiles) {
        dataMapSchemas.add(retrieveSchema(file.getName()));
    }
    return dataMapSchemas;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) ArrayList(java.util.ArrayList)

Aggregations

CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)32 CarbonFileFilter (org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)32 IOException (java.io.IOException)7 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)5 ArrayList (java.util.ArrayList)4 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)4 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)2 FileType (org.apache.carbondata.core.datastore.impl.FileFactory.FileType)2 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)2 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)2 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)2 CarbonTableIdentifier (org.apache.carbondata.core.carbon.CarbonTableIdentifier)1 Segment (org.apache.carbondata.core.datamap.Segment)1 FileHolder (org.apache.carbondata.core.datastorage.store.FileHolder)1 PartitionSpec (org.apache.carbondata.core.indexstore.PartitionSpec)1 SegmentIndexFileStore (org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore)1 CarbonFooterReader (org.apache.carbondata.core.reader.CarbonFooterReader)1 SegmentStatusManager (org.apache.carbondata.core.statusmanager.SegmentStatusManager)1 SegmentUpdateStatusManager (org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager)1 Before (org.junit.Before)1