orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Problem to substitute deprecated Method to query spatial index

Open EricSchreiner opened this issue 7 years ago • 4 comments

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.(OLocalResultSet.java:29) at com.orientechnologies.orient.core.sql.parser.OSelectStatement.execute(OSelectStatement.java:267) at com.orientechnologies.orient.core.sql.parser.OStatement.execute(OStatement.java:59) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.command(ODatabaseDocumentEmbedded.java:540) at de.contecon.picapport.db.LuceneSpatialDropTest.testDeleteLuceneIndex1(LuceneSpatialDropTest.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

EricSchreiner avatar Sep 07 '18 11:09 EricSchreiner

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

wolf4ood avatar Sep 07 '18 13:09 wolf4ood

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.

EricSchreiner avatar Sep 07 '18 14:09 EricSchreiner

Has this been fixed? If yes in which release?

EricSchreiner avatar Aug 06 '21 11:08 EricSchreiner

HI @EricSchreiner , my bad. Reopened

andrii0lomakin avatar Aug 06 '21 12:08 andrii0lomakin