Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defined and implemented get_partitioning_measures:#137 #157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
49aae64
Fixes #137 - defined and implemented get_partitioning_measures
TebaleloS Feb 13, 2024
cdf8a94
Merge branch 'master' into feature/#137-Create-DB-function-to-gather-…
TebaleloS Feb 13, 2024
8c8008e
Closes #137
TebaleloS Feb 13, 2024
1546d77
Closes #137 - saving changes
TebaleloS Feb 15, 2024
58af24c
Closes #137 - fixed get_partitioning_measures function
TebaleloS Feb 15, 2024
4f8f49c
Fixes #137
TebaleloS Feb 16, 2024
158d54c
Fixes #137 - refactored db function and the test cases
TebaleloS Feb 19, 2024
ecba9ac
Merge branch 'master' into feature/#137-Create-DB-function-to-gather-…
TebaleloS Feb 19, 2024
40cdf76
Closes #137 - removed print statements
TebaleloS Feb 20, 2024
d8e92c5
Fixes #137 - catered for partitioning without measures
TebaleloS Feb 22, 2024
19ae373
Fixes #137 - implemented the test cases
TebaleloS Feb 23, 2024
81eaf94
Fixes #137 - Implemented github comment
TebaleloS Feb 23, 2024
9eee293
Merge branch 'master' into feature/#137-Create-DB-function-to-gather-…
TebaleloS Feb 23, 2024
b2f2c93
Update database/src/main/postgres/runs/V1.5.11__get_partitioning_meas…
TebaleloS Feb 25, 2024
fe72260
Update database/src/main/postgres/runs/V1.5.11__get_partitioning_meas…
TebaleloS Feb 25, 2024
c21d06c
Update database/src/main/postgres/runs/V1.5.11__get_partitioning_meas…
TebaleloS Feb 25, 2024
4f7ae49
Update database/src/test/scala/za/co/absa/atum/database/runs/GetParti…
TebaleloS Feb 25, 2024
cc2acf0
Fixes #137 - applied github comment
TebaleloS Feb 28, 2024
b9e51ce
Fixes #137 - applied github comment
TebaleloS Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_measures(
IN i_partitioning JSONB,
OUT status INTEGER,
OUT status_text TEXT,
OUT measure_name TEXT,
OUT measured_columns TEXT[]
) RETURNS SETOF record AS
$$
-------------------------------------------------------------------------------
--
-- Function: runs.get_partitioning_measures(1)
-- Returns measures for the given partitioning
--
-- Parameters:
-- i_partitioning - partitioning 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
-- 16 - Record not found for the given partitioning
-- 41 - Partitioning not found
--
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
-------------------------------------------------------------------------------

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;
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
RETURN;
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
END IF;

status := 11;
status_text := 'OK';

RETURN QUERY
SELECT status, status_text, md.measure_name, md.measured_columns
FROM runs.measure_definitions AS md
WHERE md.fk_partitioning = _fk_partitioning;

IF NOT FOUND THEN
status := 16;
status_text := 'No measures found for the given partitioning.';
RETURN NEXT;
RETURN;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

ALTER FUNCTION runs.get_partitioning_measures(JSONB) OWNER TO atum_owner;
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
GRANT EXECUTE ON FUNCTION runs.get_partitioning_measures(JSONB) TO atum_user;
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* 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
import za.co.absa.balta.classes.setter.CustomDBType

class GetPartitioningMeasuresTest extends DBTestSuite {
private val fncGetPartitioningMeasures = "runs.get_partitioning_measures"

test("Get partitioning measures should return partitioning measures for partitioning with measures") {
val partitioning = JsonBString(
"""
|{
| "version": 1,
| "keys": ["key1", "key3", "key2", "key4"],
| "keysToValues": {
| "key1": "valueX",
| "key2": "valueY",
| "key3": "valueZ",
| "key4": "valueA"
| }
|}
|""".stripMargin
)

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(fncGetPartitioningMeasures)
.setParam("i_partitioning", partitioning)
.execute { queryResult =>
val results = queryResult.next()
assert(results.getInt("status").contains(11))
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
assert(results.getString("status_text").contains("OK"))
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
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")))

assert(!queryResult.hasNext)
}
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved

table("runs.measure_definitions").where(add("fk_partitioning", fkPartitioning)) { partitioningMeasuresResult =>
assert(partitioningMeasuresResult.hasNext)
val row = partitioningMeasuresResult.next()
assert(row.getString("created_by").contains("Thomas"))
}
}

test("Get partitioning measures should return error status code on non existing partitioning") {
val partitioning = JsonBString(
"""
|{
| "version": 1,
| "keys": ["key1"],
| "keysToValues": {
| "key1": "value1"
| }
|}
|""".stripMargin
)

function(fncGetPartitioningMeasures)
.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."))
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
assert(!queryResult.hasNext)
}
}

test("Get partitioning measures should return no data status code on partitioning without measures") {
val partitioning = JsonBString(
"""
|{
| "keys": [
| "keyA",
| "keyB",
| "keyC"
| ],
| "version": 1,
| "keysToValues": {
| "keyA": "valueA",
| "keyB": "valueB",
| "keyC": "valueC"
| }
|}
|""".stripMargin
)

table("runs.partitionings").insert(
add("partitioning", partitioning)
.add("created_by", "Thomas")
)

function(fncGetPartitioningMeasures)
.setParam("i_partitioning", partitioning)
.execute { queryResult =>
val results = queryResult.next()
assert(results.getInt("status").contains(16))
assert(results.getString("status_text").contains("No measures found for the given partitioning."))
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
assert(!queryResult.hasNext)
}
}

}
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved

Loading