Skip to content

Commit 1a0beb6

Browse files
refactor: remove original entities (#164)
redundant in the grand scheme of things and was increasing the I/O overhead
1 parent 21043db commit 1a0beb6

7 files changed

Lines changed: 18 additions & 32 deletions

File tree

‎src/dve/core_engine/backends/base/contract.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,6 @@ def apply(
443443
],
444444
)
445445

446-
if contract_metadata.cache_originals:
447-
for entity_name in list(entities):
448-
entities[f"Original{entity_name}"] = entities[entity_name]
449-
450446
return entities, feedback_errors_uri, successful, processing_errors_uri
451447

452448
def read_parquet(self, path: URI, **kwargs) -> EntityType:

‎src/dve/core_engine/backends/metadata/contract.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DataContractMetadata(BaseModel, frozen=True, arbitrary_types_allowed=True)
3535
reporting_fields: dict[EntityName, ReportingFields]
3636
"""The per-entity reporting fields."""
3737
cache_originals: bool = False
38-
"""Whether to cache the original entities after loading."""
38+
"""WARNING - Depreciated functionality. Whether to cache the original entities after loading."""
3939
_schemas: dict[EntityName, type[BaseModel]] = PrivateAttr(default_factory=dict)
4040
"""The pydantic models of the schmas."""
4141

‎src/dve/core_engine/configuration/v1/__init__.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class V1DataContractConfig(BaseModel):
207207
"""Configuration for the data contract component of the dataset."""
208208

209209
cache_originals: bool = False
210-
"""Whether to cache the original entities after loading."""
210+
"""WARNING - Depreciated functionality. Whether to cache the original entities after loading."""
211211
error_details: Optional[URI] = None
212212
"""Optional URI containing custom data contract error codes and messages"""
213213
types: dict[TypeName, TypeOrDef] = Field(default_factory=dict)
@@ -402,7 +402,6 @@ def get_contract_metadata(self) -> DataContractMetadata:
402402
reader_metadata=reader_metadata,
403403
validators=validators,
404404
reporting_fields=reporting_fields,
405-
cache_originals=self.contract.cache_originals,
406405
)
407406

408407
def load_error_message_info(self, uri):

‎src/dve/metadata_parser/models.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ class DatasetSpecification(BaseModel):
391391
"""Configuration options for a dataset."""
392392

393393
cache_originals: bool = False
394+
"""WARNING - Depreciated functionality."""
394395
types: dict[TypeName, FieldSpecification] = Field(default_factory=dict)
395396
"""Predefined types to be used within schema/dataset definitions."""
396397
schemas: dict[EntityName, EntitySpecification] = Field(default_factory=dict)

‎src/dve/pipeline/pipeline.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ def apply_business_rules( # pylint: disable=R0914,R0915
624624
entities[file_name] = self.step_implementations.add_record_index( # type: ignore
625625
self.step_implementations.read_parquet(parquet_uri) # type: ignore
626626
)
627-
entities[f"Original{file_name}"] = self.step_implementations.read_parquet(parquet_uri) # type: ignore
628627

629628
sub_info_entity = (
630629
self._audit_tables._submission_info.conv_to_entity( # pylint: disable=protected-access
@@ -660,15 +659,11 @@ def apply_business_rules( # pylint: disable=R0914,R0915
660659
for entity_name, entity in entity_manager.entities.items():
661660
# Note BI filtering done within the apply_rules
662661
self._logger.info(f"applying data contract filter to {entity_name}.")
663-
if not entity_name.startswith("Original"):
664-
filtered_entity = self._step_implementations.filter_data_contract_record_rejections(
665-
working_directory,
666-
entity,
667-
entity_name,
668-
)
669-
else:
670-
self._logger.info(f"Skipping {entity_name}. Marked original.")
671-
filtered_entity = entity
662+
filtered_entity = self._step_implementations.filter_data_contract_record_rejections(
663+
working_directory,
664+
entity,
665+
entity_name,
666+
)
672667
projected = self._step_implementations.write_parquet( # type: ignore
673668
filtered_entity,
674669
fh.joinuri(
@@ -769,9 +764,14 @@ def apply_business_rules( # pylint: disable=R0914,R0915
769764
)
770765

771766
submission_status.number_of_records = self.get_entity_count(
772-
entity=entity_manager.entities[f"""Original{rules.global_variables.get(
773-
'entity',
774-
submission_info.dataset_id)}"""]
767+
entity=self.step_implementations.read_parquet( # type: ignore
768+
fh.joinuri(
769+
self.processed_files_path,
770+
submission_info.submission_id,
771+
"data_contract",
772+
rules.global_variables.get('entity', submission_info.dataset_id)
773+
)
774+
)
775775
)
776776
submission_status.number_of_records_rejected = (
777777
submission_status.number_of_records

‎tests/test_pipeline/test_foundry_ddb_pipeline.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_foundry_runner_validation_success(movies_test_files, temp_ddb_conn):
102102
)
103103
output_loc, report_uri, audit_files = dve_pipeline.run_pipeline(sub_info)
104104
assert fh.get_resource_exists(report_uri)
105-
assert len(list(fh.iter_prefix(output_loc))) == 2
105+
assert len(list(fh.iter_prefix(output_loc))) == 1
106106
assert len(list(fh.iter_prefix(audit_files))) == 3
107107

108108
def test_foundry_runner_error(planet_test_files, temp_ddb_conn):
@@ -197,7 +197,7 @@ def test_foundry_runner_with_submitted_files_path(movies_test_files, temp_ddb_co
197197

198198
assert Path(processing_folder, sub_id, sub_info.file_name_with_ext).exists()
199199
assert fh.get_resource_exists(report_uri)
200-
assert len(list(fh.iter_prefix(output_loc))) == 2
200+
assert len(list(fh.iter_prefix(output_loc))) == 1
201201
assert len(list(fh.iter_prefix(audit_files))) == 3
202202

203203

‎tests/test_pipeline/test_spark_pipeline.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,6 @@ def test_apply_business_rules_success(
274274
assert largest_satellites_entity_path.exists()
275275
assert spark.read.parquet(str(largest_satellites_entity_path)).count() == 1
276276

277-
og_planets_entity_path = Path(
278-
Path(processed_file_path), sub_info.submission_id, "business_rules", "Originalplanets"
279-
)
280-
assert og_planets_entity_path.exists()
281-
assert spark.read.parquet(str(og_planets_entity_path)).count() == 1
282-
283277

284278
def test_apply_business_rules_with_data_errors( # pylint: disable=redefined-outer-name
285279
spark: SparkSession,
@@ -317,10 +311,6 @@ def test_apply_business_rules_with_data_errors( # pylint: disable=redefined-out
317311
assert largest_satellites_entity_path.exists()
318312
assert spark.read.parquet(str(largest_satellites_entity_path)).count() == 1
319313

320-
og_planets_entity_path = br_path / "Originalplanets"
321-
assert og_planets_entity_path.exists()
322-
assert spark.read.parquet(str(og_planets_entity_path)).count() == 1
323-
324314
errors_path = Path(br_path.parent, "errors", "business_rules_errors.jsonl")
325315
assert errors_path.exists()
326316

0 commit comments

Comments
 (0)