Commit 10b74c3
fix: cast join cols to canonical Arrow types in Table.merge() (#11)
pa.Table.join is strict about the small-vs-large variant pair
(string vs large_string, binary vs large_binary). Both variants
are semantically the same Iceberg type but pyarrow.join refuses to
bridge them. ArrowScan and a user-built dataframe can disagree on
which variant they produce - pandas->arrow typically yields the small
variant while ArrowScan returns whichever variant the parquet
metadata implies. This caused merge() to fail at the anti-join with:
ArrowInvalid: Incompatible data types for corresponding join
field keys: FieldRef.Name(<col>) of type string and
FieldRef.Name(<col>) of type large_string
The original merge() tests only exercised int32 join columns, which
is the only type with no small/large variant pair, so this slipped
through.
Fix: before the anti-join, cast the join columns on both target_data
and the source df to the canonical Iceberg-derived Arrow form via
``self.table_metadata.schema().as_arrow()``. Mirrors what
ArrowProjectionVisitor._cast_if_needed does internally per pa.Array,
applied at the pa.Table level.
Source NULL and NaN values in join columns continue to be rejected
by the In predicate constructor (which forbids NULL and NaN literals).
Target rows with NULL/NaN keys are correctly preserved by the
anti-join since their keys cannot match any source key under SQL
three-valued logic / IEEE 754 semantics.
Tests: tests/table/test_merge.py covers string/binary variant drift
on join cols (every direction), composite keys with drift, edge values
(empty, unicode, embedded NULs, long strings, high-bit bytes), NULL/NaN
handling, and row-preservation / atomicity invariants.
Co-authored-by: Ayush Patel <Ayush.Patel@imc.com>1 parent 4b7d642 commit 10b74c3
2 files changed
Lines changed: 1701 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
963 | 963 | | |
964 | 964 | | |
965 | 965 | | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
966 | 982 | | |
967 | 983 | | |
968 | 984 | | |
| |||
991 | 1007 | | |
992 | 1008 | | |
993 | 1009 | | |
994 | | - | |
| 1010 | + | |
995 | 1011 | | |
996 | 1012 | | |
997 | 1013 | | |
| |||
0 commit comments