GeoTools Query with SortBy: Wrong syntax of generated SQL

189 views Asked by At

I’m trying to read a MapInfo MAP file in Java using GeoTools and its OGR Plugin. I want to iterate over the features in a certain sort order. I’m trying to use GeoTool’s Query and SortBy for this purpose, but the SQL query that gets generated has a syntax error.

Code sample:

OGRDataStoreFactory factory = new JniOGRDataStoreFactory();
Map<String, String> connectionParams = new HashMap<String, String>();
connectionParams.put("DriverName", "MapInfo File");
connectionParams.put("DatasourceName", new File("MyTable.TAB").getAbsolutePath());
DataStore store = factory.createDataStore(connectionParams);
SimpleFeatureSource featureSource = store.getFeatureSource("MyTable");
Query query = new Query();
query.setSortBy(new SortBy[]{ new SortByImpl(new AttributeExpressionImpl("PED"), SortOrder.ASCENDING)});
SimpleFeatureIterator features = featureSource.getFeatures(query).features();
int count = 0;
while (features.hasNext() && count++ < 10) {
    Feature feature = features.next();
    System.out.println(feature);
}

This results in this error message printed to stderr:

ERROR 1: SQL Expression Parsing Error: syntax error, unexpected ORDER, expecting '.'. Occurred around :
SELECT FID, * FROM 'MyTable' ORDER BY PED
                                 ^

The problem are the single quotes around the table name.

If I remove the setSortBy() line, features are returned. So the data access in general works.

If I try the same query using ogr2ogr on the command line with double quotes it works as expected:

ogr2ogr -f "CSV" /vsistdout/ MyTable.TAB -lco GEOMETRY=AS_WKT -sql "SELECT FID, * FROM \"MyTable\" ORDER BY \"PED\" ASC"

Am I doing something wrong?

1

There are 1 answers

0
Ian Turton On

It looks like a bug here, if you can write a simple test case and file a bug report it should be easy to fix.