Skip to content

Commit

Permalink
Closes #120 - Cleaning unwanted code lines
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Apr 26, 2024
1 parent 7e30a62 commit d1b6f7c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ class PartitioningControllerImpl(partitioningService: PartitioningService)
for {
_ <- partitioningService.createPartitioningIfNotExists(partitioningSubmitDTO)
.mapError(serviceError => InternalServerErrorResponse(serviceError.message))
// _ <- ZIO.logInfo(s"Partitioning ${partitioningSubmitDTO} created")
measures <- partitioningService.getPartitioningMeasures(partitioningSubmitDTO.partitioning)
.mapError {
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message)
}
// _ <- ZIO.logInfo(s"Measures for partitioning ${partitioningSubmitDTO} retrievedM")
additionalData <- partitioningService.getPartitioningAdditionalData(partitioningSubmitDTO.partitioning)
.mapError {
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message)
}
// _ <- ZIO.logInfo(s"Additional data for partitioning ${partitioningSubmitDTO} retrievedA")
} yield AtumContextDTO(partitioningSubmitDTO.partitioning, measures.toSet, additionalData)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: Doobie
extends DoobieMultipleResultFunction[PartitioningDTO, (String, Option[String]), Task]
{
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString

override val fieldsToSelect: Seq[String] = Seq("ad_name", "ad_value")

override def sql(values: PartitioningDTO)(implicit read: Read[(String, Option[String])]): Fragment = {
val partitioning: PartitioningForDB = PartitioningForDB.fromSeqPartitionDTO(values)
val partitioningJsonString = Json.toJson(partitioning).toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ import za.co.absa.atum.server.api.database.DoobieImplicits.Sequence.get
class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task])
extends DoobieMultipleResultFunction[PartitioningDTO, MeasureDTO, Task]
{
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString

override val fieldsToSelect: Seq[String] = Seq("measure_name", "measured_columns")

override def sql(values: PartitioningDTO)(implicit read: Read[MeasureDTO]): Fragment = {
val partitioning = PartitioningForDB.fromSeqPartitionDTO(values)
val partitioningJsonString = Json.toJson(partitioning).toString
// println(partitioning)
println(partitioningJsonString)
val sqlResults = sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}(

sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}(
${
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString
partitioningJsonString
}
) ${Fragment.const(alias)};"""
println(sqlResults)
sqlResults
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package za.co.absa.atum.server.api.repository

import za.co.absa.atum.model.dto.{AdditionalDataDTO, AdditionalDataSubmitDTO, MeasureDTO, PartitioningDTO, PartitioningSubmitDTO}
import za.co.absa.atum.model.dto.{
AdditionalDataDTO, AdditionalDataSubmitDTO,
MeasureDTO, PartitioningDTO, PartitioningSubmitDTO
}
import za.co.absa.atum.server.api.database.runs.functions.{
CreateOrUpdateAdditionalData,
CreatePartitioningIfNotExists,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ class GetPartitioningAdditionalDataSpec extends ConfigProviderSpec {
override def spec: Spec[TestEnvironment with Scope, Any] = {

suite("GetPartitioningAdditionalDataSpec")(
test("Returns expected sequence of (String, Option[String])") {
test("Returns expected left results for a partitioing that doesn't exist") {
val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2"))
for {
getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData]
result <- getPartitioningAdditionalData(partitioningDTO)
} yield assertTrue(result.nonEmpty && result.isInstanceOf[Seq[(String, Option[String])]])
result <- getPartitioningAdditionalData(partitioningDTO).either
} yield assertTrue (result.isLeft)
},
test("Returns expected sequence of Additional data with provided partitioning") {
val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("string1", "string1"), PartitionDTO("string2", "string2"))
for {
getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData]
result <- getPartitioningAdditionalData(partitioningDTO).either
} yield assertTrue(result.isInstanceOf[Right[_, _]])
}
).provide(
GetPartitioningAdditionalData.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GetPartitioningMeasuresSpec extends ConfigProviderSpec {
override def spec: Spec[TestEnvironment with Scope, Any] = {

suite("GetPartitioningMeasuresSpec")(
test("Returns expected sequence of Measures") {
test("Returns expected Left for non-existing partitioning") {
val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2"))

for {
Expand All @@ -45,10 +45,7 @@ class GetPartitioningMeasuresSpec extends ConfigProviderSpec {
for {
getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures]
result <- getPartitioningMeasures(partitioningDTO).either
} yield assertTrue{
println("Returned results: " + result)
result.isInstanceOf[Right[_, _]]
}
} yield assertTrue (result.isInstanceOf[Right[_, _]])

}
).provide(
Expand Down

0 comments on commit d1b6f7c

Please sign in to comment.