-
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
Merged
Merged
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
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.
Uh oh!
There was an error while loading. Please reload this page.