Search in sources :

Example 6 with CarbonFileFilter

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

the class CarbonTablePath method getCarbonUpdatedIndexFilePath.

/**
   * Below method will be used to get the index file present in the segment folder
   * based on task id
   *
   * @param taskId      task id of the file
   * @param partitionId partition number
   * @param segmentId   segment number
   * @return full qualified carbon index path
   */
public String getCarbonUpdatedIndexFilePath(final String taskId, final String partitionId, final String segmentId) {
    String segmentDir = getSegmentDir(partitionId, segmentId);
    CarbonFile carbonFile = FileFactory.getCarbonFile(segmentDir, FileFactory.getFileType(segmentDir));
    CarbonFile[] files = carbonFile.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            return file.getName().startsWith(taskId) && file.getName().endsWith(INDEX_FILE_EXT);
        }
    });
    if (files.length > 0) {
        return files[0].getAbsolutePath();
    } else {
        throw new RuntimeException("Missing Carbon Updated index file for partition[" + partitionId + "] Segment[" + segmentId + "], taskId[" + taskId + "]");
    }
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)

Example 7 with CarbonFileFilter

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

the class CarbonTablePath method getCarbonDeleteDeltaFilePath.

/**
   * Below method will be used to get the index file present in the segment folder
   * based on task id
   *
   * @param taskId      task id of the file
   * @param partitionId partition number
   * @param segmentId   segment number
   * @return full qualified carbon index path
   */
public String getCarbonDeleteDeltaFilePath(final String taskId, final String partitionId, final String segmentId) {
    String segmentDir = getSegmentDir(partitionId, segmentId);
    CarbonFile carbonFile = FileFactory.getCarbonFile(segmentDir, FileFactory.getFileType(segmentDir));
    CarbonFile[] files = carbonFile.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            return file.getName().startsWith(taskId) && file.getName().endsWith(DELETE_DELTA_FILE_EXT);
        }
    });
    if (files.length > 0) {
        return files[0].getAbsolutePath();
    } else {
        throw new RuntimeException("Missing Carbon delete delta file index file for partition[" + partitionId + "] Segment[" + segmentId + "], taskId[" + taskId + "]");
    }
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)

Example 8 with CarbonFileFilter

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

the class CarbonTablePath method getCarbonIndexFilePath.

/**
   * Below method will be used to get the index file present in the segment folder
   * based on task id
   *
   * @param taskId      task id of the file
   * @param partitionId partition number
   * @param segmentId   segment number
   * @return full qualified carbon index path
   */
public String getCarbonIndexFilePath(final String taskId, final String partitionId, final String segmentId, final String bucketNumber) {
    String segmentDir = getSegmentDir(partitionId, segmentId);
    CarbonFile carbonFile = FileFactory.getCarbonFile(segmentDir, FileFactory.getFileType(segmentDir));
    CarbonFile[] files = carbonFile.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            if (bucketNumber.equals("-1")) {
                return file.getName().startsWith(taskId) && file.getName().endsWith(INDEX_FILE_EXT);
            }
            return file.getName().startsWith(taskId + "-" + bucketNumber) && file.getName().endsWith(INDEX_FILE_EXT);
        }
    });
    if (files.length > 0) {
        return files[0].getAbsolutePath();
    } else {
        throw new RuntimeException("Missing Carbon index file for partition[" + partitionId + "] Segment[" + segmentId + "], taskId[" + taskId + "]");
    }
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)

Example 9 with CarbonFileFilter

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

the class ManageDictionaryAndBTree method deleteDictionaryFileAndCache.

/**
   * This method will delete the dictionary files for the given column IDs and
   * clear the dictionary cache
   *
   * @param columnSchema
   * @param carbonTableIdentifier
   * @param storePath
   */
