Search in sources :

Example 1 with CarbonOutputIteratorWrapper

use of org.apache.carbondata.processing.loading.iterator.CarbonOutputIteratorWrapper in project carbondata by apache.

the class CarbonTableOutputFormat method getRecordWriter.

@Override
public RecordWriter<NullWritable, ObjectArrayWritable> getRecordWriter(TaskAttemptContext taskAttemptContext) throws IOException {
    final CarbonLoadModel loadModel = getLoadModel(taskAttemptContext.getConfiguration());
    loadModel.setTaskNo(taskAttemptContext.getConfiguration().get("carbon.outputformat.taskno", String.valueOf(System.nanoTime())));
    loadModel.setDataWritePath(taskAttemptContext.getConfiguration().get("carbon.outputformat.writepath"));
    final String[] tempStoreLocations = getTempStoreLocations(taskAttemptContext);
    final CarbonOutputIteratorWrapper iteratorWrapper = new CarbonOutputIteratorWrapper();
    final DataLoadExecutor dataLoadExecutor = new DataLoadExecutor();
    ExecutorService executorService = Executors.newFixedThreadPool(1, new CarbonThreadFactory("CarbonRecordWriter:" + loadModel.getTableName()));
    ;
    // It should be started in new thread as the underlying iterator uses blocking queue.
    Future future = executorService.submit(new Thread() {

        @Override
        public void run() {
            try {
                dataLoadExecutor.execute(loadModel, tempStoreLocations, new CarbonIterator[] { iteratorWrapper });
            } catch (Exception e) {
                dataLoadExecutor.close();
                // clean up the folders and files created locally for data load operation
                TableProcessingOperations.deleteLocalDataLoadFolderLocation(loadModel, false, false);
                throw new RuntimeException(e);
            }
        }
    });
    return new CarbonRecordWriter(iteratorWrapper, dataLoadExecutor, loadModel, future, executorService);
}
Also used : IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CarbonIterator(org.apache.carbondata.common.CarbonIterator) CarbonOutputIteratorWrapper(org.apache.carbondata.processing.loading.iterator.CarbonOutputIteratorWrapper) CarbonLoadModel(org.apache.carbondata.processing.loading.model.CarbonLoadModel) ExecutorService(java.util.concurrent.ExecutorService) CarbonThreadFactory(org.apache.carbondata.core.util.CarbonThreadFactory) Future(java.util.concurrent.Future) DataLoadExecutor(org.apache.carbondata.processing.loading.DataLoadExecutor)

Aggregations

IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 CarbonIterator (org.apache.carbondata.common.CarbonIterator)1 CarbonThreadFactory (org.apache.carbondata.core.util.CarbonThreadFactory)1 DataLoadExecutor (org.apache.carbondata.processing.loading.DataLoadExecutor)1 CarbonOutputIteratorWrapper (org.apache.carbondata.processing.loading.iterator.CarbonOutputIteratorWrapper)1 CarbonLoadModel (org.apache.carbondata.processing.loading.model.CarbonLoadModel)1