Skip to content

Commit

Permalink
Closes #137 - fixed get_partitioning_measures function
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Feb 15, 2024
1 parent 1546d77 commit 58af24c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
$$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
}
}



}

0 comments on commit 58af24c

Please sign in to comment.