jiayuasu opened a new issue, #2927:
URL: https://github.com/apache/sedona/issues/2927

   Follow-up to the Phase 1 Box2D epic (#2877).
   
   ## Scope
   
   Register a Catalyst implicit cast from `Geometry` (`GeometryUDT`) to `Box2D` 
(`Box2DUDT`). Today users have to call `ST_Box2D(geom)` explicitly to convert; 
with this in place, `CAST(geom AS box2d)` and implicit conversion in function 
dispatch would just work.
   
   ## Why this is its own issue
   
   Spark Catalyst's implicit cast resolution is not trivially extensible for 
UDT-to-UDT casts. The existing `ST_GeomFromBox2D(box)` (the inverse direction) 
is also exposed as a function — see #2885 — for the same reason. Registering a 
real Catalyst cast requires:
   
   1. Extending `Cast.canCast` (or its modern equivalent) to recognize 
`GeometryUDT -> Box2DUDT`.
   2. Wiring the conversion logic through the Catalyst code-gen path (or 
`CodegenFallback`).
   3. Verifying the cast respects null propagation, expression equality, and 
Catalyst optimization rules.
   4. Validating it doesn't conflict with Spark's own type coercion rules in 
unexpected ways.
   
   This is heavy enough to be deferred from Phase 1 and worth its own design 
pass.
   
   ## Implementation notes
   
   - The conversion logic is already implemented in `Box2D.fromGeometry` and 
the SQL-level `ST_Box2D` expression — the cast just needs to wire that into 
Catalyst.
   - Round-trip with the inverse direction: `CAST(box AS geometry)` (today 
exposed only as `ST_GeomFromBox2D` — could be promoted to a real cast in the 
same change).
   - Tests should cover: explicit `CAST(geom AS box2d)`, implicit cast in 
function dispatch (e.g., `ST_XMin(geom_col)` should not need an explicit 
`ST_Box2D` wrap if the user wants Box2D semantics — though we should be careful 
not to surprise users; the geometry-arg overload should remain the default).
   
   ## Open question
   
   Whether to register the inverse cast (`Box2D -> Geometry`, currently exposed 
via `ST_GeomFromBox2D`) at the Catalyst level too, in the same change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to