Problem to substitute deprecated Method to query spatial index
OrientDB Version: 3.0.6
Java Version: 1.8
OS: Win 10.1
Expected behavior
see $MyoriginalCode below in code
Actual behavior
see $MyProblem below in Code
Steps to reproduce
` String databaseName= this.getClass().getSimpleName(); orientDB = new OrientDB("embedded:./playground/target/databases/", OrientDBConfig.defaultConfig()); orientDB.create(databaseName, ODatabaseType.PLOCAL); ODatabaseSession dbs = orientDB.open(databaseName,"admin","admin");
OClass test = dbs.getMetadata().getSchema().createClass("test"); test.createProperty("name", OType.STRING); test.createProperty("latitude", OType.DOUBLE).setMandatory(false); test.createProperty("longitude", OType.DOUBLE).setMandatory(false); dbs.command("create index test.name on test (name) FULLTEXT ENGINE LUCENE"); dbs.command("create index test.ll on test (latitude,longitude) SPATIAL ENGINE LUCENE"); dbs.close();
....
....
String databaseName= this.getClass().getSimpleName(); ODatabasePool dbPool = new ODatabasePool(orientDB, databaseName,"admin","admin"); ODatabaseSession dbs = dbPool.acquire();
// $MyoriginalCode The following code works fine under Orientdb 2.x and 3.x // But under 3.x it's DEPRECATED !!!!! OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from test where [latitude,longitude] WITHIN [[50.0,8.0],[51.0,9.0]]"); List<ODocument> result = dbs.command(query).execute();
// $MyProblem The following two statements both result in an UnsupportedOperationException:
OResultSet result = dbs.command("select from test where [latitude,longitude] WITHIN [[50.0,8.0],[51.0,9.0]]");
OResultSet result = dbs.query("select from test where [latitude,longitude] WITHIN [[50.0,8.0],[51.0,9.0]]");
`
Stacktrace
java.lang.UnsupportedOperationException: WITHIN operator cannot be evaluated in this context
at com.orientechnologies.orient.core.sql.parser.OWithinOperator.execute(OWithinOperator.java:22)
at com.orientechnologies.orient.core.sql.parser.OBinaryCondition.evaluate(OBinaryCondition.java:57)
at com.orientechnologies.orient.core.sql.parser.ONotBlock.evaluate(ONotBlock.java:45)
at com.orientechnologies.orient.core.sql.parser.OAndBlock.evaluate(OAndBlock.java:48)
at com.orientechnologies.orient.core.sql.parser.OOrBlock.evaluate(OOrBlock.java:50)
at com.orientechnologies.orient.core.sql.parser.OWhereClause.matchesFilters(OWhereClause.java:50)
at com.orientechnologies.orient.core.sql.executor.FilterStep$1.fetchNextItem(FilterStep.java:63)
at com.orientechnologies.orient.core.sql.executor.FilterStep$1.hasNext(FilterStep.java:83)
at com.orientechnologies.orient.core.sql.parser.OLocalResultSet.fetchNext(OLocalResultSet.java:36)
at com.orientechnologies.orient.core.sql.parser.OLocalResultSet.
Hi @EricSchreiner
WITHIN operator is not supported in the new SQL Parser/executor (3.x).
by using Legacy Spatial Indexes you can only use the old executor and the legacy operators .
Otherwise you should switch to the new Geometry data handling which uses spatial functions for querying
https://orientdb.com/docs/2.2.x/Spatial-Index.html#geometry-data
Hi @wolf4ood thanks for your answer. Are there any plans to support WITHIN in the SQL parser in the near future again? If not we have to update a lot of code.
Has this been fixed? If yes in which release?
HI @EricSchreiner , my bad. Reopened