diff --git a/include/silo/storage/database_partition.h b/include/silo/storage/database_partition.h index fad07534c..b04dcc1ef 100644 --- a/include/silo/storage/database_partition.h +++ b/include/silo/storage/database_partition.h @@ -80,6 +80,12 @@ class DatabasePartition { void validateMetadataColumns() const; + template + void validateColumnsHaveSize( + const std::map& columnsOfTheType, + const std::string& columnType + ) const; + public: explicit DatabasePartition(std::vector chunks); diff --git a/src/silo/storage/database_partition.cpp b/src/silo/storage/database_partition.cpp index fb8bb9031..e1ed20b07 100644 --- a/src/silo/storage/database_partition.cpp +++ b/src/silo/storage/database_partition.cpp @@ -93,74 +93,33 @@ void DatabasePartition::validateAminoAcidSequences() const { } } -void DatabasePartition::validateMetadataColumns() const { - const size_t partition_size = sequence_count; - - for (const auto& col : columns.aa_insertion_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "aa_insertion_column " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.pango_lineage_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "pango_lineage_column " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.nuc_insertion_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "nuc_insertion_column " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.date_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "date_column " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.bool_columns) { - if (col.second.getValues().size() != partition_size) { +template +void DatabasePartition::validateColumnsHaveSize( + const std::map& columnsOfTheType, + const std::string& columnType +) const { + for (const auto& column : columnsOfTheType) { + if (column.second.getValues().size() != sequence_count) { throw preprocessing::PreprocessingException( - "bool_columns " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.int_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "int_columns " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.indexed_string_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "indexed_string_columns " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.string_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "string_columns " + col.first + " has invalid size." - ); - } - } - for (const auto& col : columns.float_columns) { - if (col.second.getValues().size() != partition_size) { - throw preprocessing::PreprocessingException( - "float_columns " + col.first + " has invalid size." + columnType + " " + column.first + " has invalid size " + + std::to_string(column.second.getValues().size()) ); } } } +void DatabasePartition::validateMetadataColumns() const { + validateColumnsHaveSize(columns.aa_insertion_columns, "aa_insertion_column"); + validateColumnsHaveSize(columns.pango_lineage_columns, "pango_lineage_column"); + validateColumnsHaveSize(columns.nuc_insertion_columns, "nuc_insertion_column"); + validateColumnsHaveSize(columns.date_columns, "date_column"); + validateColumnsHaveSize(columns.bool_columns, "bool_columns"); + validateColumnsHaveSize(columns.int_columns, "int_columns"); + validateColumnsHaveSize(columns.indexed_string_columns, "indexed_string_columns"); + validateColumnsHaveSize(columns.string_columns, "string_columns"); + validateColumnsHaveSize(columns.float_columns, "float_columns"); +} + const std::vector& DatabasePartition::getChunks() const { return chunks; }