DuckDB: spatial join on a GEOMETRY column of an Arrow scan fails (EXPRESSION_FILTER pushdown) — draft for upstream
Mantenedores costumam responder em até 3 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 28/100
Direção de pesquisa
The report identifies DuckDB’s Python Arrow scan and SPATIAL_JOIN filter pushdown as the failure path, but this is a draft for upstream DuckDB rather than a change scoped to this repository. Start by checking the reported reproduction against DuckDB 1.5.5 with PyArrow 23.0.0; done means unsupported filters are skipped and applied after the scan, allowing the join to return 4. The issue also raises a separate CRS documentation mismatch without specifying a file to change.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
A draft for DuckDB upstream, filed here for review first.
Summary
A spatial join in DuckDB fails when one side is an Arrow scan whose geometry column is a native GEOMETRY, meaning a GeoArrow WKB column (ARROW:extension:name = geoarrow.wkb). The failure:
NotImplementedException: Not implemented Error: Pushdown Filter Type EXPRESSION_FILTER is not currently supported in PyArrow Scans
The SPATIAL_JOIN operator pushes a filter on the geometry column into the Arrow scan, which the Python Arrow scan can't translate. DuckDB raises an error instead of skipping that pushdown and filtering after the scan.
This breaks the most common geospatial query on xarray-sql tables: xql.register(con, name, ds, geometry=(x, y)) produces exactly such a column, and joining it to a table of polygons with ST_Within fails. A constant polygon works; a polygon from a table, a join, or a scalar subquery fails.
Repro, without xarray-sql (DuckDB 1.5.5, pyarrow 23.0.0)
import duckdb, struct, json, pyarrow as pa, pyarrow.dataset as pads
con = duckdb.connect()
con.execute("INSTALL spatial; LOAD spatial")
xy = [(x, y) for y in (0.0, 1.0, 2.0) for x in (0.0, 1.0, 2.0)]
wkb = pa.array([struct.pack("<BIdd", 1, 1, x, y) for x, y in xy], pa.binary())
geometry = pa.field("geometry", pa.binary(), metadata={
"ARROW:extension:name": "geoarrow.wkb",
"ARROW:extension:metadata": json.dumps({"crs": "OGC:CRS84"}),
})
points = pa.Table.from_arrays([wkb], schema=pa.schema([geometry]))
con.execute("""CREATE TABLE p AS SELECT ST_SetCRS(ST_GeomFromText(
'POLYGON((-0.5 -0.5, 1.5 -0.5, 1.5 1.5, -0.5 1.5, -0.5 -0.5))'), 'OGC:CRS84') AS geom""")
for obj in (points, pads.dataset(points)):
con.register("g", obj)
con.sql("SELECT count(*) FROM g JOIN p ON ST_Within(g.geometry, p.geom)").fetchone()
# NotImplementedException: ... EXPRESSION_FILTER ... PyArrow Scans
Results by query shape, on an xarray-sql table registered with geometry=("longitude", "latitude"):
| Query | Result |
|---|---|
WHERE ST_Within(geometry, ST_GeomFromText('POLYGON ...')) (constant) |
works |
WHERE ST_Within(geometry, (SELECT geom FROM p)) |
fails |
JOIN p ON ST_Within(g.geometry, p.geom) |
fails |
FROM g, p WHERE ST_Within(g.geometry, p.geom) |
fails |
FROM (FROM g LIMIT ...) g JOIN p ON ... |
fails |
JOIN p ON ST_Within(ST_Point(g.longitude, g.latitude), p.geom) |
works |
CREATE TABLE gm AS FROM g, then join gm |
works |
The same join on a plain binary column, ST_Within(ST_GeomFromWKB(g.wkb), p.geom), also works. So the trigger is the native GEOMETRY type on an Arrow scan.
Setting disabled_optimizers to join_filter_pushdown, filter_pushdown or both doesn't change it.
Expected
The Arrow scan should decline filters it can't translate, as it does for other expressions, and DuckDB should apply them after the scan, so the join returns 4.
Workarounds today
- Build the point in the join:
ST_Point(longitude, latitude). This loses the CRS tag. - Copy the table into DuckDB first with
CREATE TABLE ... AS.
For xarray-sql
- Until DuckDB is fixed, the geospatial docs could show the
ST_Pointform for joins against polygon tables. - A related mismatch: xarray-sql tags its points
OGC:CRS84, while DuckDB'sST_Readtags GeoJSON (always longitude/latitude on WGS84)EPSG:4326.ST_Withinthen refuses with "Cannot call function 'ST_Within' with geometries of different coordinate reference systems". Users have to passgeometry_crs="EPSG:4326"or useST_SetCRS. That deserves a line in the docs, or a separate issue on which default fits DuckDB better.
- Linguagem predominante
- Python
- Estrelas
- 142
- Forks
- 19
- Merge médio
- 3d 47min
- PRs com merge (30d)
- 8
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de xqlsystems/xarray-sql
-
dependencies github_actions
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
xqlsystems/xarray-sql#295 ·
Mantenedores costumam responder em até 3 dias
-
A big-endian data variable registers, then every query fails: Byte-swapped arrays not supportedAbertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
xqlsystems/xarray-sql#288 ·
Mantenedores costumam responder em até 3 dias
-
documentation ml
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 85/100
xqlsystems/xarray-sql#268 ·
Mantenedores costumam responder em até 3 dias
-
enhancement ml
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
xqlsystems/xarray-sql#267 · 4 comentários ·
Mantenedores costumam responder em até 3 dias
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 74/100
xqlsystems/xarray-sql#243 ·
Mantenedores costumam responder em até 3 dias
Todas as issues de xqlsystems/xarray-sql
Issues semelhantes
-
documentation good first issue
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
MarketSquare/robotframework-browser#5479 ·
Mantenedores costumam responder em até 1 dia
-
Visual COBOL: missing 11.0 and 12.0, and 9.0 date differs from Rocket Software's lifecycle pageAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
endoflife-date/endoflife.date#11561 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
OCA/l10n-brazil#5602 ·
Mantenedores costumam responder em até 1 dia
-
documentation review-2.0.0
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
dkuenzel/meshcore-home-gateway#106 ·
Mantenedores costumam responder em até 1 dia