Skip to content

Commit

Permalink
finos#1167 remove check for missing column in fields map for SchemaMa…
Browse files Browse the repository at this point in the history
…pper validation
  • Loading branch information
junaidzm13 committed Feb 13, 2024
1 parent 86f73dd commit a1fc13d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object SchemaMapper {
Iterator(
() => hasUniqueColumnNames(fieldsMap.values.toList),
() => externalFieldsInMapConformsToExternalSchema(externalSchema, fieldsMap.keys),
() => internalFieldsInMapMatchTableColumns(internalColumns, fieldsMap.values)
() => internalFieldsInMapConformsToTableColumns(internalColumns, fieldsMap.values)
).map(_()).find(_.nonEmpty).flatten
}

Expand All @@ -42,12 +42,11 @@ object SchemaMapper {
.map(f => s"Field `$f` not found in external schema")
}

private def internalFieldsInMapMatchTableColumns(columns: Array[Column],
internalFields: Iterable[String]): ValidationError = {
private def internalFieldsInMapConformsToTableColumns(columns: Array[Column],
internalFields: Iterable[String]): ValidationError = {
internalFields
.find(columnName => columns.forall(_.name != columnName))
.map(columnName => s"Column `$columnName` not found in internal columns")
.orElse(Option.when(columns.length > internalFields.size)(s"More internal columns passed than mapped fields"))
}

final case class InvalidSchemaMapException(message: String) extends RuntimeException(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,7 @@ class SchemaMapperTest extends AnyFeatureSpec with Matchers {
exception.getMessage should include regex "[Cc]olumn `absent-col` not found"
}

Scenario("fails when a passed internal column is not present in mapped fields") {
val exception = intercept[InvalidSchemaMapException](
SchemaMapper(testExternalSchema, tableColumns.slice(0, 2), fieldsMap.slice(0, 1))
)
exception shouldBe a[RuntimeException]
exception.getMessage should include regex "[Mm]ore .* columns .* than mapped fields"
}

Scenario("fails when a external->internal map contains duplicated internal field") {
Scenario("fails when external->internal map contains duplicated internal field") {
val exception = intercept[InvalidSchemaMapException](SchemaMapper(
testExternalSchema,
Columns.fromNames("id".int(), "ric".string()),
Expand Down

0 comments on commit a1fc13d

Please sign in to comment.