Skip to content

Commit

Permalink
Merge branch 'master' into feature/#263-Hide-non-active-endpoints-v2-…
Browse files Browse the repository at this point in the history
…from-swagger
  • Loading branch information
TebaleloS authored Sep 30, 2024
2 parents c591e57 + ecf55e2 commit 7b8551c
Show file tree
Hide file tree
Showing 40 changed files with 1,416 additions and 340 deletions.
82 changes: 82 additions & 0 deletions database/src/main/postgres/runs/V1.9.12__get_partitioning.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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(
IN i_partitioning JSONB,
OUT status INTEGER,
OUT status_text TEXT,
OUT id BIGINT,
OUT o_partitioning JSONB,
OUT author TEXT
) RETURNS record AS
$$
-------------------------------------------------------------------------------
--
-- Function: runs.get_partitioning(1)
-- Retrieves a partitioning by its JSONB representation.
--
-- Parameters:
-- i_partitioning - partitioning to search for, a valid example:
-- {
-- "keys": ["one", "two", "three"],
-- "version": 1,
-- "keysToValues": {
-- "one": "DatasetA",
-- "two": "Version1",
-- "three": "2022-12-20"
-- }
-- }
--
-- Returns:
-- status - status of the operation:
-- status_text - textual representation of the status
-- id - ID of the partitioning
-- o_partitioning - partitioning data
-- author - author of the partitioning
--
-- Status codes:
-- 11 - OK
-- 41 - Partitioning not found
--
-------------------------------------------------------------------------------
BEGIN
-- Initialize status and status_text
status := 41;
status_text := 'Partitioning not found';

-- Retrieve partitioning ID
id := runs._get_id_partitioning(i_partitioning);

-- If ID is found, retrieve partitioning details
IF id IS NOT NULL THEN
SELECT GPBI.id, GPBI.partitioning, GPBI.author
INTO get_partitioning.id, get_partitioning.o_partitioning, get_partitioning.author
FROM runs.get_partitioning_by_id(id) AS GPBI;

-- Update status if partitioning is found
IF FOUND THEN
status := 11;
status_text := 'OK';
END IF;
END IF;

RETURN;
END;
$$
LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER;

ALTER FUNCTION runs.get_partitioning(i_partitioning JSONB) OWNER TO atum_owner;
GRANT EXECUTE ON FUNCTION runs.get_partitioning(i_partitioning JSONB) TO atum_user;
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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_main_flow(
IN i_partitioning_id BIGINT,
OUT status INTEGER,
OUT status_text TEXT,
OUT id_flow BIGINT,
OUT flow_name TEXT,
OUT flow_description TEXT,
OUT from_pattern BOOLEAN
) RETURNS record AS
$$
-------------------------------------------------------------------------------
--
-- Function: runs.get_partitioning_main_flow(1)
-- Returns the main flow for the given partitioning
--
-- Parameters:
-- i_partitioning_id - id of the partitioning for requested main flow
--
-- Returns:
-- status - Status code
-- status_text - Status message
-- id_flow - ID of the main flow associated with a given partitioning
-- flow_name - Name of the main flow
-- flow_description - Description of the main flow
-- from_pattern - Flag if the main flow was generated from pattern
--
-- Status codes:
-- 11 - OK
-- 41 - Partitioning not found
-- 50 - Main flow 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;
END IF;

status = 11;
status_text = 'OK';

SELECT F.id_flow,
F.flow_name,
F.flow_description,
F.from_pattern
FROM flows.flows AS F
WHERE F.fk_primary_partitioning = i_partitioning_id
INTO id_flow, flow_name, flow_description, from_pattern;

IF NOT FOUND THEN
status := 50;
status_text := 'Main flow not found';
RETURN;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

ALTER FUNCTION runs.get_partitioning_main_flow(BIGINT) OWNER TO atum_owner;
GRANT EXECUTE ON FUNCTION runs.get_partitioning_main_flow(BIGINT) TO atum_user;
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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 io.circe.Json
import za.co.absa.balta.DBTestSuite
import za.co.absa.balta.classes.JsonBString

class GetPartitioningIntegrationTests extends DBTestSuite {

private val fnCreatePartitioning = "runs.create_partitioning"
private val fnGetPartitioning = "runs.get_partitioning"

private val partitioning1Value =
"""
|{
| "version":1,
| "keys":["key1","key2","key3","key4"],
| "keysToValues":{
| "key1":"valueX",
| "key2":"valueY",
| "key3":"valueZ",
| "key4":"valueA"
| }
|}
|""".stripMargin

private val partitioning1 = JsonBString(partitioning1Value)

private val partitioning2 = JsonBString(
"""
|{
| "version":1,
| "keys":["key1","key2","key3","key4"],
| "keysToValues":{
| "key1":"valueX",
| "key2":"valueX",
| "key3":"valueX",
| "key4":"valueX"
| }
|}
|""".stripMargin
)

test("Existing (correct) partitioning is returned") {
val partitioning1ID = function(fnCreatePartitioning)
.setParam("i_partitioning", partitioning1)
.setParam("i_by_user", "Fantômas")
.setParamNull("i_parent_partitioning_id")
.execute { queryResult =>
assert(queryResult.hasNext)
val row = queryResult.next()
assert(row.getInt("status").contains(11))
assert(row.getString("status_text").contains("Partitioning created"))
row.getLong("id_partitioning").get
}

function(fnCreatePartitioning)
.setParam("i_partitioning", partitioning2)
.setParam("i_by_user", "Fantômas")
.setParamNull("i_parent_partitioning_id")
.execute { queryResult =>
assert(queryResult.hasNext)
val row = queryResult.next()
assert(row.getInt("status").contains(11))
assert(row.getString("status_text").contains("Partitioning created"))
}

function(fnGetPartitioning)
.setParam("i_partitioning", partitioning1)
.execute { queryResult =>
assert(queryResult.hasNext)
val row = queryResult.next()
assert(row.getInt("status").contains(11))
assert(row.getString("status_text").contains("OK"))
assert(row.getLong("id").contains(partitioning1ID))
assert {
val retrievedPartitioningAsJson = Json.fromString(row.getJsonB("o_partitioning").get.value)
val expectedPartitioningAsJson = Json.fromString(partitioning1Value)
retrievedPartitioningAsJson \\ "keysToValues" == expectedPartitioningAsJson \\ "keysToValues" &&
retrievedPartitioningAsJson \\ "keys" == expectedPartitioningAsJson \\ "keys"
}
assert(row.getString("author").contains("Fantômas"))
assert(!queryResult.hasNext)
}
}

test("Non-existent partitioning is not returned") {
function(fnGetPartitioning)
.setParam("i_partitioning", partitioning1)
.execute { queryResult =>
assert(queryResult.hasNext)
val row = queryResult.next()
assert(row.getInt("status").contains(41))
assert(row.getString("status_text").contains("Partitioning not found"))
assert(row.getLong("id").isEmpty)
assert(row.getJsonB("o_partitioning").isEmpty)
assert(row.getString("author").isEmpty)
assert(!queryResult.hasNext)
}
}

}
Loading

0 comments on commit 7b8551c

Please sign in to comment.