Search in sources :

Example 1 with MajorTypeId

use of com.bakdata.conquery.models.events.MajorTypeId in project conquery by bakdata.

the class PreprocessedHeader method assertMatch.

/**
 * Verify that the supplied table matches the preprocessed' data in shape.
 */
public void assertMatch(Table table) {
    StringJoiner errors = new StringJoiner("\n");
    if (table.getColumns().length != getColumns().length) {
        errors.add(String.format("Length=`%d` does not match table Length=`%d`", getColumns().length, table.getColumns().length));
    }
    final Map<String, MajorTypeId> typesByName = Arrays.stream(getColumns()).collect(Collectors.toMap(PPColumn::getName, PPColumn::getType));
    for (int i = 0; i < Math.min(table.getColumns().length, getColumns().length); i++) {
        final Column column = table.getColumns()[i];
        if (!typesByName.containsKey(column.getName())) {
            errors.add(String.format("Column[%s] is missing in Import.", column.getName()));
        } else if (!typesByName.get(column.getName()).equals(column.getType())) {
            errors.add(String.format("Column[%s] Types do not match %s != %s", column.getName(), typesByName.get(column.getName()), column.getType()));
        }
    }
    if (errors.length() != 0) {
        log.error(errors.toString());
        throw new IllegalArgumentException(String.format("Headers[%s.%s] do not match Table[%s]. More Info in Logs.", getTable(), getName(), table.getId()));
    }
}
Also used : Column(com.bakdata.conquery.models.datasets.Column) StringJoiner(java.util.StringJoiner) MajorTypeId(com.bakdata.conquery.models.events.MajorTypeId)

Aggregations

Column (com.bakdata.conquery.models.datasets.Column)1 MajorTypeId (com.bakdata.conquery.models.events.MajorTypeId)1 StringJoiner (java.util.StringJoiner)1