Skip to content

Commit

Permalink
intersect instead of iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
salamonpavel committed Sep 9, 2024
1 parent 59d30f2 commit 809044a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions agent/src/main/scala/za/co/absa/atum/agent/AtumContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ class AtumContext private[agent] (
* @return the sub-partition context
*/
def subPartitionContext(subPartitions: AtumPartitions): AtumContext = {
val newPartitions = subPartitions.foldLeft(atumPartitions) { case (acc, (k, v)) =>
if (acc.contains(k)) {
throw PartitioningUpdateException(s"Partition key '$k' already exists. Updates are not allowed.")
} else {
acc + (k -> v)
}
val overlap = atumPartitions.keys.toSet.intersect(subPartitions.keys.toSet)
if (overlap.nonEmpty) {
throw PartitioningUpdateException(s"Partition keys '$overlap' already exist. Updates are not allowed.")
}
agent.getOrCreateAtumSubContext(newPartitions)(this)
agent.getOrCreateAtumSubContext(atumPartitions ++ subPartitions)(this)
}

private def takeMeasurements(df: DataFrame): Set[MeasurementDTO] = {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Dependencies.*
import Dependencies.Versions.spark3
import VersionAxes.*

ThisBuild / scalaVersion := Setup.scala213.asString // default version TODO
ThisBuild / scalaVersion := Setup.scala212.asString // default version TODO

ThisBuild / versionScheme := Some("early-semver")

Expand Down

0 comments on commit 809044a

Please sign in to comment.