|
14 | 14 | # KIND, either express or implied. See the License for the |
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | | -import copy |
18 | 17 | import math |
19 | | -import threading |
20 | 18 | from abc import ABC, abstractmethod |
21 | | -from collections.abc import Callable, Hashable |
| 19 | +from collections.abc import Callable |
22 | 20 | from functools import singledispatch |
23 | 21 | from typing import ( |
24 | 22 | Any, |
|
27 | 25 | TypeVar, |
28 | 26 | ) |
29 | 27 |
|
30 | | -from cachetools import LRUCache, cached |
31 | | -from cachetools.keys import hashkey |
32 | | - |
33 | 28 | from pyiceberg.conversions import from_bytes |
34 | 29 | from pyiceberg.expressions import ( |
35 | 30 | AlwaysFalse, |
@@ -1975,37 +1970,17 @@ def residual_for(self, partition_data: Record) -> BooleanExpression: |
1975 | 1970 | return self.expr |
1976 | 1971 |
|
1977 | 1972 |
|
1978 | | -_DEFAULT_RESIDUAL_EVALUATOR_CACHE_SIZE = 128 |
1979 | | - |
1980 | | - |
1981 | | -def _residual_evaluator_cache_key( |
1982 | | - spec: PartitionSpec, expr: BooleanExpression, case_sensitive: bool, schema: Schema |
1983 | | -) -> tuple[Hashable, ...]: |
1984 | | - return hashkey(spec.spec_id, repr(expr), case_sensitive, schema.schema_id) |
1985 | | - |
1986 | | - |
1987 | | -@cached( |
1988 | | - cache=LRUCache(maxsize=_DEFAULT_RESIDUAL_EVALUATOR_CACHE_SIZE), |
1989 | | - key=_residual_evaluator_cache_key, |
1990 | | - lock=threading.RLock(), |
1991 | | -) |
1992 | | -def _cached_residual_evaluator_template( |
1993 | | - spec: PartitionSpec, expr: BooleanExpression, case_sensitive: bool, schema: Schema |
1994 | | -) -> ResidualEvaluator: |
1995 | | - return ( |
1996 | | - UnpartitionedResidualEvaluator(schema=schema, expr=expr) |
1997 | | - if spec.is_unpartitioned() |
1998 | | - else ResidualEvaluator(spec=spec, expr=expr, schema=schema, case_sensitive=case_sensitive) |
1999 | | - ) |
2000 | | - |
2001 | | - |
2002 | 1973 | def residual_evaluator_of( |
2003 | 1974 | spec: PartitionSpec, expr: BooleanExpression, case_sensitive: bool, schema: Schema |
2004 | 1975 | ) -> ResidualEvaluator: |
2005 | 1976 | """Create a residual evaluator. |
2006 | 1977 |
|
2007 | | - Always returns a fresh evaluator instance because evaluators are stateful |
| 1978 | + Returns a fresh evaluator instance because evaluators are stateful |
2008 | 1979 | (they set `self.struct` during evaluation) and may be used from multiple |
2009 | 1980 | threads. |
2010 | 1981 | """ |
2011 | | - return copy.copy(_cached_residual_evaluator_template(spec=spec, expr=expr, case_sensitive=case_sensitive, schema=schema)) |
| 1982 | + return ( |
| 1983 | + UnpartitionedResidualEvaluator(schema=schema, expr=expr) |
| 1984 | + if spec.is_unpartitioned() |
| 1985 | + else ResidualEvaluator(spec=spec, expr=expr, schema=schema, case_sensitive=case_sensitive) |
| 1986 | + ) |
0 commit comments