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 9 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,63 @@
/*
* 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 measure_name TEXT,
OUT measured_columns TEXT[],
OUT status INTEGER,
OUT status_text TEXT
) RETURNS SETOF record AS
$$
-------------------------------------------------------------------------------
--
-- Function: runs.get_partitioning_measures(2)
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
-- Iterates over a JSONB object and returns each key-value pair as a record
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
--
-- Parameters:
-- i_partitioning - JSONB object where each key is a measure name and its corresponding value is an array of measured columns
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
--
-- Returns:
-- measure_name - Name of the measure
-- measured_columns - Array of columns associated with the measure
--
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
measure_name := 'Partitioning not found';
measured_columns := '{}';
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
status := 41;
status_text := 'The partitioning does not exist.';
RETURN;
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
END IF;

status = 11;
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
status_text = 'OK';

RETURN QUERY
SELECT md.measure_name, md.measured_columns, status, status_text
FROM runs.measure_definitions AS md
WHERE md.fk_partitioning = _fk_partitioning;
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CreatePartitioningIfNotExists extends DBTestSuite{
row.getLong("id_partitioning").get
}

table("runs.partitionings").where(add("id_partitioning", partitioningID)) {partitioningResult =>
table("runs.partitionings").where(add("id_partitioning", partitioningID)) { partitioningResult =>
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
val row = partitioningResult.next()
// assert(row.getJsonB("partitioning").contains(partitioning)) TODO keys are reordered in JsonB and whitespaces removed
assert(row.getString("created_by").contains("Fantômas"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 GetPartitioningMeasuresTest extends DBTestSuite{

private val fncGetPartitioningMeasures = "runs.get_partitioning_measures"

private val partitioning = JsonBString(
"""
|{
| "version": 1,
| "keys": ["key1", "key2"],
| "values": {
| "key1": "value1",
| "key2": "value2"
| }
|}
|""".stripMargin
)

test("Get partitioning measures") {
function(fncGetPartitioningMeasures)
.setParam("i_partitioning", partitioning)
.execute { queryResult =>
val results = queryResult.distinct.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
}
TebaleloS marked this conversation as resolved.
Show resolved Hide resolved
}

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