-
Notifications
You must be signed in to change notification settings - Fork 1
#305 getAncestors Database functionality. #311
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bbba4ae
Added the getAncestors Database functionality.
ABLL526 e479ea3
Added the getAncestors Database functionality.
ABLL526 8694a4f
Added the getAncestors Database functionality.
ABLL526 d968718
Added the getAncestors Database functionality.
ABLL526 a5c556c
Added the getAncestors Database functionality.
ABLL526 8961762
Changes made:
ABLL526 f83460a
Changes made:
ABLL526 c99a34a
Merge branch 'master' into 305-Get-Ancestors-Database
ABLL526 9c3256f
Merge branch 'master' into 305-Get-Ancestors-Database
ABLL526 4dcaa86
Changes Made:
ABLL526 867ea14
Merge branch 'master' into 305-Get-Ancestors-Database
ABLL526 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
112 changes: 112 additions & 0 deletions
112
database/src/main/postgres/runs/V0.3.0.3__get_partitioning_ancestors.sql
This file contains hidden or 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,112 @@ | ||
/* | ||
* 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_ancestors( | ||
IN i_id_partitioning BIGINT, | ||
IN i_limit INT DEFAULT 10, | ||
IN i_offset BIGINT DEFAULT 0, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT ancestor_id BIGINT, | ||
OUT partitioning JSONB, | ||
OUT author TEXT, | ||
OUT has_more BOOLEAN | ||
) RETURNS SETOF record AS | ||
$$ | ||
------------------------------------------------------------------------------- | ||
-- | ||
-- Function: runs.get_partitioning_ancestors(3) | ||
-- Returns the ids and partitionings of the ancestors of the given partition id. | ||
-- | ||
-- Parameters: | ||
-- i_id_partitioning - id that we're asking the Ancestors for | ||
-- i_limit - (optional) maximum number of partitionings to return, default is 10 | ||
-- i_offset - (optional) offset to use for pagination, default is 0 | ||
-- | ||
-- Returns: | ||
-- status - Status code | ||
-- status_text - Status message | ||
-- ancestor_id - ID of Ancestor partitioning | ||
-- partitioning - partitioning data of ancestor | ||
-- author - author of the Ancestor partitioning | ||
-- has_more - Flag indicating if there are more partitionings available | ||
|
||
-- Status codes: | ||
-- 10 - OK | ||
-- 14 - OK (No Ancestors found, therefore no op) | ||
-- 41 - Partitioning not found | ||
-- | ||
------------------------------------------------------------------------------- | ||
DECLARE | ||
_has_more BOOLEAN; | ||
|
||
BEGIN | ||
|
||
-- Check if the partitioning exists | ||
PERFORM 1 FROM runs.partitionings WHERE id_partitioning = i_id_partitioning; | ||
IF NOT FOUND THEN | ||
status := 41; | ||
status_text := 'Partitioning not found'; | ||
RETURN NEXT; | ||
RETURN; | ||
END IF; | ||
|
||
-- Check if there are more partitionings than the limit | ||
SELECT count(*) > i_limit | ||
FROM | ||
flows.partitioning_to_flow PF | ||
INNER JOIN flows.flows F ON F.id_flow = PF.fk_flow | ||
INNER JOIN runs.partitionings P ON P.id_partitioning = F.fk_primary_partitioning | ||
WHERE | ||
PF.fk_partitioning = i_id_partitioning AND | ||
P.id_partitioning IS DISTINCT FROM i_id_partitioning | ||
LIMIT i_limit + 1 OFFSET i_offset | ||
INTO _has_more; | ||
|
||
-- Return the ancestors | ||
RETURN QUERY | ||
SELECT | ||
10 AS status, | ||
'OK' AS status_text, | ||
P.id_partitioning AS ancestor_id, | ||
P.partitioning AS partitioning, | ||
P.created_by AS author, | ||
_has_more AS has_more | ||
FROM | ||
flows.partitioning_to_flow PF | ||
INNER JOIN flows.flows F ON F.id_flow = PF.fk_flow | ||
INNER JOIN runs.partitionings P ON P.id_partitioning = F.fk_primary_partitioning | ||
WHERE | ||
PF.fk_partitioning = i_id_partitioning AND | ||
P.id_partitioning IS DISTINCT FROM i_id_partitioning | ||
ORDER BY P.id_partitioning | ||
LIMIT i_limit | ||
OFFSET i_offset; | ||
|
||
--If no ancestors found send an OK status | ||
IF NOT FOUND THEN | ||
status := 14; | ||
status_text := 'OK'; | ||
RETURN NEXT; | ||
END IF; | ||
RETURN; | ||
|
||
END; | ||
$$ | ||
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; | ||
|
||
ALTER FUNCTION runs.get_partitioning_ancestors(BIGINT, INT, BIGINT) OWNER TO atum_owner; | ||
GRANT EXECUTE ON FUNCTION runs.get_partitioning_ancestors(BIGINT, INT, BIGINT) TO atum_user; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is gonna be useful, but as you said on some place above, function
runs.get_partitioning_checkpoint_v2
basically uses similar principle, so I guess you can keep it as is