Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong data returned for some OGRSQL queries combined with OGR_L_SetNextByIndex #8585

Closed
theroggy opened this issue Oct 21, 2023 · 2 comments
Closed

Comments

@theroggy
Copy link
Contributor

theroggy commented Oct 21, 2023

The following combination of factors leads to wrong data being returned:

  • the arrow API is used
  • to execute an "OGRSQL" sql query that contains a "LIMIT" clause (e.g. SELECT * FROM naturalearth_lowres LIMIT 1). When the "SQLITE" dialect is used it seems to work fine.
  • and this is combined with using OGR_L_SetNextByIndex to skip some rows

In this combination the rows aren't skipped correctly.

I'm afraid I don't have a code snippet ready to reproduce it... it was noticed while working on the arrow interface in pyogrio, so in cython.

However, it can be triggered by eg. running "SELECT * FROM LIMIT 1" on any dataset using the "OGRSQL" dialect and setting OGR_L_SetNextByIndex to index 1. This should return 0 rows, but it returns one row.

Tested on gdal 3.7 and 3.8, and this gives the same result.

reference: geopandas/pyogrio#306

@rouault
Copy link
Member

rouault commented Oct 21, 2023

This is not specific to the Arrow interface.

$ python
>>> from osgeo import ogr
>>> ds = ogr.Open('poly.shp')
>>> lyr = ds.ExecuteSQL("SELECT * FROM POLY LIMIT 1")
>>> lyr.SetNextByIndex(1)
>>> lyr.GetNextFeature()
OGRFeature(poly):1
  AREA (Real) = 247328.172
  EAS_ID (Integer64) = 179
  PRFEDEA (String) = 35043423
  POLYGON ((480035.34375 4765558.5,480039.03125 4765539.5,479730.375 4765400.5,479647.0 4765369.5,479690.1875 4765259.5,479819.84375 4765180.5,479779.84375 4765109.5,479681.78125 4764940.0,479468.0 4764942.5,479411.4375 4764940.5,479353.0 4764939.5,479208.65625 4764882.5,479196.8125 4764879.0,479123.28125 4765015.0,479046.53125 4765117.0,479029.71875 4765110.5,479014.9375 4765147.5,479149.9375 4765200.5,479639.625 4765399.5,480035.34375 4765558.5))

@rouault rouault changed the title Wrong data returned using the arrow interface for some OGRSQL queries combined with OGR_L_SetNextByIndex Wrong data returned for some OGRSQL queries combined with OGR_L_SetNextByIndex Oct 21, 2023
@theroggy
Copy link
Contributor Author

Sorry for the misinformation about it being specific for Arrow. I don't see where, but somewhere in the pyogrio code it must be "handled" for the non-arrow case...

rouault added a commit that referenced this issue Oct 21, 2023
OGRSQL: fix incorrect interaction of LIMIT clause and SetNextByIndex() (fixes #8585)
rouault added a commit that referenced this issue Oct 21, 2023
[Backport release/3.7] OGRSQL: fix incorrect interaction of LIMIT clause and SetNextByIndex() (fixes #8585)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants