-
Notifications
You must be signed in to change notification settings - Fork 2
Bug/ndit 868 #32
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
Open
stevenhsd
wants to merge
4
commits into
main
Choose a base branch
from
bug/ndit-868
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+181
−10
Open
Bug/ndit 868 #32
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4a3f89d
feat: Added new option to check csv headers in duckdb csv readers
stevenhsd 5dfbafc
refactor: small changes to foundry pipeline and duckdb csv to fix hea…
stevenhsd 0191dd3
feat: Added new check to base reader for sense check of whether proce…
stevenhsd b3fc0d8
refactor: Address review comments
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,21 @@ | ||
| """General utilities for file readers""" | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from dve.core_engine.type_hints import URI | ||
| from dve.parser.file_handling.service import open_stream | ||
|
|
||
|
|
||
| def check_csv_header_expected( | ||
| resource: URI, | ||
| expected_schema: type[BaseModel], | ||
| delimiter: Optional[str] = ",", | ||
| quote_char: str = '"', | ||
| ) -> set[str]: | ||
| """Check the header of a CSV matches the expected fields""" | ||
| with open_stream(resource) as fle: | ||
| header_fields = fle.readline().rstrip().replace(quote_char, "").split(delimiter) | ||
| expected_fields = expected_schema.__fields__.keys() | ||
| return set(expected_fields).difference(header_fields) |
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 |
|---|---|---|
|
|
@@ -109,6 +109,8 @@ def error_report( | |
| self._logger.exception(exc) | ||
| sub_stats = None | ||
| report_uri = None | ||
| submission_status = submission_status if submission_status else SubmissionStatus() | ||
| submission_status.processing_failed = True | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. build a submission status if there isn't a submission status. Then you don't need if sub_stats on line 152. Check the error_report child method to check if there any scenarios where the submission_status is returned. |
||
| dump_processing_errors( | ||
| fh.joinuri(self.processed_files_path, submission_info.submission_id), | ||
| "error_report", | ||
|
|
@@ -148,7 +150,8 @@ def run_pipeline( | |
| sub_info, sub_status, sub_stats, report_uri = self.error_report( | ||
| submission_info=submission_info, submission_status=sub_status | ||
| ) | ||
| self._audit_tables.add_submission_statistics_records(sub_stats=[sub_stats]) | ||
| if sub_stats: | ||
| 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}, this exception was raised: {err}" | ||
|
|
||
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
55 changes: 55 additions & 0 deletions
55
tests/test_core_engine/test_backends/test_readers/test_utilities.py
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,55 @@ | ||
| import datetime as dt | ||
| from pathlib import Path | ||
| import tempfile | ||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| from pydantic import BaseModel, create_model | ||
|
|
||
| from dve.core_engine.backends.readers.utilities import check_csv_header_expected | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ["header_row", "delim", "schema", "expected"], | ||
| [ | ||
| ( | ||
| "field1,field2,field3", | ||
| ",", | ||
| {"field1": (str, ...), "field2": (int, ...), "field3": (float, 1.2)}, | ||
| set(), | ||
| ), | ||
| ( | ||
| "field2,field3,field1", | ||
| ",", | ||
| {"field1": (str, ...), "field2": (int, ...), "field3": (float, 1.2)}, | ||
| set(), | ||
| ), | ||
| ( | ||
| "str_field|int_field|date_field|", | ||
| ",", | ||
| {"str_field": (str, ...), "int_field": (int, ...), "date_field": (dt.date, dt.date.today())}, | ||
| {"str_field","int_field","date_field"}, | ||
| ), | ||
| ( | ||
| '"str_field"|"int_field"|"date_field"', | ||
| "|", | ||
| {"str_field": (str, ...), "int_field": (int, ...), "date_field": (dt.date, dt.date.today())}, | ||
| set(), | ||
| ), | ||
| ( | ||
| 'str_field,int_field,date_field\n', | ||
| ",", | ||
| {"str_field": (str, ...), "int_field": (int, ...), "date_field": (dt.date, dt.date.today())}, | ||
| set(), | ||
| ), | ||
|
|
||
| ], | ||
| ) | ||
| def test_check_csv_header_expected( | ||
| header_row: str, delim: str, schema: type[BaseModel], expected: set[str] | ||
| ): | ||
| mdl = create_model("TestModel", **schema) | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| fle = Path(tmpdir).joinpath(f"test_file_{uuid4().hex}.csv") | ||
| fle.open("w+").write(header_row) | ||
| res = check_csv_header_expected(fle.as_posix(), mdl, delim) | ||
| assert res == expected |
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.
think if we are adding these attributes then we need to add them to the docstrings explaining to the user what they are. Not as obvious vs existing attrs like header, delim etc.