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

#48: Review of the db model and functions #82

Merged
merged 16 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -13,22 +13,22 @@
* limitations under the License.
*/

-- DROP TABLE IF EXISTS flow_patterns.checkpoint_measure_definitions;
-- DROP TABLE IF EXISTS flow_patterns.measure_definitions;

CREATE TABLE flow_patterns.checkpoint_measure_definitions
CREATE TABLE flow_patterns.measure_definitions
(
id_fp_checkpoint_measure_definition BIGINT NOT NULL DEFAULT global_id(),
id_fp_measure_definition BIGINT NOT NULL DEFAULT global_id(),
key_fp_flow BIGINT NOT NULL,
measure_type TEXT NOT NULL,
measure_fields TEXT[] NOT NULL,
created_by TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_by TEXT NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT fp_checkpoint_definitions_pk PRIMARY KEY (id_fp_checkpoint_measure_definition)
CONSTRAINT fp_checkpoint_definitions_pk PRIMARY KEY (id_fp_measure_definition)
);

ALTER TABLE flow_patterns.checkpoint_measure_definitions
ADD CONSTRAINT fp_checkpoint_measure_definitions_unq UNIQUE (key_fp_flow, measure_type, measure_fields);
ALTER TABLE flow_patterns.measure_definitions
ADD CONSTRAINT fp_measure_definitions_unq UNIQUE (key_fp_flow, measure_type, measure_fields);

