-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/ndit 663 foundry integration #17
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
georgeRobertson
merged 6 commits into
develop_v04
from
feature/ndit-663_foundry_integration
Dec 16, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0dbbe7
feat: initial work to add Foundry pipeline for running DVE
stevenhsd b0cdca3
Merge branch 'develop_v04' of https://github.com/NHSDigital/data-vali…
stevenhsd 047c6a5
feat: amend foundry pipeline to include exception handling as not usi…
stevenhsd b356bd2
feat: some formatting. Tweaked how errors are handled within file tra…
stevenhsd 8b787cb
test: reenabled books behave tests
stevenhsd 7772040
docs: added some rationale around foundry pipeline
stevenhsd 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
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
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
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,94 @@ | ||
| """A duckdb pipeline for running on Foundry platform""" | ||
|
|
||
| from typing import Optional | ||
| from dve.core_engine.backends.implementations.duckdb.duckdb_helpers import duckdb_get_entity_count, duckdb_write_parquet | ||
| from dve.core_engine.backends.utilities import dump_errors | ||
| from dve.core_engine.models import SubmissionInfo | ||
| from dve.core_engine.type_hints import URI, Failed | ||
| from dve.pipeline.duckdb_pipeline import DDBDVEPipeline | ||
| from dve.pipeline.utils import SubmissionStatus | ||
| from dve.parser import file_handling as fh | ||
|
|
||
| class FoundryDDBPipeline(DDBDVEPipeline): | ||
| """DuckDB pipeline for running on Foundry Platform. | ||
| Polymorphed to allow for exception handling when processing | ||
| single files sequentially through services.""" | ||
|
|
||
| def persist_audit_records(self, submission_info: SubmissionInfo) -> URI: | ||
| """Write out key audit relations to parquet for persisting to datasets""" | ||
| write_to = fh.joinuri(self.processed_files_path, submission_info.submission_id, "audit/") | ||
| self.write_parquet( | ||
| self._audit_tables._processing_status.get_relation(), | ||
| write_to + "processing_status.parquet", | ||
| ) | ||
| self.write_parquet( | ||
| self._audit_tables._submission_statistics.get_relation(), | ||
| write_to + "submission_statistics.parquet", | ||
| ) | ||
| return write_to | ||
|
|
||
| def file_transformation( | ||
| self, submission_info: SubmissionInfo | ||
| ) -> SubmissionInfo | dict[str, str]: | ||
| try: | ||
| return super().file_transformation(submission_info) | ||
| except Exception as exc: # pylint: disable=W0718 | ||
| self._logger.error(f"File transformation raised exception: {exc}") | ||
| self._logger.exception(exc) | ||
| return submission_info.dict() | ||
|
|
||
| def apply_data_contract(self, submission_info: SubmissionInfo) -> tuple[SubmissionInfo | bool]: | ||
georgeRobertson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try: | ||
| return super().apply_data_contract(submission_info) | ||
| except Exception as exc: # pylint: disable=W0718 | ||
| self._logger.error(f"Apply data contract raised exception: {exc}") | ||
| self._logger.exception(exc) | ||
| return submission_info, True | ||
|
|
||
| def apply_business_rules(self, submission_info: SubmissionInfo, failed: Failed): | ||
| try: | ||
| return super().apply_business_rules(submission_info, failed) | ||
| except Exception as exc: # pylint: disable=W0718 | ||
| self._logger.error(f"Apply business rules raised exception: {exc}") | ||
| self._logger.exception(exc) | ||
| return submission_info, SubmissionStatus(failed=True) | ||
|
|
||
| def run_pipeline(self, submission_info: SubmissionInfo) -> tuple[Optional[URI], URI, URI]: | ||
| """Sequential single submission pipeline runner""" | ||
| try: | ||
| sub_id: str = submission_info.submission_id | ||
| self._audit_tables.add_new_submissions(submissions=[submission_info]) | ||
| self._audit_tables.mark_transform(submission_ids=[sub_id]) | ||
| sub_info = self.file_transformation(submission_info=submission_info) | ||
| if isinstance(sub_info, SubmissionInfo): | ||
| self._audit_tables.mark_data_contract(submission_ids=[sub_id]) | ||
| sub_info, failed = self.apply_data_contract(submission_info=submission_info) | ||
| self._audit_tables.mark_business_rules(submissions=[(sub_id, failed)]) | ||
| sub_info, sub_status = self.apply_business_rules( | ||
| submission_info=submission_info, failed=failed | ||
| ) | ||
| else: | ||
| sub_status = SubmissionStatus(failed=True) | ||
| self._audit_tables.mark_error_report( | ||
| submissions=[(sub_id, sub_status.submission_result)] | ||
| ) | ||
| sub_info, sub_status, sub_stats, report_uri = self.error_report( | ||
| submission_info=submission_info, status=sub_status | ||
| ) | ||
| self._audit_tables.add_submission_statistics_records(sub_stats=[sub_stats]) | ||
| except Exception as err: # pylint: disable=W0718 | ||
| self._logger.error( | ||
| f"During processing of submission_id: {sub_id}, the following exception was raised: {err}" | ||
| ) | ||
| self._audit_tables.mark_failed(submissions=[sub_id]) | ||
| finally: | ||
| audit_files_uri = self.persist_audit_records(submission_info=submission_info) | ||
| return ( | ||
| ( | ||
| None | ||
| if sub_status.failed | ||
| else fh.joinuri(self.processed_files_path, sub_id, "business_rules") | ||
| ), | ||
| report_uri, | ||
| audit_files_uri, | ||
| ) | ||
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
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
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
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
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
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
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.