sungwy commented on code in PR #2050: URL: https://github.com/apache/iceberg-python/pull/2050#discussion_r2112948288
########## pyiceberg/table/update/validate.py: ########## @@ -24,7 +24,8 @@ from pyiceberg.table.snapshots import Operation, Snapshot, ancestors_between from pyiceberg.typedef import Record -VALIDATE_DATA_FILES_EXIST_OPERATIONS = {Operation.OVERWRITE, Operation.REPLACE, Operation.DELETE} +VALIDATE_DATA_FILES_EXIST_OPERATIONS: Set[Operation] = {Operation.OVERWRITE, Operation.REPLACE, Operation.DELETE} +VALIDATE_ADDED_FILES_OPERATIONS: Set[Operation] = {Operation.APPEND, Operation.OVERWRITE} Review Comment: I know Java uses this name, but I'd like to make an argument for us to be more specific about the files we are referring to since we are naming this constant for the first time in PyIceberg: ```suggestion VALIDATE_ADDED_DATA_FILES_OPERATIONS: Set[Operation] = {Operation.APPEND, Operation.OVERWRITE} ``` ########## pyiceberg/table/update/validate.py: ########## @@ -150,3 +151,54 @@ def _validate_deleted_data_files( if any(conflicting_entries): conflicting_snapshots = {entry.snapshot_id for entry in conflicting_entries} raise ValidationException(f"Deleted data files were found matching the filter for snapshots {conflicting_snapshots}!") + + +def _added_data_files( + table: Table, + starting_snapshot: Snapshot, + data_filter: Optional[BooleanExpression], + partition_set: Optional[dict[int, set[Record]]], + parent_snapshot: Optional[Snapshot], +) -> Iterator[ManifestEntry]: + if parent_snapshot is None: + return + + manifests, snapshot_ids = validation_history( + table, + parent_snapshot, + starting_snapshot, + VALIDATE_ADDED_FILES_OPERATIONS, + ManifestContent.DATA, + ) + + if data_filter is not None: + evaluator = _InclusiveMetricsEvaluator(table.schema(), data_filter) + + for manifest in manifests: + for entry in manifest.fetch_manifest_entry(table.io): + if entry.snapshot_id not in snapshot_ids: + continue + + if data_filter and evaluator.eval(entry.data_file) is ROWS_CANNOT_MATCH: Review Comment: nit: there's a lot of duplicated code between `_deleted_data_files` and `_added_data_files`. Is there a way we could refactor the code block here to prevent that? ########## pyiceberg/table/update/validate.py: ########## @@ -150,3 +151,54 @@ def _validate_deleted_data_files( if any(conflicting_entries): conflicting_snapshots = {entry.snapshot_id for entry in conflicting_entries} raise ValidationException(f"Deleted data files were found matching the filter for snapshots {conflicting_snapshots}!") + + +def _added_data_files( + table: Table, + starting_snapshot: Snapshot, + data_filter: Optional[BooleanExpression], + partition_set: Optional[dict[int, set[Record]]], + parent_snapshot: Optional[Snapshot], +) -> Iterator[ManifestEntry]: + if parent_snapshot is None: Review Comment: Could we introduce a doc string for each function? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org