-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get partitioning measures: 229 (#249)
* Defining and implementing PL/PG function * Defining measure dto * Removing measure ID * defining get class to call db-function * Implement db call class * removing unused import * adding integration tests * restoring db-function * Adding test and fixing the build * Adding tests layer and updating sql function * Implementing service functionality * Implementing Controller functionality * fixing return type * fixing merge conflicts * Adding the endpoint * Adding repository unit test * Adding service unit test * Fixing merge conflicts * Fixing fileName conflicts * removing unused file * Changing file name * fixing file format * Removing outdated tests * Fixing the function and the test cases * Restoring files * implementing endpoint test-cases * Fixing endpoint tests * Addressing GitHub comments * Update database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningMeasuresByIdV2IntegrationTests.scala Co-authored-by: David Benedeki <[email protected]> * Update database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningMeasuresByIdV2IntegrationTests.scala Co-authored-by: David Benedeki <[email protected]> --------- Co-authored-by: David Benedeki <[email protected]>
- Loading branch information
Showing
16 changed files
with
450 additions
and
7 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
database/src/main/postgres/runs/V1.9.5__get_partitioning_measures_by_id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
-- Function: runs.get_partitioning_measures_by_id(Long) | ||
CREATE OR REPLACE FUNCTION runs.get_partitioning_measures_by_id( | ||
IN i_partitioning_id BIGINT, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT measure_name TEXT, | ||
OUT measured_columns TEXT[] | ||
) RETURNS SETOF record AS | ||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.get_partitioning_measures_by_id(1) | ||
-- Returns measures for the given partitioning id | ||
-- | ||
-- Parameters: | ||
-- i_partitioning_id - partitioning id we are asking the measures for | ||
-- | ||
-- Returns: | ||
-- status - Status code | ||
-- status_text - Status message | ||
-- measure_name - Name of the measure | ||
-- measured_columns - Array of columns associated with the measure | ||
-- | ||
-- Status codes: | ||
-- 11 - OK | ||
-- 41 - Partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
BEGIN | ||
|
||
PERFORM 1 FROM runs.partitionings WHERE id_partitioning = i_partitioning_id; | ||
|
||
IF NOT FOUND THEN | ||
status := 41; | ||
status_text := 'Partitioning not found'; | ||
RETURN NEXT; | ||
RETURN; | ||
END IF; | ||
|
||
RETURN QUERY | ||
SELECT 11, 'OK', MD.measure_name, MD.measured_columns | ||
FROM runs.measure_definitions AS MD | ||
WHERE MD.fk_partitioning = i_partitioning_id; | ||
|
||
RETURN; | ||
|
||
END; | ||
$$ | ||
LANGUAGE plpgsql volatile SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.get_partitioning_measures_by_id(BIGINT) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.get_partitioning_measures_by_id(BIGINT) TO atum_user; |
95 changes: 95 additions & 0 deletions
95
...t/scala/za/co/absa/atum/database/runs/GetPartitioningMeasuresByIdV2IntegrationTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package za.co.absa.atum.database.runs | ||
|
||
import za.co.absa.balta.DBTestSuite | ||
import za.co.absa.balta.classes.JsonBString | ||
import za.co.absa.balta.classes.setter.CustomDBType | ||
|
||
class GetPartitioningMeasuresByIdV2IntegrationTests extends DBTestSuite { | ||
private val fncGetPartitioningMeasuresById = "runs.get_partitioning_measures_by_id" | ||
|
||
private val partitioning: JsonBString = JsonBString( | ||
""" | ||
|{ | ||
| "version": 1, | ||
| "keys": ["key1", "key3", "key2", "key4"], | ||
| "keysToValues": { | ||
| "key1": "valueX", | ||
| "key2": "valueY", | ||
| "key3": "valueZ", | ||
| "key4": "valueA" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
test("Get partitioning measures by id should return partitioning measures for partitioning with measures") { | ||
|
||
table("runs.partitionings").insert( | ||
add("partitioning", partitioning) | ||
.add("created_by", "Thomas") | ||
) | ||
|
||
val fkPartitioning: Long = table("runs.partitionings") | ||
.fieldValue("partitioning", partitioning, "id_partitioning").get.get | ||
|
||
table("runs.measure_definitions").insert( | ||
add("fk_partitioning", fkPartitioning) | ||
.add("created_by", "Thomas") | ||
.add("measure_name", "measure1") | ||
.add("measured_columns", CustomDBType("""{"col1"}""", "TEXT[]")) | ||
) | ||
|
||
table("runs.measure_definitions").insert( | ||
add("fk_partitioning", fkPartitioning) | ||
.add("created_by", "Thomas") | ||
.add("measure_name", "measure2") | ||
.add("measured_columns", CustomDBType("""{"col2"}""", "TEXT[]")) | ||
) | ||
|
||
function(fncGetPartitioningMeasuresById) | ||
.setParam("i_partitioning_id", fkPartitioning) | ||
.execute { queryResult => | ||
val results = queryResult.next() | ||
assert(results.getInt("status").contains(11)) | ||
assert(results.getString("status_text").contains("OK")) | ||
assert(results.getString("measure_name").contains("measure1")) | ||
assert(results.getArray[String]("measured_columns").map(_.toSeq).contains(Seq("col1"))) | ||
|
||
val results2 = queryResult.next() | ||
assert(results2.getInt("status").contains(11)) | ||
assert(results2.getString("status_text").contains("OK")) | ||
assert(results2.getString("measure_name").contains("measure2")) | ||
assert(results2.getArray[String]("measured_columns").map(_.toSeq).contains(Seq("col2"))) | ||
} | ||
} | ||
|
||
test("Get partitioning measures by id should return error for partitioning without measures") { | ||
|
||
table("runs.partitionings").insert( | ||
add("partitioning", partitioning) | ||
.add("created_by", "Thomas") | ||
) | ||
|
||
val fkPartitioning: Long = table("runs.partitionings") | ||
.fieldValue("partitioning", partitioning, "id_partitioning").get.get | ||
|
||
function(fncGetPartitioningMeasuresById) | ||
.setParam(fkPartitioning) | ||
.execute { queryResult => | ||
assert(!queryResult.hasNext) | ||
} | ||
} | ||
|
||
test("Get partitioning measures by id should return an error for non-existing partitioning") { | ||
|
||
function(fncGetPartitioningMeasuresById) | ||
.setParam(999) | ||
.execute { queryResult => | ||
val results = queryResult.next() | ||
assert(results.getInt("status").contains(41)) | ||
assert(results.getString("status_text").contains("Partitioning not found")) | ||
assert(!queryResult.hasNext) // checking no more records are returned. | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...cala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasuresById.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.server.api.database.runs.functions | ||
|
||
import doobie.implicits.toSqlInterpolator | ||
import za.co.absa.atum.server.api.database.PostgresDatabaseProvider | ||
import za.co.absa.atum.server.api.database.runs.Runs | ||
import za.co.absa.db.fadb.DBSchema | ||
import za.co.absa.db.fadb.doobie.DoobieEngine | ||
import za.co.absa.db.fadb.doobie.DoobieFunction.DoobieMultipleResultFunctionWithAggStatus | ||
import za.co.absa.db.fadb.status.aggregation.implementations.ByFirstErrorStatusAggregator | ||
import za.co.absa.db.fadb.status.handling.implementations.StandardStatusHandling | ||
import zio._ | ||
import za.co.absa.atum.server.model.MeasureFromDB | ||
|
||
import za.co.absa.atum.server.api.database.DoobieImplicits.Sequence.get | ||
|
||
class GetPartitioningMeasuresById(implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) | ||
extends DoobieMultipleResultFunctionWithAggStatus[Long, MeasureFromDB, Task](values => | ||
Seq(fr"${values}") | ||
) with StandardStatusHandling with ByFirstErrorStatusAggregator { | ||
|
||
override def fieldsToSelect: Seq[String] = super.fieldsToSelect ++ Seq("measure_name", "measured_columns") | ||
} | ||
|
||
object GetPartitioningMeasuresById { | ||
val layer: URLayer[PostgresDatabaseProvider, GetPartitioningMeasuresById] = ZLayer { | ||
for { | ||
dbProvider <- ZIO.service[PostgresDatabaseProvider] | ||
} yield new GetPartitioningMeasuresById()(Runs, dbProvider.dbEngine) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.