Skip to content

Commit 0693583

Browse files
refactor: change submission rejection to file rejection in the error reports (#119)
* refactor: change submission rejection to file rejection in the error reports
1 parent 9175588 commit 0693583

5 files changed

Lines changed: 39 additions & 10 deletions

File tree

src/dve/pipeline/pipeline.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from dve.parser.file_handling.implementations.file import LocalFilesystemImplementation
4343
from dve.parser.file_handling.service import _get_implementation
4444
from dve.pipeline.utils import SubmissionStatus, deadletter_file, load_config, load_reader
45+
from dve.reporting.constants import ErrorReportStatus
4546
from dve.reporting.error_report import ERROR_SCHEMA, calculate_aggregates
4647

4748
PERMISSIBLE_EXCEPTIONS: tuple[type[Exception]] = (
@@ -764,8 +765,8 @@ def _get_error_dataframes(self, submission_id: str):
764765
pl.when(pl.col("Status") == pl.lit("informational"))
765766
.then(pl.lit("Warning"))
766767
.when(pl.col("FailureType") == pl.lit("submission")) # type: ignore
767-
.then(pl.lit("Submission Failure")) # type: ignore
768-
.otherwise(pl.lit("Record Rejection")) # type: ignore
768+
.then(pl.lit(ErrorReportStatus.FILE_REJECTION.reporting_name)) # type: ignore
769+
.otherwise(pl.lit(ErrorReportStatus.RECORD_REJECTION.reporting_name)) # type: ignore
769770
.alias("error_type") # type: ignore
770771
)
771772
df = df.select(
@@ -828,9 +829,13 @@ def error_report(
828829
sub_stats = SubmissionStatisticsRecord(
829830
submission_id=submission_info.submission_id,
830831
record_count=submission_status.number_of_records,
831-
number_submission_rejections=err_types.get("Submission Failure", 0),
832-
number_record_rejections=err_types.get("Record Rejection", 0),
833-
number_warnings=err_types.get("Warning", 0),
832+
number_submission_rejections=err_types.get(
833+
ErrorReportStatus.FILE_REJECTION.reporting_name, 0
834+
),
835+
number_record_rejections=err_types.get(
836+
ErrorReportStatus.RECORD_REJECTION.reporting_name, 0
837+
),
838+
number_warnings=err_types.get(ErrorReportStatus.WARNING.reporting_name, 0),
834839
)
835840

836841
summary_dict = {
@@ -841,7 +846,7 @@ def error_report(
841846
summary_items = er.SummaryItems(
842847
submission_status=submission_status,
843848
summary_dict=summary_dict,
844-
row_headings=["Submission Failure", "Record Rejection", "Warning"],
849+
row_headings=[e.reporting_name for e in ErrorReportStatus],
845850
)
846851

847852
workbook = er.ExcelFormat(

src/dve/reporting/constants.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Constants used within the error reports
3+
"""
4+
5+
from enum import Enum
6+
7+
8+
class ErrorReportStatus(Enum):
9+
"""
10+
Constant to centrally hold error report status.
11+
"""
12+
13+
FILE_REJECTION = 1, "File Rejection"
14+
RECORD_REJECTION = 2, "Record Rejection"
15+
WARNING = 3, "Warning"
16+
17+
@property
18+
def reporting_name(self):
19+
"""
20+
The error report 'friendly' name.
21+
"""
22+
return self.value[1]

src/dve/reporting/error_report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from dve.common.error_utils import conditional_cast
1212
from dve.core_engine.message import FeedbackMessage
1313
from dve.parser.file_handling.service import open_stream
14+
from dve.reporting.constants import ErrorReportStatus
1415

1516
ERROR_SCHEMA = {
1617
"Table": Utf8(),
@@ -85,7 +86,7 @@ def create_error_dataframe(errors: deque[FeedbackMessage], key_fields):
8586

8687
df = df.with_columns( # type: ignore
8788
pl.when(pl.col("Status") == pl.lit("error")) # type: ignore
88-
.then(pl.lit("Submission Failure")) # type: ignore
89+
.then(pl.lit(ErrorReportStatus.FILE_REJECTION.reporting_name)) # type: ignore
8990
.otherwise(pl.lit("Warning")) # type: ignore
9091
.alias("error_type")
9192
)

src/dve/reporting/excel_report.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from polars.exceptions import ColumnNotFoundError
1818

1919
from dve.pipeline.utils import SubmissionStatus
20+
from dve.reporting.constants import ErrorReportStatus
2021

2122

2223
@dataclass
@@ -97,9 +98,9 @@ def get_submission_status(self, aggregates: DataFrame) -> str:
9798
if aggregates.is_empty():
9899
return "File has been accepted, no issues to report"
99100
failures = aggregates["Type"].unique()
100-
if "Submission Failure" in failures:
101+
if ErrorReportStatus.FILE_REJECTION.reporting_name in failures:
101102
status = "File has been rejected"
102-
elif "Warning" in failures:
103+
elif ErrorReportStatus.WARNING.reporting_name in failures:
103104
status = "File has been accepted, all records accepted with warnings"
104105
else:
105106
status = "File has been accepted, no issues to report"

tests/test_pipeline/test_spark_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_error_report_where_report_is_expected( # pylint: disable=redefined-out
440440
("File Name", "doesnotmatter"),
441441
("File Extension", "json"),
442442
("Total Number of Records Processed", "9"),
443-
("Submission Failure", "0"),
443+
("File Rejection", "0"),
444444
("Record Rejection", "2"),
445445
("Warning", "0"),
446446
]

0 commit comments

Comments
 (0)