ALTER TABLE flow_patterns.checkpoint_measure_definitions OWNER to atum_owner;
ALTER TABLE flow_patterns.measure_definitions OWNER to atum_owner;
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION flow_patterns.get_flow_checkpoint_measure_definitions(
CREATE OR REPLACE FUNCTION flow_patterns.get_flow_measure_definitions(
IN i_flow_name TEXT,
OUT status INTEGER,
OUT status_text TEXT,
OUT id_fp_checkpoint_measure_definition BIGINT,
OUT id_fp_measure_definition BIGINT,
OUT measure_type TEXT,
OUT measure_fields TEXT[],
OUT created_by TEXT,
Expand All @@ -28,7 +28,7 @@ CREATE OR REPLACE FUNCTION flow_patterns.get_flow_checkpoint_measure_definitions
$$
-------------------------------------------------------------------------------
--
-- Function: flow_patterns.get_flow_checkpoint_measure_definitions(1)
-- Function: flow_patterns.get_flow_measure_definitions(1)
-- Gets all the control measure definitions of the flow.
-- If flow of the given name does not exists one record with status 40 is returned.
--
Expand All @@ -38,7 +38,7 @@ $$
-- Returns:
-- status - Status code
-- status_text - Status text
-- id_fp_checkpoint_measure_definition - Id of the additional data entry
-- id_fp_measure_definition - Id of the additional data entry
-- measure_type - type of the control measure
-- measure_fields - dlist of the fields the measure is applied to
-- created_by - user who created the entry
Expand All @@ -60,10 +60,10 @@ BEGIN

IF status = 10 THEN
RETURN QUERY
SELECT 10,'OK',CMD.id_fp_checkpoint_measure_definition,CMD.measure_type,
SELECT 10,'OK',CMD.id_fp_measure_definition,CMD.measure_type,
CMD.measure_fields,CMD.created_by,CMD.created_at,CMD.updated_by,
CMD.updated_at
FROM flow_patterns.checkpoint_measure_definitions CMD
FROM flow_patterns.measure_definitions CMD
WHERE CMD.key_fp_flow = _key_fp_flow;
ELSE
RETURN NEXT;
Expand All @@ -74,4 +74,4 @@ END;
$$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

GRANT EXECUTE ON FUNCTION flow_patterns.get_flow_checkpoint_measure_definitions(TEXT) TO atum_configurator;
GRANT EXECUTE ON FUNCTION flow_patterns.get_flow_measure_definitions(TEXT) TO atum_configurator;
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION flow_patterns.set_checkpoint_measure_definition(
CREATE OR REPLACE FUNCTION flow_patterns.set_measure_definition(
IN i_flow_name TEXT,
IN i_measure_type TEXT,
IN i_measure_fields TEXT[],
IN i_by_user TEXT,
OUT status INTEGER,
OUT status_text TEXT,
OUT id_fp_checkpoint_measure_definition BIGINT,
OUT id_fp_measure_definition BIGINT,
OUT key_fp_flow BIGINT
) RETURNS record AS
$$
-------------------------------------------------------------------------------
--
-- Function: flow_patterns.set_checkpoint_measure_definition(4)
-- Function: flow_patterns.set_measure_definition(4)
-- Adds a measure definition pattern to the given flow.
--
-- Parameters:
Expand All @@ -38,7 +38,7 @@ $$
-- Returns:
-- status - Status code
-- status_text - Status text
-- id_fp_checkpoint_measure_definition - id of the measure definition entry
-- id_fp_measure_definition - id of the measure definition entry
-- key_fp_flow - id of the flow the additional data pattern were added into
--
-- Status codes:
Expand All @@ -47,18 +47,18 @@ $$
--
-------------------------------------------------------------------------------
DECLARE
_id_fp_checkpoint_measure_definition BIGINT;
_id_fp_measure_definition BIGINT;
BEGIN
SELECT GF.status, GF.status_text, GF.id_fp_flow
FROM flow_patterns.get_flow(i_flow_name) GF
INTO status, status_text, key_fp_flow;

IF status = 10 THEN

INSERT INTO flow_patterns.checkpoint_measure_definitions(key_fp_flow, measure_type, measure_fields, created_by, updated_by)
INSERT INTO flow_patterns.measure_definitions(key_fp_flow, measure_type, measure_fields, created_by, updated_by)
VALUES (key_fp_flow, i_measure_type, i_measure_fields, i_by_user, i_by_user)
RETURNING flow_patterns.checkpoint_measure_definitions.id_fp_checkpoint_measure_definition
INTO id_fp_checkpoint_measure_definition;
RETURNING flow_patterns.measure_definitions.id_fp_measure_definition
INTO id_fp_measure_definition;

status := 11;
status_text := 'Measure definition entry created';
Expand All @@ -72,4 +72,4 @@ END;
$$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

GRANT EXECUTE ON FUNCTION flow_patterns.set_checkpoint_measure_definition(TEXT, TEXT, TEXT[], TEXT) TO atum_configurator;
GRANT EXECUTE ON FUNCTION flow_patterns.set_measure_definition(TEXT, TEXT, TEXT[], TEXT) TO atum_configurator;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 ABSA Group Limited
* 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.
Expand Down Expand Up @@ -55,4 +55,4 @@ END;
$$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

GRANT EXECUTE ON FUNCTION flow_patterns.get_flow() TO atum_configurator;
GRANT EXECUTE ON FUNCTION flow_patterns.list_flows() TO atum_configurator;
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION flow_patterns.update_checkpoint_measure_definition(
IN i_id_fp_checkpoint_measure_definition TEXT,
CREATE OR REPLACE FUNCTION flow_patterns.update_measure_definition(
IN i_id_fp_measure_definition TEXT,
IN i_measure_type TEXT,
IN i_measure_fields TEXT[],
IN i_by_user TEXT,
Expand All @@ -24,7 +24,7 @@ CREATE OR REPLACE FUNCTION flow_patterns.update_checkpoint_measure_definition(
$$
-------------------------------------------------------------------------------
--
-- Function: flow_patterns.update_checkpoint_measure_definition(4)
-- Function: flow_patterns.update_measure_definition(4)
-- Updates the measure definition pattern values
--
-- Parameters:
Expand All @@ -36,7 +36,7 @@ $$
-- Returns:
-- status - Status code
-- status_text - Status text
-- id_fp_checkpoint_measure_definition - id of the measure definition entry
-- id_fp_measure_definition - id of the measure definition entry
-- key_fp_flow - id of the flow the additional data pattern were added into
--
-- Status codes:
Expand All @@ -50,8 +50,8 @@ DECLARE
_measure_fields TEXT;
BEGIN
SELECT CMD.measure_type, CMD.measure_fields
FROM flow_patterns.checkpoint_measure_definitions CMD
WHERE CMD.id_fp_checkpoint_measure_definition = i_id_fp_checkpoint_measure_definition
FROM flow_patterns.measure_definitions CMD
WHERE CMD.id_fp_measure_definition = i_id_fp_measure_definition
FOR UPDATE
INTO _measure_type, _measure_fields;

Expand All @@ -62,12 +62,12 @@ BEGIN
END IF;

IF (i_measure_type IS DISTINCT FROM _measure_type) OR (i_measure_fields IS DISTINCT FROM _measure_fields) THEN
UPDATE flow_patterns.checkpoint_measure_definitions
UPDATE flow_patterns.measure_definitions
SET measure_type = i_measure_type,
measure_fields = i_measure_fields,
updated_by = i_by_user,
updated_at = now()
WHERE id_fp_checkpoint_measure_definition = i_id_fp_checkpoint_measure_definition;
WHERE id_fp_measure_definition = i_id_fp_measure_definition;

status := 12;
status_text := 'Measure definition entry updated';
Expand All @@ -81,4 +81,4 @@ END;
$$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

GRANT EXECUTE ON FUNCTION flow_patterns.update_checkpoint_measure_definition(TEXT, TEXT, TEXT[], TEXT) TO atum_configurator;
GRANT EXECUTE ON FUNCTION flow_patterns.update_measure_definition(TEXT, TEXT, TEXT[], TEXT) TO atum_configurator;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

--TODO
CREATE OR REPLACE FUNCTION runs._add_segmentation_flow(
IN i_segmentation HSTORE,
IN i_by_user TEXT,
Expand Down Expand Up @@ -77,9 +78,9 @@ BEGIN

IF (FOUND) THEN
_from_pattern := TRUE;
INSERT INTO runs.checkpoint_measure_definitions (key_segmentation, measure_type, measure_fields, created_by)
INSERT INTO runs.measure_definitions (key_segmentation, measure_type, measure_fields, created_by)
SELECT _id_segmentation, CMD.measure_type, CMD.measure_fields, CMD.updated_by
FROM flow_patterns.checkpoint_measure_definitions CMD
FROM flow_patterns.measure_definitions CMD
WHERE CMD.key_fp_flow = _key_fp_flow;

IF i_take_pattern_additional_data THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

-- TODO
CREATE OR REPLACE FUNCTION runs._get_flow_name_from_segmentation(
IN i_segmentation HSTORE,
OUT flow_name TEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

--TODO
CREATE OR REPLACE FUNCTION runs.define_flow(
IN i_segmentation HSTORE,
IN i_by_user TEXT,
Expand Down Expand Up @@ -130,9 +131,9 @@ BEGIN
FROM runs.segmentation_to_flow STF
WHERE STF.key_segmentation = _key_parent_segmentation;

INSERT INTO runs.checkpoint_measure_definitions (key_segmentation, measure_type, measure_fields, created_by, created_at)
INSERT INTO runs.measure_definitions (key_segmentation, measure_type, measure_fields, created_by, created_at)
SELECT _id_segmentation, CMD.measure_type, CMD.measure_fields, CMD.created_by, CMD.created_at
FROM runs.checkpoint_measure_definitions CMD
FROM runs.measure_definitions CMD
WHERE CMD.key_segmentation = _key_parent_segmentation
ON CONFLICT DO NOTHING;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

--TODO
CREATE OR REPLACE FUNCTION runs.flows_of_segmentation(
IN i_segmentation HSTORE,
OUT status INTEGER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ BEGIN
runs.segmentations S ON S.id_segmentation = STF.key_segmentation INNER JOIN
runs.checkpoints CP ON CP.key_segmentation = STF.key_segmentation INNER JOIN
runs.measurements M ON M.key_checkpoint = CP.id_checkpoint INNER JOIN
runs.checkpoint_measure_definitions CMD ON CMD.id_checkpoint_measure_definition = M.key_checkpoint_measure_definition
runs.measure_definitions CMD ON CMD.id_measure_definition = M.key_measure_definition
WHERE STF.key_flow = i_id_flow;

RETURN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION runs.get_segmentation_additional_data(
IN i_segmentation HSTORE,
CREATE OR REPLACE FUNCTION runs.get_partitioning_additional_data(
IN i_partitioning JSONB,
OUT status INTEGER,
OUT status_text TEXT,
OUT ad_name TEXT,
Expand All @@ -27,12 +27,12 @@ CREATE OR REPLACE FUNCTION runs.get_segmentation_additional_data(
$$
-------------------------------------------------------------------------------
--
-- Function: runs.get_segmentation_additional_data(1)
-- Function: runs.get_partitioning_additional_data(1)
-- Return's all additional data, that are associated with the give segmentation.
-- If the given segmentation does not exist, exactly one record is returned with the error status.
--
-- Parameters:
-- i_segmentation - segmentation for which the data are bound to
-- i_partitioning - segmentation for which the data are bound to
--
-- Returns:
-- status - Status code
Expand All @@ -50,13 +50,13 @@ $$
--
-------------------------------------------------------------------------------
DECLARE
_key_segmentation BIGINT;
_fk_partitioning BIGINT;
BEGIN
_key_segmentation = runs._get_key_segmentation(i_segmentation);
_fk_partitioning = runs._get_id_partitioning(i_partitioning);

IF _key_segmentation IS NULL THEN
IF _fk_partitioning IS NULL THEN
status := 41;
status_text := 'Segmentation not found';
status_text := 'Partitioning not found';
RETURN NEXT;
RETURN;
END IF;
Expand All @@ -65,11 +65,12 @@ BEGIN
SELECT 10, 'OK', AD.ad_name, AD.ad_value,
AD.created_by, AD.created_at, AD.updated_by, AD.updated_at
FROM runs.additional_data AD
WHERE AD.key_segmentation = _key_segmentation;
WHERE AD.fk_partitioning = _fk_partitioning;

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

GRANT EXECUTE ON FUNCTION runs.get_segmentation_additional_data(HSTORE) TO atum_user;
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;
Loading
Loading