@Override public CategorizationResult reduce(final Collection<? extends CategorizationResult> results) { final RowAnnotationFactory annotationFactory = null; final Map<String, RowAnnotation> reducedCategories = new LinkedHashMap<>(); for (final CategorizationResult result : results) { final Collection<String> categoryNames = result.getCategoryNames(); for (final String categoryName : categoryNames) { final RowAnnotation partialAnnotation = result.getCategoryRowAnnotation(categoryName); final RowAnnotation reducedAnnotation = reducedCategories.get(categoryName); if (reducedAnnotation == null) { // adopt the annotation from the partial result final RowAnnotation annotation = _rowAnnotationFactory.createAnnotation(); _rowAnnotationFactory.transferAnnotations(partialAnnotation, annotation); reducedCategories.put(categoryName, annotation); } else { // add records to the existing annotation _rowAnnotationFactory.transferAnnotations(partialAnnotation, reducedAnnotation); } } } return new CategorizationResult(annotationFactory, reducedCategories); }
private void reduce(final RowAnnotation annotation, final AnnotatedRowsResult annotatedRowsResult) { if (annotatedRowsResult == null) { return; } final int rowCount = annotatedRowsResult.getAnnotatedRowCount(); if (rowCount == 0) { return; } final List<InputRow> rows = annotatedRowsResult.getSampleRows(); if (rows.size() == rowCount) { for (final InputRow row : rows) { _rowAnnotationFactory.annotate(row, annotation); } } else { _rowAnnotationFactory.transferAnnotations(annotatedRowsResult.getAnnotation(), annotation); } }
@Override public CompletenessAnalyzerResult reduce(final Collection<? extends CompletenessAnalyzerResult> results) { final CompletenessAnalyzerResult firstResult = results.iterator().next(); final RowAnnotation annotation = _rowAnnotationFactory.createAnnotation(); final InputColumn<?>[] highlightedColumns = firstResult.getHighlightedColumns(); int totalRowCount = 0; for (final CompletenessAnalyzerResult result : results) { final List<InputRow> sampleRows = result.getSampleRows(); final int invalidRowCount = result.getInvalidRowCount(); if (invalidRowCount == sampleRows.size()) { // if the rows are included for preview/sampling - then // re-annotate them in the master result for (final InputRow sampleRow : sampleRows) { _rowAnnotationFactory.annotate(sampleRow, annotation); } } else { // else we just transfer annotation counts _rowAnnotationFactory.transferAnnotations(result.getAnnotation(), annotation); } totalRowCount += result.getTotalRowCount(); } return new CompletenessAnalyzerResult(totalRowCount, annotation, _rowAnnotationFactory, highlightedColumns); }