Repository navigation
#478 (1): better reader capability #488
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 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
583438e
feat: improve reader capability with multi-value filters and paginati…
lsulak 0c3b69b
feat: cleanup
lsulak 444756a
feat: renaming appropriatelly the flyway files
lsulak 3630136
test(02): adjust integration tests to pass JSONB instead of HSTORE fo…
lsulak c2e7e36
ADR dedicated to consumption patterns - audits ideas and better readi…
lsulak 8e950cf
feat: querying improvements
lsulak a26a3d0
feat: removing unnecessary files
lsulak 478a421
updating readme
lsulak 50dd096
Merge branch 'master' into feature/478-better-reader-capability
lsulak 23c51bb
refactor: move audit scope (ADR 02) out of the #478 reader capability…
lsulak 5467d7d
feat(db): keep final checkpoint function signatures and properties in…
lsulak 29e2827
fix: reject checkpoint properties without any accepted value
lsulak 36817e6
fix: scaladoc link and coverage of empty checkpoint properties valida…
lsulak ba5c8ee
test: exercise combined-filter pagination against seeded data in serv…
lsulak ae02ced
fix: keep the default checkpoints limit of 5 in the checkpoints DB fu…
lsulak 28ef69a
test: close the single-transaction test connection even if rollback f…
lsulak eed28eb
Merge branch 'master' into feature/478-better-reader-capability
lsulak bfd01f5
this test is testing much less actually / there is quite an overlap, …
lsulak e1d4a98
redundant
lsulak aaecb4a
refactoring mostly
lsulak 683e108
improving code doc
lsulak f74ac88
improving code doc
lsulak ab4383b
#478 (2): checkpoint time window and latest-first on flows (audit con…
lsulak 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
221 changes: 221 additions & 0 deletions
221
database/src/main/postgres/flows/V0.8.0.1__get_flow_checkpoints.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,221 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| -- The previous overload is dropped so that the new signature (JSONB multi-value checkpoint properties filter and | ||
| -- the process start time window) is unambiguous when the function is called with named or defaulted arguments. | ||
| DROP FUNCTION IF EXISTS flows.get_flow_checkpoints(BIGINT, INT, BIGINT, TEXT, HSTORE, BOOLEAN); | ||
|
|
||
| CREATE OR REPLACE FUNCTION flows.get_flow_checkpoints( | ||
| IN i_flow_id BIGINT, | ||
| IN i_checkpoints_limit INT DEFAULT NULL, | ||
| IN i_offset BIGINT DEFAULT 0, | ||
| IN i_checkpoint_name TEXT DEFAULT NULL, | ||
| IN i_checkpoint_properties JSONB DEFAULT NULL, | ||
| IN i_latest_first BOOLEAN DEFAULT TRUE, | ||
| IN i_from_time TIMESTAMP WITH TIME ZONE DEFAULT NULL, | ||
| IN i_to_time TIMESTAMP WITH TIME ZONE DEFAULT NULL, | ||
| OUT status INTEGER, | ||
| OUT status_text TEXT, | ||
| OUT id_checkpoint UUID, | ||
| OUT checkpoint_name TEXT, | ||
| OUT checkpoint_author TEXT, | ||
| OUT measured_by_atum_agent BOOLEAN, | ||
| OUT measure_name TEXT, | ||
| OUT measured_columns TEXT[], | ||
| OUT measurement_value JSONB, | ||
| OUT checkpoint_start_time TIMESTAMP WITH TIME ZONE, | ||
| OUT checkpoint_end_time TIMESTAMP WITH TIME ZONE, | ||
| OUT id_partitioning BIGINT, | ||
| OUT partitioning JSONB, | ||
| OUT partitioning_author TEXT, | ||
| OUT has_more BOOLEAN | ||
| ) RETURNS SETOF record AS | ||
| -------------------------------------------------------------------------------------------------------------------- | ||
| -- | ||
| -- Function: flows.get_flow_checkpoints(8) | ||
| -- Retrieves all checkpoints (measures and their measurement details) related to an input flow (and checkpoint | ||
| -- name, checkpoint properties and/or process start time window, if specified). | ||
| -- | ||
| -- Note: a single row returned from this function doesn't contain all data related to a single checkpoint - it only | ||
| -- represents one measure associated with a checkpoint. So even if only a single checkpoint would be retrieved, | ||
| -- this function can potentially return multiple rows. | ||
| -- | ||
| -- Parameters: | ||
| -- i_flow_id - ID of the flow for which checkpoints are to be retrieved | ||
| -- i_checkpoints_limit - (optional) maximum number of checkpoints to return, returns all of them if NULL | ||
| -- i_offset - (optional) offset of the first checkpoint to return | ||
| -- i_checkpoint_name - (optional) if specified, returns data related to particular checkpoint's name | ||
| -- i_checkpoint_properties - (optional) JSON object mapping a property name to an array of accepted values, | ||
| -- e.g. {"executionID": ["a", "b"]}; returns only checkpoints that, for every given | ||
| -- property name, have that property with one of the accepted values | ||
| -- i_latest_first - (optional) if true (default), checkpoints are ordered by process_start_time | ||
| -- in descending order (latest first); if false, in ascending order | ||
| -- i_from_time - (optional) if specified, returns only checkpoints with process_start_time >= i_from_time | ||
| -- i_to_time - (optional) if specified, returns only checkpoints with process_start_time < i_to_time | ||
| -- | ||
| -- Note: i_checkpoints_limit and i_offset are used for pagination purposes; | ||
| -- checkpoints are ordered by process_start_time (descending by default, see i_latest_first) | ||
| -- and then by id_checkpoint in ascending order as a tie-breaker | ||
| -- | ||
| -- Returns: | ||
| -- status - Status code | ||
| -- status_text - Status text | ||
| -- id_checkpoint - ID of retrieved checkpoint | ||
| -- checkpoint_name - Name of the retrieved checkpoint | ||
| -- checkpoint_author - Author of the checkpoint | ||
| -- measured_by_atum_agent - Flag indicating whether the checkpoint was measured by Atum Agent | ||
| -- (if false, data supplied manually) | ||
| -- measure_name - measure name associated with a given checkpoint | ||
| -- measured_columns - measure columns associated with a given checkpoint | ||
| -- measurement_value - measurement details associated with a given checkpoint | ||
| -- checkpoint_start_time - Time of the checkpoint | ||
| -- checkpoint_end_time - End time of the checkpoint computation | ||
| -- id_partitioning - ID of the partitioning | ||
| -- partitioning - Partitioning value | ||
| -- partitioning_author - Author of the partitioning | ||
| -- has_more - Flag indicating whether there are more checkpoints available, always `false` if `i_limit` is NULL | ||
| -- | ||
| -- Status codes: | ||
| -- 11 - OK | ||
| -- 42 - Flow not found | ||
| --------------------------------------------------------------------------------------------------- | ||
| $$ | ||
| DECLARE | ||
| _has_more BOOLEAN; | ||
| _latest_first BOOLEAN := coalesce(i_latest_first, TRUE); | ||
| BEGIN | ||
| -- Check if the flow exists by querying the partitioning_to_flow table. | ||
| -- Rationale: | ||
| -- This table is preferred over the flows table because: | ||
| -- 1. Every flow has at least one record in partitioning_to_flow. | ||
| -- 2. This table is used in subsequent queries, providing a caching advantage. | ||
| -- 3. Improves performance by reducing the need to query the flows table directly. | ||
| PERFORM 1 FROM flows.partitioning_to_flow WHERE fk_flow = i_flow_id; | ||
| IF NOT FOUND THEN | ||
| status := 42; | ||
| status_text := 'Flow not found'; | ||
| RETURN NEXT; | ||
| RETURN; | ||
| END IF; | ||
|
|
||
| -- Determine if there are more checkpoints than the limit | ||
| IF i_checkpoints_limit IS NOT NULL THEN | ||
| SELECT count(*) > i_checkpoints_limit | ||
| FROM (SELECT 1 | ||
| FROM runs.checkpoints C | ||
| JOIN flows.partitioning_to_flow PF ON C.fk_partitioning = PF.fk_partitioning | ||
| WHERE PF.fk_flow = i_flow_id | ||
| AND (i_checkpoint_name IS NULL OR C.checkpoint_name = i_checkpoint_name) | ||
| AND (i_from_time IS NULL OR C.process_start_time >= i_from_time) | ||
| AND (i_to_time IS NULL OR C.process_start_time < i_to_time) | ||
| AND ( | ||
| i_checkpoint_properties IS NULL | ||
| OR NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM jsonb_each(i_checkpoint_properties) AS flt(k, v) | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM runs.checkpoint_properties CP | ||
| WHERE CP.fk_checkpoint = C.id_checkpoint | ||
| AND CP.property_name = flt.k | ||
| AND (v ? CP.property_value) | ||
| ) | ||
| ) | ||
| ) | ||
| ORDER BY CASE | ||
| WHEN _latest_first THEN C.process_start_time | ||
| END DESC, | ||
| CASE | ||
| WHEN NOT _latest_first THEN C.process_start_time | ||
| END ASC, | ||
| C.id_checkpoint ASC | ||
| LIMIT i_checkpoints_limit + 1 OFFSET i_offset) s | ||
| INTO _has_more; | ||
| ELSE | ||
| _has_more := false; | ||
| END IF; | ||
|
|
||
| -- Retrieve the checkpoints and their associated measurements | ||
| RETURN QUERY | ||
| WITH limited_checkpoints AS (SELECT C.id_checkpoint, | ||
| C.fk_partitioning, | ||
| C.checkpoint_name, | ||
| C.created_by, | ||
| C.measured_by_atum_agent, | ||
| C.process_start_time, | ||
| C.process_end_time | ||
| FROM runs.checkpoints C | ||
| JOIN flows.partitioning_to_flow PF ON C.fk_partitioning = PF.fk_partitioning | ||
| WHERE PF.fk_flow = i_flow_id | ||
| AND (i_checkpoint_name IS NULL OR C.checkpoint_name = i_checkpoint_name) | ||
| AND (i_from_time IS NULL OR C.process_start_time >= i_from_time) | ||
| AND (i_to_time IS NULL OR C.process_start_time < i_to_time) | ||
| AND ( | ||
| i_checkpoint_properties IS NULL | ||
| OR NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM jsonb_each(i_checkpoint_properties) AS flt(k, v) | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM runs.checkpoint_properties CP | ||
| WHERE CP.fk_checkpoint = C.id_checkpoint | ||
| AND CP.property_name = flt.k | ||
| AND (v ? CP.property_value) | ||
| ) | ||
| ) | ||
| ) | ||
| ORDER BY CASE | ||
| WHEN _latest_first THEN C.process_start_time | ||
| END DESC, | ||
| CASE | ||
| WHEN NOT _latest_first THEN C.process_start_time | ||
| END ASC, | ||
| C.id_checkpoint ASC | ||
| LIMIT i_checkpoints_limit OFFSET i_offset) | ||
| SELECT 11 AS status, | ||
| 'OK' AS status_text, | ||
| LC.id_checkpoint, | ||
| LC.checkpoint_name, | ||
| LC.created_by AS checkpoint_author, | ||
| LC.measured_by_atum_agent, | ||
| MD.measure_name, | ||
| MD.measured_columns, | ||
| M.measurement_value, | ||
| LC.process_start_time AS checkpoint_start_time, | ||
| LC.process_end_time AS checkpoint_end_time, | ||
| LC.fk_partitioning AS id_partitioning, | ||
| P.partitioning AS partitioning, | ||
| P.created_by AS partitioning_author, | ||
| _has_more AS has_more | ||
| FROM limited_checkpoints LC | ||
| INNER JOIN | ||
| runs.measurements M ON LC.id_checkpoint = M.fk_checkpoint | ||
| INNER JOIN | ||
| runs.measure_definitions MD ON M.fk_measure_definition = MD.id_measure_definition | ||
| INNER JOIN | ||
| runs.partitionings P ON LC.fk_partitioning = P.id_partitioning | ||
| ORDER BY CASE | ||
| WHEN _latest_first THEN LC.process_start_time | ||
| END DESC, | ||
| CASE | ||
| WHEN NOT _latest_first THEN LC.process_start_time | ||
| END ASC, | ||
| LC.id_checkpoint ASC; | ||
| END; | ||
| $$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER; | ||
|
|
||
| ALTER FUNCTION flows.get_flow_checkpoints(BIGINT, INT, BIGINT, TEXT, JSONB, BOOLEAN, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE) OWNER TO atum_owner; | ||
| GRANT EXECUTE ON FUNCTION flows.get_flow_checkpoints(BIGINT, INT, BIGINT, TEXT, JSONB, BOOLEAN, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE) TO atum_owner; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.