Skip to content

Commit

Permalink
feat: allow features to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Apr 27, 2023
1 parent 88acb65 commit a5bf1ea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class DatabaseSchema(
val instanceName: String,
val metadata: List<DatabaseMetadata>,
val primaryKey: String,
val features: List<DatabaseFeature>,
val features: List<DatabaseFeature>?,
)

data class DatabaseMetadata(val name: String, val type: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ data class SequenceFilterFields(val fields: Map<FieldName, SequenceFilterFieldTy
companion object {
private val nucleotideMutationsField = Pair("nucleotideMutations", SequenceFilterFieldType.MutationsList)

fun fromDatabaseConfig(databaseConfig: DatabaseConfig) = SequenceFilterFields(
fields = databaseConfig.schema.metadata
fun fromDatabaseConfig(databaseConfig: DatabaseConfig): SequenceFilterFields {
val metadataFields = databaseConfig.schema.metadata
.map(::mapToSequenceFilterFields)
.flatten()
.toMap() +
.toMap()
val staticFields = listOf(nucleotideMutationsField)

val featuresFields = if (databaseConfig.schema.features.isNullOrEmpty()) {
emptyMap<FieldName, SequenceFilterFieldType>()
} else {
databaseConfig.schema.features
.map(::mapToSequenceFilterFieldsFromFeatures)
.flatten()
.toMap() +
nucleotideMutationsField,
)
.toMap()
}

return SequenceFilterFields(fields = metadataFields + staticFields + featuresFields)
}
}
}

Expand All @@ -35,7 +42,7 @@ private fun mapToSequenceFilterFields(databaseMetadata: DatabaseMetadata) = when
}

private fun mapToSequenceFilterFieldsFromFeatures(databaseFeature: DatabaseFeature) = when (databaseFeature.name) {
"sarsCoV2VariantQuery" -> listOf(databaseFeature.name to SequenceFilterFieldType.VariantQuery)
"sarsCoV2VariantQuery" -> listOf("variantQuery" to SequenceFilterFieldType.VariantQuery)
else -> throw IllegalArgumentException(
"Unknown feature '${databaseFeature.name}'",
)
Expand Down
2 changes: 1 addition & 1 deletion lapis2/src/test/resources/config/testDatabaseConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ schema:
- name: pangoLineage
type: pango_lineage
features:
- feature: sarsCoV2VariantQuery
- name: sarsCoV2VariantQuery
primaryKey: gisaid_epi_isl
2 changes: 2 additions & 0 deletions siloLapisTests/testDatabaseConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ schema:
type: string
- name: pangoLineage
type: pango_lineage
features:
- name: sarsCoV2VariantQuery
primaryKey: gisaid_epi_isl

0 comments on commit a5bf1ea

Please sign in to comment.