use of org.apache.flink.streaming.api.functions.sink.filesystem.RecordWiseCompactingFileWriter in project flink by apache.
the class CompactService method compact.
@SuppressWarnings({ "rawtypes", "unchecked" })
private Iterable<FileSinkCommittable> compact(CompactorRequest request) throws Exception {
List<FileSinkCommittable> results = new ArrayList<>(request.getCommittableToPassthrough());
List<Path> compactingFiles = getCompactingPath(request);
if (compactingFiles.isEmpty()) {
return results;
}
Path targetPath = assembleCompactedFilePath(compactingFiles.get(0));
CompactingFileWriter compactingFileWriter = bucketWriter.openNewCompactingFile(compactingWriterType, request.getBucketId(), targetPath, System.currentTimeMillis());
if (compactingWriterType == Type.RECORD_WISE) {
((RecordWiseFileCompactor) fileCompactor).compact(compactingFiles, ((RecordWiseCompactingFileWriter) compactingFileWriter)::write);
} else if (compactingWriterType == CompactingFileWriter.Type.OUTPUT_STREAM) {
((OutputStreamBasedFileCompactor) fileCompactor).compact(compactingFiles, ((OutputStreamBasedCompactingFileWriter) compactingFileWriter).asOutputStream());
}
PendingFileRecoverable compactedPendingFile = compactingFileWriter.closeForCommit();
FileSinkCommittable compacted = new FileSinkCommittable(request.getBucketId(), compactedPendingFile);
results.add(compacted);
for (Path f : compactingFiles) {
// cleanup compacted files
results.add(new FileSinkCommittable(request.getBucketId(), f));
}
return results;
}
Aggregations