forked from apache/iceberg-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validate.py
More file actions
67 lines (57 loc) · 2.78 KB
/
test_validate.py
File metadata and controls
67 lines (57 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint:disable=redefined-outer-name,eval-used
from typing import cast
from unittest.mock import patch
from pyiceberg.io import FileIO
from pyiceberg.manifest import ManifestContent, ManifestFile
from pyiceberg.table import Table
from pyiceberg.table.snapshots import Operation, Snapshot
from pyiceberg.table.update.validate import validation_history
def test_validation_history(table_v2_with_extensive_snapshots: Table) -> None:
"""Test the validation history function."""
mock_manifests = {}
for i, snapshot in enumerate(table_v2_with_extensive_snapshots.snapshots()):
mock_manifest = ManifestFile(
manifest_path=f"foo/bar/{i}",
manifest_length=1,
partition_spec_id=1,
content=ManifestContent.DATA if i % 2 == 0 else ManifestContent.DELETES,
sequence_number=1,
min_sequence_number=1,
added_snapshot_id=snapshot.snapshot_id,
)
# Store the manifest for this specific snapshot
mock_manifests[snapshot.snapshot_id] = [mock_manifest]
expected_manifest_data_counts = len([m for m in mock_manifests.values() if m[0].content == ManifestContent.DATA]) - 1
oldest_snapshot = table_v2_with_extensive_snapshots.snapshots()[0]
newest_snapshot = cast(Snapshot, table_v2_with_extensive_snapshots.current_snapshot())
def mock_read_manifest_side_effect(self: Snapshot, io: FileIO) -> list[ManifestFile]:
"""Mock the manifests method to use the snapshot_id for lookup."""
snapshot_id = self.snapshot_id
if snapshot_id in mock_manifests:
return mock_manifests[snapshot_id]
return []
with patch("pyiceberg.table.snapshots.Snapshot.manifests", new=mock_read_manifest_side_effect):
manifests, snapshots = validation_history(
table_v2_with_extensive_snapshots,
newest_snapshot,
oldest_snapshot,
{Operation.APPEND},
ManifestContent.DATA,
)
assert len(manifests) == expected_manifest_data_counts