|
21 | 21 | - _anti_join_tables struct-array O(n+m) multi-column join correctness |
22 | 22 | - NULL handling with IS NOT DISTINCT FROM semantics |
23 | 23 | - Full InMemoryCatalog round-trip through pluggable backend |
| 24 | +- _extract_filter_columns regex correctness for filter column safeguard |
24 | 25 | """ |
25 | 26 |
|
26 | 27 | from __future__ import annotations |
|
38 | 39 | from pyiceberg.schema import Schema |
39 | 40 | from pyiceberg.types import IntegerType, LongType, NestedField, StringType |
40 | 41 |
|
| 42 | +# ============================================================================= |
| 43 | +# _extract_filter_columns correctness (for partition column safeguard) |
| 44 | +# ============================================================================= |
| 45 | + |
| 46 | + |
| 47 | +class TestExtractFilterColumns: |
| 48 | + """_extract_filter_columns must correctly extract column names from PyArrow expressions. |
| 49 | +
|
| 50 | + This is critical for the safeguard in read_parquet() that prevents pushing filters |
| 51 | + to the scanner when they reference columns not in the file (e.g., partition columns). |
| 52 | + """ |
| 53 | + |
| 54 | + def test_simple_equality(self) -> None: |
| 55 | + """Extract column from simple equality expression.""" |
| 56 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 57 | + |
| 58 | + expr = pc.field("partition_id") == 1 |
| 59 | + columns = _extract_filter_columns(expr) |
| 60 | + assert columns == {"partition_id"} |
| 61 | + |
| 62 | + def test_simple_comparison(self) -> None: |
| 63 | + """Extract column from comparison expression.""" |
| 64 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 65 | + |
| 66 | + expr = pc.field("id") > 5 |
| 67 | + columns = _extract_filter_columns(expr) |
| 68 | + assert columns == {"id"} |
| 69 | + |
| 70 | + def test_multiple_columns_and(self) -> None: |
| 71 | + """Extract multiple columns from AND expression.""" |
| 72 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 73 | + |
| 74 | + expr = (pc.field("a") == 1) & (pc.field("b") == 2) |
| 75 | + columns = _extract_filter_columns(expr) |
| 76 | + assert columns == {"a", "b"} |
| 77 | + |
| 78 | + def test_multiple_columns_or(self) -> None: |
| 79 | + """Extract multiple columns from OR expression.""" |
| 80 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 81 | + |
| 82 | + expr = (pc.field("x") < 10) | (pc.field("y") > 20) |
| 83 | + columns = _extract_filter_columns(expr) |
| 84 | + assert columns == {"x", "y"} |
| 85 | + |
| 86 | + def test_complex_nested(self) -> None: |
| 87 | + """Extract columns from complex nested expression.""" |
| 88 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 89 | + |
| 90 | + expr = ((pc.field("a") == 1) & (pc.field("b") == 2)) | (pc.field("c") > 3) |
| 91 | + columns = _extract_filter_columns(expr) |
| 92 | + assert columns == {"a", "b", "c"} |
| 93 | + |
| 94 | + def test_same_column_multiple_times(self) -> None: |
| 95 | + """Same column referenced multiple times returns single entry.""" |
| 96 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 97 | + |
| 98 | + expr = (pc.field("id") > 5) & (pc.field("id") < 10) |
| 99 | + columns = _extract_filter_columns(expr) |
| 100 | + assert columns == {"id"} |
| 101 | + |
| 102 | + def test_isin_expression(self) -> None: |
| 103 | + """Extract column from is_in expression.""" |
| 104 | + from pyiceberg.execution.backends.pyarrow_backend import _extract_filter_columns |
| 105 | + |
| 106 | + expr = pc.field("category").isin(["a", "b", "c"]) |
| 107 | + columns = _extract_filter_columns(expr) |
| 108 | + assert columns == {"category"} |
| 109 | + |
| 110 | + |
41 | 111 | # ============================================================================= |
42 | 112 | # Multi-column anti-join correctness (O(n+m) struct-array approach) |
43 | 113 | # ============================================================================= |
|
0 commit comments