Skip to content

Commit

Permalink
Merge pull request #10 from atd/feature/resolve-preloadings-on-mappings
Browse files Browse the repository at this point in the history
Resolve preloadings in mappings
  • Loading branch information
margon8 authored Jul 31, 2023
2 parents fd4e941 + 4609019 commit aeaad64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ class ConfigReaderService(implicit val region: Regions) {

private def prepareConfig(params: Map[String, String]) = {

val preloadedConfig = preloadConfig()

params
.filter { kv =>
kv._1.startsWith("dp.")
}.map { kv =>
System.setProperty(kv._1, kv._2)
val value = if (preloadedConfig.contains(kv._2)) {
preloadedConfig(kv._2)
} else {
kv._2
}
System.setProperty(kv._1, value)
}

preloadConfig()
preloadedConfig
.map { kv =>
System.setProperty(kv._1, kv._2)
}
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/run_map.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
path = ${?raw_bucket}"/tmp"
pathy = ${dp.raw_bucket}/tmp
time = ${dp.time}

2 changes: 1 addition & 1 deletion src/test/resources/run_variable.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
path = ${?raw_bucket}"/tmp"

time = ${df.now}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.metabolic.data.mapper.domain.ops.mapping.TupletIntervalMapping
import com.metabolic.data.mapper.domain.ops.source.{DedupeSourceOp, FilterSourceOp, SQLOrder, SelectExpressionSourceOp}
import org.scalatest.funsuite.AnyFunSuite

import scala.util.matching.Regex

class ConfigReaderServiceTest extends AnyFunSuite with RegionedTest {

val personHOCON =
Expand Down Expand Up @@ -145,11 +147,20 @@ class ConfigReaderServiceTest extends AnyFunSuite with RegionedTest {

}

test("ConfigReaderService resolves a preload ") {

val overrideConfig = new ConfigReaderService().getConfig("src/test/resources/run_variable.conf")
val datePattern: String = """\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}"""

assert(overrideConfig.getString("time").matches(datePattern))
}

test("ConfigReaderService resolves a variable in map ") {

val args: Map[String, String] = Map(
"dp.region" -> "eu-west-4",
"dp.raw_bucket" -> "s3://factorial-dl-rawy"
"dp.raw_bucket" -> "s3://factorial-dl-rawy",
"dp.time" -> "2021-01-01T00:00:00"
)

val overrideConfig = new ConfigReaderService().getConfig("src/test/resources/run_map.conf", args)
Expand All @@ -158,6 +169,20 @@ class ConfigReaderServiceTest extends AnyFunSuite with RegionedTest {

}

test("ConfigReaderService resolves a preload in a map") {

val args: Map[String, String] = Map(
"dp.region" -> "eu-west-4",
"dp.raw_bucket" -> "s3://factorial-dl-rawy",
"dp.time" -> "df.now"
)

val overrideConfig = new ConfigReaderService().getConfig("src/test/resources/run_map.conf", args)
val datePattern: String = """\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}"""

assert(overrideConfig.getString("time").matches(datePattern))
}

test("ConfigReaderService resolves mappings ") {

val config = new ConfigReaderService()
Expand Down Expand Up @@ -254,4 +279,4 @@ class ConfigReaderServiceTest extends AnyFunSuite with RegionedTest {
}


}
}

0 comments on commit aeaad64

Please sign in to comment.