@VisibleForTesting static Set<String> computeEmptyColumns(TableAnswerElement table) { return table.getMetadata().toColumnMap().keySet().stream() .filter(column -> table.getRowsList().stream().allMatch(row -> !row.hasNonNull(column))) .collect(ImmutableSet.toImmutableSet()); }
@VisibleForTesting static @Nonnull Map<String, MajorIssueConfig> computeMajorIssueConfigs(TableAnswerElement table) { Map<String, ImmutableList.Builder<MinorIssueConfig>> majorIssueConfigs = new HashMap<>(); // For every issue column of every row, extract the issue and use it to update the map table.getMetadata().getColumnMetadata().stream() .filter(c -> c.getSchema().equals(Schema.ISSUE)) .map(ColumnMetadata::getName) .flatMap( column -> table.getRowsList().stream() .filter(row -> row.hasNonNull(column)) .map(row -> row.getIssue(column))) .forEach( issue -> majorIssueConfigs .computeIfAbsent(issue.getType().getMajor(), m -> ImmutableList.builder()) .add( new MinorIssueConfig( issue.getType().getMinor(), issue.getSeverity(), issue.getUrl()))); return CommonUtil.toImmutableMap( majorIssueConfigs, Entry::getKey, // major issue type e -> new MajorIssueConfig(e.getKey(), e.getValue().build())); }
@Test public void fillInEmptyColumnsOnBuild() { Row row = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))) .build(); assertThat(row.getColumnNames(), contains("col")); assertThat(row.hasNonNull("col"), equalTo(false)); } }