Skip to content

Commit 243bbb9

Browse files
committed
Consolidate evaluator planning tests
1 parent 9d8155e commit 243bbb9

2 files changed

Lines changed: 30 additions & 67 deletions

File tree

tests/table/test_evaluator_planning.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pytest
2323

2424
import pyiceberg.table as table_module
25-
from pyiceberg.expressions import BooleanExpression, GreaterThan
25+
from pyiceberg.expressions import BooleanExpression, EqualTo, GreaterThan
2626
from pyiceberg.manifest import DataFile, FileFormat
2727
from pyiceberg.schema import Schema
2828
from pyiceberg.table import ManifestGroupPlanner, Table
@@ -63,3 +63,32 @@ def evaluate(struct: StructProtocol) -> bool:
6363
assert not partition_evaluator(_data_file(1, 1))
6464
assert partition_evaluator(_data_file(2, 10))
6565
assert evaluator_calls == [[1, 10]]
66+
67+
68+
def test_metrics_evaluator_prepares_once_per_plan(table_v2: Table, monkeypatch: pytest.MonkeyPatch) -> None:
69+
class CountingMetricsEvaluator:
70+
def __init__(
71+
self,
72+
schema: Schema,
73+
expr: BooleanExpression,
74+
case_sensitive: bool = True,
75+
include_empty_files: bool = False,
76+
) -> None:
77+
self.calls: list[DataFile] = []
78+
instances.append(self)
79+
80+
def eval(self, data_file: DataFile) -> bool:
81+
self.calls.append(data_file)
82+
return True
83+
84+
instances: list[CountingMetricsEvaluator] = []
85+
monkeypatch.setattr(table_module, "_InclusiveMetricsEvaluator", CountingMetricsEvaluator)
86+
planner = ManifestGroupPlanner(table_metadata=table_v2.metadata, io=table_v2.io, row_filter=EqualTo("x", 10))
87+
first_file = _data_file(1, 1)
88+
second_file = _data_file(2, 2)
89+
90+
metrics_evaluator = planner._build_metrics_evaluator()
91+
assert len(instances) == 1
92+
assert metrics_evaluator(first_file)
93+
assert metrics_evaluator(second_file)
94+
assert instances[0].calls == [first_file, second_file]

tests/table/test_metrics_evaluator_planning.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)