fix: coerce filter expressions before simplifying (#6935)
## Summary
Fix `Planner::optimize_expr` so expression type coercion runs before
simplification. This matches DataFusion's normal plan pipeline where
analyzer type coercion runs before optimizer simplification.
This matters for immutable UDFs with literal arguments. With the
previous order, simplification could evaluate a constant UDF call before
`Int64` literals were coerced to the UDF's expected `Float64` inputs.
For geospatial filters, `st_point(0, 0)` could reach the geo UDF as
integer arrays and panic during the UDF's strict float downcast.
`st_point(0.0, 0.0)` worked because the literals were already `Float64`.
## Repro Demo
This is a standalone Python repro script. It is not added to the repo.
```python
import tempfile
import lance
import numpy as np
import pyarrow as pa
from geoarrow.rust.core import point, points
def run_filter(ds, expr):
table = ds.to_table(filter=expr)
values = table.to_pydict()
print(f"{expr} -> {table.num_rows} rows: {values}")
assert table.num_rows == 1
with tempfile.TemporaryDirectory() as tmpdir:
point_array = points([np.array([1.0, 10.0]), np.array([2.0, 10.0])])
schema = pa.schema([pa.field(point("xy")).with_name("point")])
table = pa.Table.from_arrays([point_array], schema=schema)
ds = lance.write_dataset(table, f"{tmpdir}/geo_filter.lance")
run_filter(ds, "st_distance(point, st_point(0.0, 0.0)) < 5")
run_filter(ds, "st_distance(point, st_point(0, 0)) < 5")
```
Observed before the fix:
```text
st_distance(point, st_point(0.0, 0.0)) < 5 -> 1 rows: {'point': [{'x': 1.0, 'y': 2.0}]}
thread 'lance_background_thread' panicked at .../arrow-array-58.3.0/src/cast.rs:849:33:
primitive array
RuntimeError: Task was aborted
```
Observed after the fix:
```text
st_distance(point, st_point(0.0, 0.0)) < 5 -> 1 rows: {'point': [{'x': 1.0, 'y': 2.0}]}
st_distance(point, st_point(0, 0)) < 5 -> 1 rows: {'point': [{'x': 1.0, 'y': 2.0}]}
``` X
Xin Sun committed
c4e77647b182337facce0e6cf2459f3dff2de96a
Parent: 98390e1
Committed by GitHub <noreply@github.com>
on 5/26/2026, 6:56:36 AM