Search in sources :

Example 26 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class UnsafeSingleThreadFinalSortFilesMerger method getSortedRecordFromFile.

/**
 * This method will be used to get the sorted record from file
 *
 * @return sorted record sorted record
 */
private IntermediateSortTempRow getSortedRecordFromFile() throws CarbonDataWriterException {
    IntermediateSortTempRow row = null;
    // poll the top object from heap
    // heap maintains binary tree which is based on heap condition that will
    // be based on comparator we are passing the heap
    // when will call poll it will always delete root of the tree and then
    // it does trickel down operation complexity is log(n)
    SortTempChunkHolder poll = this.recordHolderHeapLocal.peek();
    // get the row from chunk
    row = poll.getRow();
    // check if there no entry present
    if (!poll.hasNext()) {
        // if chunk is empty then close the stream
        poll.close();
        recordHolderHeapLocal.poll();
        // change the file counter
        --this.fileCounter;
        // return row
        return row;
    }
    // read new row
    try {
        poll.readRow();
    } catch (Exception e) {
        throw new CarbonDataWriterException(e);
    }
    // maintain heap
    this.recordHolderHeapLocal.siftTopDown();
    // return row
    return row;
}
Also used : IntermediateSortTempRow(org.apache.carbondata.processing.loading.row.IntermediateSortTempRow) SortTempChunkHolder(org.apache.carbondata.processing.loading.sort.unsafe.holder.SortTempChunkHolder) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) NoSuchElementException(java.util.NoSuchElementException)

Example 27 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class SecondaryIndexQueryResultProcessor method readAndLoadDataFromSortTempFiles.

/**
 * This method will read sort temp files, perform merge sort and add it to store for data loading
 */
private void readAndLoadDataFromSortTempFiles() throws SecondaryIndexException {
    Throwable throwable = null;
    try {
        Object[] previousRow = null;
        // comparator for grouping the similar data, means every record
        // should be unique in index table
        RowComparator comparator = new RowComparator(noDictionaryColMapping, SecondaryIndexUtil.getNoDictDataTypes(indexTable));
        intermediateFileMerger.finish();
        sortDataRows = null;
        finalMerger.startFinalMerge();
        while (finalMerger.hasNext()) {
            Object[] rowRead = finalMerger.next();
            if (null == previousRow) {
                previousRow = rowRead;
            } else {
                int compareResult = comparator.compare(previousRow, rowRead);
                if (0 == compareResult) {
                    // skip similar data rows
                    continue;
                } else {
                    previousRow = rowRead;
                }
            }
            CarbonRow row = new CarbonRow(rowRead);
            dataHandler.addDataToStore(row);
        }
        dataHandler.finish();
    } catch (CarbonDataWriterException e) {
        LOGGER.error(e);
        throw new SecondaryIndexException("Problem loading data while creating secondary index: ", e);
    } catch (CarbonSortKeyAndGroupByException e) {
        LOGGER.error(e);
        throw new SecondaryIndexException("Problem in merging intermediate files while creating secondary index: ", e);
    } catch (Throwable t) {
        LOGGER.error(t);
        throw new SecondaryIndexException("Problem while creating secondary index: ", t);
    } finally {
        if (null != dataHandler) {
            try {
                dataHandler.closeHandler();
            } catch (CarbonDataWriterException e) {
                LOGGER.error(e);
                throwable = e;
            }
        }
    }
    if (null != throwable) {
        throw new SecondaryIndexException("Problem closing data handler while creating secondary index: ", throwable);
    }
    dataHandler = null;
}
Also used : CarbonRow(org.apache.carbondata.core.datastore.row.CarbonRow) RowComparator(org.apache.spark.sql.secondaryindex.load.RowComparator) CarbonSortKeyAndGroupByException(org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException) SecondaryIndexException(org.apache.spark.sql.secondaryindex.exception.SecondaryIndexException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)

Example 28 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class CarbonUtil method copyCarbonDataFileToCarbonStorePath.

/**
 * This method will copy the given file to carbon store location
 *
 * @param localFilePath local file name with full path
 * @throws CarbonDataWriterException
 * @return the file size
 */
