|
23 | 23 |
|
24 | 24 | from pyiceberg.catalog import Catalog
|
25 | 25 | from pyiceberg.exceptions import NoSuchTableError
|
| 26 | +from pyiceberg.expressions import And, EqualTo, Reference |
| 27 | +from pyiceberg.expressions.literals import LongLiteral |
26 | 28 | from pyiceberg.schema import Schema
|
27 | 29 | from pyiceberg.table import UpsertResult
|
| 30 | +from pyiceberg.table.upsert_util import create_match_filter |
28 | 31 | from pyiceberg.types import IntegerType, NestedField, StringType
|
29 | 32 | from tests.catalog.test_base import InMemoryCatalog, Table
|
30 | 33 |
|
@@ -366,3 +369,22 @@ def test_upsert_with_identifier_fields(catalog: Catalog) -> None:
|
366 | 369 |
|
367 | 370 | assert upd.rows_updated == 1
|
368 | 371 | assert upd.rows_inserted == 1
|
| 372 | + |
| 373 | + |
| 374 | +def test_create_match_filter_single_condition() -> None: |
| 375 | + """ |
| 376 | + Test create_match_filter with a composite key where the source yields exactly one unique key. |
| 377 | + Expected: The function returns the single And condition directly. |
| 378 | + """ |
| 379 | + |
| 380 | + data = [ |
| 381 | + {"order_id": 101, "order_line_id": 1, "extra": "x"}, |
| 382 | + {"order_id": 101, "order_line_id": 1, "extra": "x"}, # duplicate |
| 383 | + ] |
| 384 | + schema = pa.schema([pa.field("order_id", pa.int32()), pa.field("order_line_id", pa.int32()), pa.field("extra", pa.string())]) |
| 385 | + table = pa.Table.from_pylist(data, schema=schema) |
| 386 | + expr = create_match_filter(table, ["order_id", "order_line_id"]) |
| 387 | + assert expr == And( |
| 388 | + EqualTo(term=Reference(name="order_id"), literal=LongLiteral(101)), |
| 389 | + EqualTo(term=Reference(name="order_line_id"), literal=LongLiteral(1)), |
| 390 | + ) |
0 commit comments