From 58af24cd5e0bd8e2865e3448b5f521555704649e Mon Sep 17 00:00:00 2001 From: AB019TC Date: Thu, 15 Feb 2024 14:38:52 +0200 Subject: [PATCH] Closes #137 - fixed get_partitioning_measures function --- ...=> V1.5.11__get_partitioning_measures.sql} | 18 ++++++++----- ...es.scala => GetPartitioningMeasures.scala} | 26 ++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) rename database/src/main/postgres/runs/{V1.5.11_get_partitioning_measures.sql => V1.5.11__get_partitioning_measures.sql} (79%) rename database/src/test/scala/za/co/absa/atum/database/runs/{getPartitioningMeasures.scala => GetPartitioningMeasures.scala} (64%) diff --git a/database/src/main/postgres/runs/V1.5.11_get_partitioning_measures.sql b/database/src/main/postgres/runs/V1.5.11__get_partitioning_measures.sql similarity index 79% rename from database/src/main/postgres/runs/V1.5.11_get_partitioning_measures.sql rename to database/src/main/postgres/runs/V1.5.11__get_partitioning_measures.sql index 0e3158b6e..b5ca49c89 100644 --- a/database/src/main/postgres/runs/V1.5.11_get_partitioning_measures.sql +++ b/database/src/main/postgres/runs/V1.5.11__get_partitioning_measures.sql @@ -34,15 +34,19 @@ $$ ------------------------------------------------------------------------------- DECLARE -key text; + _fk_partitioning BIGINT; BEGIN - FOR key IN SELECT jsonb_object_keys(i_partitioning) - LOOP - measure_name := key; - measure_column := ARRAY(SELECT jsonb_array_elements_text(i_partitioning ->> key)); - RETURN NEXT; - END LOOP; + _fk_partitioning = runs._get_id_partitioning(i_partitioning); + IF _fk_partitioning IS NULL THEN + measure_name := 'Partitioning not found'; + measure_column := '{}'; + RETURN; + END IF; + + SELECT measure_name, measure_column + FROM runs.partitioning_measures + WHERE fk_partitioning = _fk_partitioning; RETURN; END; $$ diff --git a/database/src/test/scala/za/co/absa/atum/database/runs/getPartitioningMeasures.scala b/database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningMeasures.scala similarity index 64% rename from database/src/test/scala/za/co/absa/atum/database/runs/getPartitioningMeasures.scala rename to database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningMeasures.scala index 39890edc3..103d07bcc 100644 --- a/database/src/test/scala/za/co/absa/atum/database/runs/getPartitioningMeasures.scala +++ b/database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningMeasures.scala @@ -19,17 +19,22 @@ package za.co.absa.atum.database.runs import za.co.absa.balta.DBTestSuite import za.co.absa.balta.classes.JsonBString -import scala.Byte.MaxValue -class getPartitioningMeasures extends DBTestSuite{ +class GetPartitioningMeasures extends DBTestSuite{ private val fncGetPartitioningMeasures = "runs.get_partitioning_measures" private val partitioning = JsonBString( """ |{ - | "measure1": ["column1", "column2"], - | "measure2": ["column3", "column4"] + | "version": 1, + | "keys": ["key1", "key3", "key2", "key4"], + | "values": { + | "key1": "valueX", + | "key2": "valueY", + | "key3": "valueZ", + | "key4": "valueA" + | } |} |""".stripMargin ) @@ -38,18 +43,9 @@ class getPartitioningMeasures extends DBTestSuite{ function(fncGetPartitioningMeasures) .setParam("i_partitioning", partitioning) .execute { queryResult => - assert(queryResult.hasNext) - val row = queryResult.next() - assert(row.getArray("measure_column").asInstanceOf[Array[String]].sameElements(Array("column1", "column2"))) - - assert(queryResult.hasNext) - val row2 = queryResult.next() - assert(row2.getArray("measure_column").asInstanceOf[Array[String]].sameElements(Array("column3", "column4"))) - - assert(!queryResult.hasNext) + print(queryResult) + queryResult.foreach(println) } } - - }