Search in sources :

Example 1 with HoodieAppendException

use of org.apache.hudi.exception.HoodieAppendException in project hudi by apache.

the class HoodieAppendHandle method appendDataAndDeleteBlocks.

protected void appendDataAndDeleteBlocks(Map<HeaderMetadataType, String> header) {
    try {
        header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, instantTime);
        header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, writeSchemaWithMetaFields.toString());
        List<HoodieLogBlock> blocks = new ArrayList<>(2);
        if (recordList.size() > 0) {
            String keyField = config.populateMetaFields() ? HoodieRecord.RECORD_KEY_METADATA_FIELD : hoodieTable.getMetaClient().getTableConfig().getRecordKeyFieldProp();
            blocks.add(getBlock(config, pickLogDataBlockFormat(), recordList, header, keyField));
        }
        if (keysToDelete.size() > 0) {
            blocks.add(new HoodieDeleteBlock(keysToDelete.toArray(new HoodieKey[keysToDelete.size()]), header));
        }
        if (blocks.size() > 0) {
            AppendResult appendResult = writer.appendBlocks(blocks);
            processAppendResult(appendResult, recordList);
            recordList.clear();
            keysToDelete.clear();
        }
    } catch (Exception e) {
        throw new HoodieAppendException("Failed while appending records to " + writer.getLogFile().getPath(), e);
    }
}
Also used : HoodieLogBlock(org.apache.hudi.common.table.log.block.HoodieLogBlock) HoodieDeleteBlock(org.apache.hudi.common.table.log.block.HoodieDeleteBlock) ArrayList(java.util.ArrayList) HoodieAppendException(org.apache.hudi.exception.HoodieAppendException) AppendResult(org.apache.hudi.common.table.log.AppendResult) HoodieException(org.apache.hudi.exception.HoodieException) HoodieUpsertException(org.apache.hudi.exception.HoodieUpsertException) HoodieAppendException(org.apache.hudi.exception.HoodieAppendException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AppendResult (org.apache.hudi.common.table.log.AppendResult)1 HoodieDeleteBlock (org.apache.hudi.common.table.log.block.HoodieDeleteBlock)1 HoodieLogBlock (org.apache.hudi.common.table.log.block.HoodieLogBlock)1 HoodieAppendException (org.apache.hudi.exception.HoodieAppendException)1 HoodieException (org.apache.hudi.exception.HoodieException)1 HoodieUpsertException (org.apache.hudi.exception.HoodieUpsertException)1