public static long copyCarbonDataFileToCarbonStorePath(String localFilePath, String carbonDataDirectoryPath, long fileSizeInBytes) throws CarbonDataWriterException {
    long copyStartTime = System.currentTimeMillis();
    LOGGER.info(String.format("Copying %s to %s, operation id %d", localFilePath, carbonDataDirectoryPath, copyStartTime));
    long targetSize = 0;
    try {
        CarbonFile localCarbonFile = FileFactory.getCarbonFile(localFilePath);
        long localFileSize = localCarbonFile.getSize();
        // the size of local carbon file must be greater than 0
        if (localFileSize == 0L) {
            LOGGER.error("The size of local carbon file: " + localFilePath + " is 0.");
            throw new CarbonDataWriterException("The size of local carbon file is 0.");
        }
        String carbonFilePath = carbonDataDirectoryPath + localFilePath.substring(localFilePath.lastIndexOf(File.separator));
        copyLocalFileToCarbonStore(carbonFilePath, localFilePath, CarbonCommonConstants.BYTEBUFFER_SIZE, getMaxOfBlockAndFileSize(fileSizeInBytes, localFileSize));
        CarbonFile targetCarbonFile = FileFactory.getCarbonFile(carbonFilePath);
        // the size of carbon file must be greater than 0
        // and the same as the size of local carbon file
        targetSize = targetCarbonFile.getSize();
        if (targetSize == 0L || targetSize != localFileSize) {
            LOGGER.error("The size of carbon file: " + carbonFilePath + " is 0 " + "or is not the same as the size of local carbon file: (" + "carbon file size=" + targetSize + ", local carbon file size=" + localFileSize + ")");
            throw new CarbonDataWriterException("The size of carbon file is 0 " + "or is not the same as the size of local carbon file.");
        }
    } catch (Exception e) {
        throw new CarbonDataWriterException("Problem while copying file from local store to carbon store", e);
    }
    LOGGER.info(String.format("Total copy time is %d ms, operation id %d", System.currentTimeMillis() - copyStartTime, copyStartTime));
    return targetSize;
}
Also used : CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) TException(org.apache.thrift.TException) IOException(java.io.IOException) InvalidConfigurationException(org.apache.carbondata.core.exception.InvalidConfigurationException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 29 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class CarbonFactDataWriterImplV3 method closeWriter.

/**
 * Method will be used to close the open file channel
 *
 * @throws CarbonDataWriterException
 */
public void closeWriter() throws CarbonDataWriterException {
    CarbonDataWriterException exception = null;
    try {
        commitCurrentFile(true);
        writeIndexFile();
    } catch (Exception e) {
        LOGGER.error("Problem while writing the index file", e);
        exception = new CarbonDataWriterException("Problem while writing the index file", e);
    } finally {
        try {
            closeExecutorService();
        } catch (CarbonDataWriterException e) {
            if (null == exception) {
                exception = e;
            }
        }
    }
    if (null != exception) {
        throw exception;
    }
}
Also used : CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) IOException(java.io.IOException)

Example 30 with CarbonDataWriterException

use of org.apache.carbondata.core.datastore.exception.CarbonDataWriterException in project carbondata by apache.

the class CarbonFactDataWriterImplV3 method writeFooterToFile.

@Override
protected void writeFooterToFile() throws CarbonDataWriterException {
    try {
        // get the current file position
        long footerOffset = currentOffsetInFile;
        // get thrift file footer instance
        FileFooter3 convertFileMeta = CarbonMetadataUtil.convertFileFooterVersion3(blockletMetadata, blockletIndex, thriftColumnSchemaList.size());
        convertFileMeta.setIs_sort(isSorted);
        String appName = CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_WRITTEN_BY_APPNAME);
        if (appName == null) {
            throw new CarbonDataWriterException("DataLoading failed as CARBON_WRITTEN_BY_APPNAME is null");
        }
        convertFileMeta.putToExtra_info(CarbonCommonConstants.CARBON_WRITTEN_BY_FOOTER_INFO, appName);
        convertFileMeta.putToExtra_info(CarbonCommonConstants.CARBON_WRITTEN_VERSION, CarbonVersionConstants.CARBONDATA_VERSION);
        // write the footer
        byte[] byteArray = CarbonUtil.getByteArray(convertFileMeta);
        ByteBuffer buffer = ByteBuffer.allocate(byteArray.length + CarbonCommonConstants.LONG_SIZE_IN_BYTE);
        buffer.put(byteArray);
        buffer.putLong(footerOffset);
        buffer.flip();
        currentOffsetInFile += fileChannel.write(buffer);
        // fill the carbon index details
        fillBlockIndexInfoDetails(convertFileMeta.getNum_rows(), carbonDataFileName, footerOffset, currentOffsetInFile);
    } catch (IOException e) {
        LOGGER.error("Problem while writing the carbon file", e);
        throw new CarbonDataWriterException("Problem while writing the carbon file: ", e);
    }
}
Also used : FileFooter3(org.apache.carbondata.format.FileFooter3) IOException(java.io.IOException) CarbonDataWriterException(org.apache.carbondata.core.datastore.exception.CarbonDataWriterException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

CarbonDataWriterException (org.apache.carbondata.core.datastore.exception.CarbonDataWriterException)33 IOException (java.io.IOException)17 CarbonSortKeyAndGroupByException (org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException)9 CarbonDataLoadingException (org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException)6 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5 CarbonRow (org.apache.carbondata.core.datastore.row.CarbonRow)5 ByteBuffer (java.nio.ByteBuffer)4 CarbonThreadFactory (org.apache.carbondata.core.util.CarbonThreadFactory)4 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)3 ExecutionException (java.util.concurrent.ExecutionException)3 CarbonIterator (org.apache.carbondata.common.CarbonIterator)3 CarbonFile (org.apache.carbondata.core.datastore.filesystem.CarbonFile)3 GenericDataType (org.apache.carbondata.processing.datatypes.GenericDataType)3 CarbonRowBatch (org.apache.carbondata.processing.loading.row.CarbonRowBatch)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 Future (java.util.concurrent.Future)2