-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge/merging release 2.26.X into develop ver3 (#1997)
- Loading branch information
1 parent
10213a2
commit d9a72fc
Showing
45 changed files
with
581 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,8 +55,6 @@ build.log | |
# syntax: regexp | ||
# ^\.pc/ | ||
|
||
build.log | ||
|
||
.cache* | ||
dependency-reduced-pom.xml | ||
|
||
|
46 changes: 46 additions & 0 deletions
46
data-model/src/main/scala/za/co/absa/enceladus/model/ConformedSchema.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2018 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.enceladus.model | ||
|
||
import org.apache.spark.sql.types.StructField | ||
import za.co.absa.enceladus.model.conformanceRule._ | ||
|
||
case class ConformedSchema(schema: List[StructField], dataset: Dataset) { | ||
def hasField(field: String): Boolean = { | ||
if (schema.exists(_.name == field)) true else { | ||
val ss = dataset.conformance.find { | ||
case MappingConformanceRule(_, _, _, _, _, _, outputColumn, additionalColumns, _, _, _) => | ||
outputColumn == field || additionalColumns.getOrElse(Map()).contains(field) | ||
case SingleColumnConformanceRule(_, _, outputColumn, _, inputColumnAlias) => | ||
outputColumn == field || field == outputColumn + "." + inputColumnAlias | ||
case DropConformanceRule(_, _, _) => false | ||
case c: ConformanceRule => c.outputColumn == field | ||
} | ||
|
||
ss match { | ||
case None => false | ||
case Some(matchedRule: ConformanceRule) => | ||
val maybeRule = dataset.conformance.find { | ||
case DropConformanceRule(_, _, outputCol) => outputCol == matchedRule.outputColumn | ||
case _ => false | ||
} | ||
maybeRule.isEmpty | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
data-model/src/test/scala/za/co/absa/enceladus/model/ConformedSchemaTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2018 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.enceladus.model | ||
|
||
import org.apache.spark.sql.types.{StringType, StructField} | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import za.co.absa.enceladus.model.conformanceRule.{DropConformanceRule, LiteralConformanceRule, MappingConformanceRule, SingleColumnConformanceRule} | ||
|
||
class ConformedSchemaTest extends AnyFunSuite{ | ||
private val conformanceRule1 = LiteralConformanceRule( | ||
order = 0, | ||
controlCheckpoint = true, | ||
outputColumn = "something", | ||
value = "1.01" | ||
) | ||
|
||
private val conformanceRule1d = LiteralConformanceRule( | ||
order = 0, | ||
controlCheckpoint = true, | ||
outputColumn = "fieldToDelete", | ||
value = "1.01" | ||
) | ||
|
||
private val conformanceRule2 = DropConformanceRule(order = 0, | ||
controlCheckpoint = true, | ||
outputColumn = "fieldToDelete") | ||
|
||
private val conformanceRule3 = MappingConformanceRule(order = 0, | ||
controlCheckpoint = true, | ||
outputColumn = "something3",additionalColumns = Some(Map("newCol" -> "mappedCol")), | ||
mappingTable = "",mappingTableVersion = 1, | ||
attributeMappings = Map(),targetAttribute = "col") | ||
|
||
private val conformanceRule4 = SingleColumnConformanceRule( | ||
order = 0, | ||
outputColumn = "singleCol",inputColumn = "as", | ||
inputColumnAlias = "subCol", controlCheckpoint = false) | ||
|
||
private val dataset = Dataset(name = "Test DS", | ||
version = 1, | ||
hdfsPath = "newPath", | ||
hdfsPublishPath = "newPublishPath", | ||
schemaName = "newSchema", | ||
schemaVersion = 1, | ||
conformance = List(conformanceRule1, conformanceRule1d, conformanceRule2, conformanceRule3, conformanceRule4), | ||
properties = Some(Map( | ||
"property1" -> "value1", | ||
"property2.sub" -> "value2" | ||
) | ||
)) | ||
|
||
val schemaFields = List(StructField("stdField",StringType)) | ||
|
||
test("conformed schema") { | ||
val conformedSchema = ConformedSchema(schemaFields, dataset) | ||
assertResult(conformedSchema.hasField("stdField"))(true) | ||
assertResult(conformedSchema.hasField("fieldToDelete"))(false) | ||
assertResult(conformedSchema.hasField("something"))(true) | ||
assertResult(conformedSchema.hasField("newCol"))(true) | ||
assertResult(conformedSchema.hasField("newCol1"))(false) | ||
assertResult(conformedSchema.hasField("mappedColCol1"))(false) | ||
assertResult(conformedSchema.hasField("something3"))(true) | ||
assertResult(conformedSchema.hasField("col"))(false) | ||
assertResult(conformedSchema.hasField("singleCol"))(true) | ||
assertResult(conformedSchema.hasField("singleCol.subCol"))(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.