From baf89a26727bf0b25e7e9cec00c576fccf0b7c94 Mon Sep 17 00:00:00 2001 From: AB019TC Date: Thu, 4 Apr 2024 09:15:24 +0200 Subject: [PATCH] Fixes #120 - Adding implicit conversion --- .../functions/GetPartitioningAdditionalData.scala | 12 ++++++++---- .../runs/functions/GetPartitioningMeasures.scala | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala index 59e2e5df6..1ccbca62a 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala @@ -29,20 +29,24 @@ import za.co.absa.fadb.doobie.DoobieFunction.DoobieMultipleResultFunction import za.co.absa.fadb.doobie.DoobieEngine import zio.interop.catz.asyncInstance import zio.{Task, URLayer, ZIO, ZLayer} +import doobie._ +import doobie.postgres.implicits._ class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) extends DoobieMultipleResultFunction[PartitioningSubmitDTO, AdditionalDataDTO, Task] { + implicit val getMapWithOptionStringValues: Get[Map[String, Option[String]]] = Get[Map[String, String]] + .tmap(map => map.map { case (k, v) => k -> Option(v) }) - override def sql(values: PartitioningSubmitDTO)(implicit read: Read[AdditionalDataDTO]): Fragment = { + override def sql(values: PartitioningSubmitDTO)(implicit read: Read[AdditionalDataDTO]): Fragment = { val partitioning = PartitioningForDB.fromSeqPartitionDTO(values.partitioning) val partitioningJsonString = Json.toJson(partitioning).toString sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( ${ - import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString - partitioningJsonString - } + import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString + partitioningJsonString + } ) ${Fragment.const(alias)};""" } diff --git a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala index 0fe290f1f..658198376 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala @@ -29,10 +29,14 @@ import za.co.absa.atum.server.api.database.PostgresDatabaseProvider import za.co.absa.atum.server.api.database.runs.Runs import zio._ import zio.interop.catz._ +import doobie._ +import doobie.postgres.implicits._ class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) extends DoobieMultipleResultFunction[PartitioningSubmitDTO, MeasureDTO, Task] { + implicit val getMapWithOptionStringValues: Get[Map[String, Option[String]]] = Get[Map[String, String]] + .tmap(map => map.map { case (k, v) => k -> Option(v) }) override def sql(values: PartitioningSubmitDTO)(implicit read: Read[MeasureDTO]): Fragment = { val partitioning = PartitioningForDB.fromSeqPartitionDTO(values.partitioning)