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

   ## Description
   
   Applying a geography scalar function to the output of a **geography spatial 
join** fails with:
   
   ```
   SedonaError: SedonaCScalarKernelImpl::execute failed: Array input must not 
be empty
   ```
   
   The join itself is correct — it is only the scalar kernel layered on top 
that fails. It looks like the spatial join emits zero-row batches and the 
geography scalar kernels reject an empty array instead of returning an empty 
result.
   
   ## Reproduction
   
   Self-contained, no external data (`sedonadb` 0.4.0, `__features__ == 
['s2geography']`):
   
   ```python
   import json, sedonadb
   
   sd = sedonadb.connect()
   
   # Tiny polygons scattered over a wide area -> a very selective self-join.
   opts = json.dumps({"geom_type": "Polygon", "num_vertices": [4, 8],
                      "bounds": [-170, -80, 170, 80], "size": [0.0005, 0.002], 
"seed": 42})
   sd.sql(f"SELECT id, ST_GeogFromWKB(ST_AsBinary(geometry)) AS geog "
          f"FROM sd_random_geometry('{opts}') LIMIT 5000").to_view("a", 
overwrite=True)
   sd.sql("SELECT id, geog FROM a").to_view("b", overwrite=True)
   
   # 1. The join alone is fine
   sd.sql("SELECT COUNT(*) FROM a JOIN b ON a.id < b.id AND 
ST_Intersects(a.geog, b.geog)").to_pandas()
   # -> 0
   
   # 2. Any geography scalar function over the join output fails
   sd.sql("""SELECT COUNT(*), SUM(ST_Area(a.geog))
             FROM a JOIN b ON a.id < b.id AND ST_Intersects(a.geog, 
b.geog)""").to_pandas()
   # -> SedonaError: SedonaCScalarKernelImpl::execute failed: Array input must 
not be empty
   ```
   
   `ST_Area`, `ST_Intersection` and `ST_Distance` all fail the same way, on 
either side of the join.
   
   ## What narrows it down
   
   | Case | Result |
   |---|---|
   | Geography spatial join, `COUNT(*)` only | ✅ |
   | Geography spatial join + `ST_Area` over its output | ❌ `Array input must 
not be empty` |
   | Geography spatial join + `ST_Intersection` over its output | ❌ same |
   | Geography spatial join + `ST_Distance` over its output | ❌ same |
   | **Equi**-join (`a.id = b.id + 999999`) with 0 matching rows + `ST_Area` | 
✅ returns `0, NaN` |
   | Dense geography spatial join (2256 matches) + `ST_Area` | ✅ |
   | Geography scalar over an empty scan (`WHERE 1 = 0`, `LIMIT 0`) | ✅ |
   | Same query on `ST_GeomFromWKB` instead of `ST_GeogFromWKB` | ✅ |
   
   So it is specific to the geography **spatial join** operator's output 
batches — an empty non-spatial join and an empty table scan both behave 
correctly, and the geometry path is unaffected.
   
   ## Impact
   
   This blocks the geography version of SpatialBench Q9 (building overlap / 
IoU). At SF1 the geography self-join finds exactly the same 37 building pairs 
as the geometry query, but adding `ST_Area(ST_Intersection(...))` on top errors 
out, so the query cannot complete. The geometry equivalent runs fine.
   
   ## Environment
   
   - `sedonadb` 0.4.0 (PyPI wheel), Python 3.13, macOS arm64
   - `sedonadb.__features__ == ['s2geography']`
   


-- 
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