public static void deleteDictionaryFileAndCache(final ColumnSchema columnSchema, CarbonTableIdentifier carbonTableIdentifier, String storePath) {
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(storePath, carbonTableIdentifier);
    String metadataDirectoryPath = carbonTablePath.getMetadataDirectoryPath();
    CarbonFile metadataDir = FileFactory.getCarbonFile(metadataDirectoryPath, FileFactory.getFileType(metadataDirectoryPath));
    // sort index file is created with dictionary size appended to it. So all the files
    // with a given column ID need to be listed
    CarbonFile[] listFiles = metadataDir.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile path) {
            if (path.getName().startsWith(columnSchema.getColumnUniqueId())) {
                return true;
            }
            return false;
        }
    });
    for (CarbonFile file : listFiles) {
        // still need to be deleted
        try {
            FileFactory.deleteFile(file.getCanonicalPath(), FileFactory.getFileType(file.getCanonicalPath()));
        } catch (IOException e) {
            LOGGER.error("Failed to delete dictionary or sortIndex file for column " + columnSchema.getColumnName() + "with column ID " + columnSchema.getColumnUniqueId());
        }
    }
    // remove dictionary cache
    removeDictionaryColumnFromCache(carbonTableIdentifier, storePath, columnSchema.getColumnUniqueId());
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) IOException(java.io.IOException)

Example 10 with CarbonFileFilter

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

the class FileFooterValidator method setUp.

@Before
public void setUp() throws Exception {
    if (setUpIsDone) {
        return;
    }
    CarbonHiveContext.sql("CREATE CUBE validatefooter DIMENSIONS (empno Integer, empname String," + " designation String," + " doj Timestamp, workgroupcategory Integer, workgroupcategoryname String, " + "deptno Integer, deptname String, projectcode Integer, projectjoindate Timestamp," + " projectenddate Timestamp) MEASURES (attendance Integer,utilization Integer," + "salary Integer) OPTIONS (PARTITIONER [PARTITION_COUNT=1])");
    CarbonHiveContext.sql("LOAD DATA fact from './src/test/resources/data.csv' INTO CUBE validatefooter " + "PARTITIONDATA(DELIMITER ',', QUOTECHAR '\"')");
    String storePath = CarbonProperties.getInstance().getProperty(CarbonCommonConstants.STORE_LOCATION);
    CarbonTableIdentifier tableIdentifier = new CarbonTableIdentifier(CarbonCommonConstants.DATABASE_DEFAULT_NAME, "validatefooter", "1");
    String segmentPath = CarbonStorePath.getCarbonTablePath(storePath, tableIdentifier).getCarbonDataDirectoryPath("0", "0");
    CarbonFile carbonFile = FileFactory.getCarbonFile(segmentPath, FileFactory.getFileType(segmentPath));
    CarbonFile[] list = carbonFile.listFiles(new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            if (file.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT)) {
                return true;
            }
            return false;
        }
    });
    for (CarbonFile file : list) {
        String fileLocation = file.getAbsolutePath();
        CarbonFile factFile = FileFactory.getCarbonFile(fileLocation, FileFactory.getFileType(fileLocation));
        long offset = factFile.getSize() - CarbonCommonConstants.LONG_SIZE_IN_BYTE;
        FileHolder fileHolder = FileFactory.getFileHolder(FileFactory.getFileType(fileLocation));
        offset = fileHolder.readLong(fileLocation, offset);
        CarbonFooterReader metaDataReader = new CarbonFooterReader(fileLocation, offset);
        fileFooter = metaDataReader.readFooter();
    }
    setUpIsDone = true;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonFileFilter(org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter) CarbonTableIdentifier(org.apache.carbondata.core.carbon.CarbonTableIdentifier) FileHolder(org.apache.carbondata.core.datastorage.store.FileHolder) CarbonFooterReader(org.apache.carbondata.core.reader.CarbonFooterReader) Before(org.junit.Before)

Aggregations

CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)17 CarbonFileFilter (org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter)17 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2 FileType (org.apache.carbondata.core.datastore.impl.FileFactory.FileType)2 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)2 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)2 CarbonTableIdentifier (org.apache.carbondata.core.carbon.CarbonTableIdentifier)1 FileHolder (org.apache.carbondata.core.datastorage.store.FileHolder)1 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)1 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)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