-
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.
Merge branch 'master' into feature/measurement-refactoring
- Loading branch information
Showing
2 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
database/src/main/postgres/runs/V1.5.12_get_partitioning_additional_data.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,77 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
CREATE OR REPLACE FUNCTION runs.get_partitioning_additional_data( | ||
IN i_partitioning JSONB, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT ad_name TEXT, | ||
OUT ad_value TEXT | ||
) RETURNS SETOF record AS | ||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.get_partitioning_additional_data(2) | ||
-- Returns additional data for the given partitioning | ||
-- | ||
-- Parameters: | ||
-- i_partitioning - partitioning for requested additional data | ||
-- | ||
-- Returns: | ||
-- status - Status code | ||
-- status_text - Status message | ||
-- ad_name - Name of the additional data | ||
-- ad_value - Value of the additional data | ||
-- | ||
-- Status codes: | ||
-- 11 - OK | ||
-- 16 - Record not found for the given partitioning | ||
-- 41 - Partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
|
||
DECLARE | ||
_fk_partitioning BIGINT; | ||
BEGIN | ||
_fk_partitioning = runs._get_id_partitioning(i_partitioning); | ||
|
||
IF _fk_partitioning IS NULL THEN | ||
status := 41; | ||
status_text := 'The partitioning does not exist.'; | ||
RETURN NEXT; | ||
RETURN; | ||
END IF; | ||
|
||
status = 11; | ||
status_text = 'OK'; | ||
|
||
RETURN QUERY | ||
SELECT status, status_text, ad.ad_name, ad.ad_value | ||
FROM runs.additional_data AS ad | ||
WHERE ad.fk_partitioning = _fk_partitioning; | ||
|
||
IF NOT FOUND THEN | ||
status := 16; | ||
status_text := 'No additional data found for the given partitioning.'; | ||
RETURN NEXT; | ||
RETURN; | ||
END IF; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.get_partitioning_additional_data(JSONB) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.get_partitioning_additional_data(JSONB) TO atum_user; |
168 changes: 168 additions & 0 deletions
168
database/src/test/scala/za/co/absa/atum/database/runs/GetPartitioningAditionalDataTest.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,168 @@ | ||
/* | ||
* 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.database.runs | ||
|
||
import za.co.absa.balta.DBTestSuite | ||
import za.co.absa.balta.classes.JsonBString | ||
|
||
class GetPartitioningAditionalDataTest extends DBTestSuite{ | ||
|
||
private val fncGetPartitioningAdditionalData = "runs.get_partitioning_additional_data" | ||
|
||
private val partitioning1 = JsonBString( | ||
""" | ||
|{ | ||
| "version": 1, | ||
| "keys": ["keyX", "keyY", "keyZ"], | ||
| "keysToValues": { | ||
| "keyX": "value1", | ||
| "keyZ": "value3", | ||
| "keyY": "value2" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
private val partitioning2 = JsonBString( | ||
""" | ||
|{ | ||
| "version": 1, | ||
| "keys": ["key1", "key3", "key2", "key4"], | ||
| "keysToValues": { | ||
| "key1": "valueX", | ||
| "key2": "valueY", | ||
| "key3": "valueZ", | ||
| "key4": "valueA" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
test("Get partitioning additional data returns additional data for partitioning with additional data") { | ||
table("runs.partitionings").insert( | ||
add("partitioning", partitioning1) | ||
.add("created_by", "Joseph") | ||
) | ||
|
||
table("runs.partitionings").insert( | ||
add("partitioning", partitioning2) | ||
.add("created_by", "Daniel") | ||
) | ||
|
||
|
||
val fkPartitioning1: Long = table("runs.partitionings").fieldValue("partitioning", partitioning1, "id_partitioning").get.get | ||
val fkPartitioning2: Long = table("runs.partitionings").fieldValue("partitioning", partitioning2, "id_partitioning").get.get | ||
|
||
table("runs.additional_data").insert( | ||
add("fk_partitioning", fkPartitioning1) | ||
.add("created_by", "Joseph") | ||
.add("ad_name", "ad_1") | ||
.add("ad_value", "This is the additional data for Joseph") | ||
.add("updated_by", "Joseph") | ||
) | ||
|
||
table("runs.additional_data").insert( | ||
add("fk_partitioning", fkPartitioning1) | ||
.add("created_by", "Joseph") | ||
.add("ad_name", "ad_2") | ||
.add("ad_value", "This is the additional data for Joseph") | ||
.add("updated_by", "Joseph") | ||
) | ||
|
||
table("runs.additional_data").insert( | ||
add("fk_partitioning", fkPartitioning2) | ||
.add("created_by", "Daniel") | ||
.add("ad_name", "ad_3") | ||
.add("ad_value", "This is the additional data for Daniel") | ||
.add("updated_by", "Daniel") | ||
) | ||
|
||
function(fncGetPartitioningAdditionalData) | ||
.setParam("i_partitioning", partitioning1) | ||
.execute { queryResult => | ||
val results = queryResult.next() | ||
assert(results.getInt("status").contains(11)) | ||
assert(results.getString("status_text").contains("OK")) | ||
assert(results.getString("ad_name").contains("ad_1")) | ||
assert(results.getString("ad_value").contains("This is the additional data for Joseph")) | ||
|
||
val results2 = queryResult.next() | ||
assert(results2.getInt("status").contains(11)) | ||
assert(results2.getString("status_text").contains("OK")) | ||
assert(results2.getString("ad_name").contains("ad_2")) | ||
assert(results2.getString("ad_value").contains("This is the additional data for Joseph")) | ||
|
||
assert(!queryResult.hasNext) | ||
} | ||
|
||
table("runs.additional_data").where(add("fk_partitioning", fkPartitioning1)) { additionalDataResult => | ||
assert(additionalDataResult.hasNext) | ||
val row = additionalDataResult.next() | ||
assert(row.getString("ad_name").contains("ad_1")) | ||
assert(row.getString("ad_value").contains("This is the additional data for Joseph")) | ||
assert(row.getString("created_by").contains("Joseph")) | ||
} | ||
|
||
} | ||
|
||
test("Get partitioning additional data should return no records for partitioning without additional data") { | ||
table("runs.partitionings").insert( | ||
add("partitioning", partitioning2) | ||
.add("created_by", "Joseph") | ||
) | ||
|
||
val fkPartitioning: Long = table("runs.partitionings").fieldValue("partitioning", partitioning2, "id_partitioning").get.get | ||
|
||
function(fncGetPartitioningAdditionalData) | ||
.setParam("i_partitioning", partitioning2) | ||
.execute { queryResult => | ||
val results = queryResult.next() | ||
assert(results.getInt("status").contains(16)) | ||
assert(results.getString("status_text").contains("No additional data found for the given partitioning.")) | ||
assert(results.getString("ad_name").isEmpty) | ||
assert(!queryResult.hasNext) | ||
} | ||
|
||
table("runs.additional_data").where(add("fk_partitioning", fkPartitioning)) { additionalDataResult => | ||
assert(!additionalDataResult.hasNext) | ||
} | ||
} | ||
|
||
test("Get partitioning additional data should return error status code on non existing partitioning") { | ||
val partitioning = JsonBString( | ||
""" | ||
|{ | ||
| "version": 1, | ||
| "keys": ["key1"], | ||
| "keysToValues": { | ||
| "key1": "value1" | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
function(fncGetPartitioningAdditionalData) | ||
.setParam("i_partitioning", partitioning) | ||
.execute { queryResult => | ||
val results = queryResult.next() | ||
assert(results.getInt("status").contains(41)) | ||
assert(results.getString("status_text").contains("The partitioning does not exist.")) | ||
assert(!queryResult.hasNext) | ||
} | ||
} | ||
|
||
} |