Spatial query failed with java.lang.NullPointerException

Hello!
Now I am exploring the geospatial capabilities of orientdb in the following model problem:
test_Country - contains countries with boundaries;
test_Placemark - contains POI with position;
I want to find in which country the specific POI is located.
This query works as expected:

select name from test_Country where ST_Contains(geometry, “POINT(14.55126 41.7834853)”) = true

returns Italy
but

select name from test_Country where ST_Contains(geometry, (select point from test_Placemark)) = true

gives

java.lang.NullPointerException
at com.orientechnologies.orient.core.sql.executor.FetchFromIndexedFunctionStep.init(FetchFromIndexedFunctionStep.java:100)
at com.orientechnologies.orient.core.sql.executor.FetchFromIndexedFunctionStep.syncPull(FetchFromIndexedFunctionStep.java:38)
at com.orientechnologies.orient.core.sql.executor.FilterByClustersStep$1.fetchNextItem(FilterByClustersStep.java:57)
at com.orientechnologies.orient.core.sql.executor.FilterByClustersStep$1.hasNext(FilterByClustersStep.java:93)
at com.orientechnologies.orient.core.sql.executor.FilterByClassStep$1.fetchNextItem(FilterByClassStep.java:50)
at com.orientechnologies.orient.core.sql.executor.FilterByClassStep$1.hasNext(FilterByClassStep.java:88)
at com.orientechnologies.orient.core.sql.executor.ProjectionCalculationStep$1.hasNext(ProjectionCalculationStep.java:33)
at com.orientechnologies.orient.core.sql.parser.OLocalResultSet.fetchNext(OLocalResultSet.java:40)
at com.orientechnologies.orient.core.sql.parser.OLocalResultSet.(OLocalResultSet.java:30)
at com.orientechnologies.orient.core.sql.parser.OSelectStatement.execute(OSelectStatement.java:276)
at com.orientechnologies.orient.core.sql.parser.OStatement.execute(OStatement.java:79)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.command(ODatabaseDocumentEmbedded.java:567)
at com.orientechnologies.orient.server.network.protocol.http.command.post.OServerCommandPostCommand.executeStatement(OServerCommandPostCommand.java:189)
at com.orientechnologies.orient.server.network.protocol.http.command.post.OServerCommandPostCommand.execute(OServerCommandPostCommand.java:95)
at com.orientechnologies.orient.server.network.protocol.http.command.post.OServerCommandPostCommandGraph.execute(OServerCommandPostCommandGraph.java:36)
at com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpAbstract.service(ONetworkProtocolHttpAbstract.java:228)
at com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpAbstract.execute(ONetworkProtocolHttpAbstract.java:707)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:69)

Result of subquery looks ok:

select point from test_Placemark

"result": [
    {
        "point": {
            "coordinates": [
                14.55126,
                41.7834853
            ],
            "@class": "OPoint"
        }
    }
],

Any hints? Is this a bug?

Hi @arch7tect

probably it’s a bug, any chance to have a script to reproduce it?

Thanks

Luigi

Hi @arch7tect

I think I got it, it must be a problem of how the function manages subquery result sets.
Could you please try this and see if it works?

select name from test_Country LET $foo = (select point from test_Placemark) where ST_Contains(geometry, $foo[0].point) = true 

Thanks

Luigi

Hi!
Script to reproduce the problem:

drop class Country if exists unsafe;
create class Country extends V;
create property Country.name STRING;
create property Country.geometry EMBEDDED OMultiPolygon;
drop class POI if exists unsafe;
create class POI extends V;
create property POI.name STRING;
create property POI.location EMBEDDED OPoint;
insert into POI(name, location) values(“zeropoint”, St_GeomFromText(“Point(0 0)”));
insert into Country(name, geometry) values(“zeroland”, St_GeomFromText(“MultiPolygon(((1 1, 1 -1, -1 -1, -1 1, 1 1)))”));
CREATE INDEX POI.location ON POI(location) SPATIAL ENGINE LUCENE;
CREATE INDEX Country.geometry ON Country(geometry) SPATIAL ENGINE LUCENE;
let name = select name from Country where ST_Contains(geometry, (select location from POI)) = true;
return $name;

This query works ok:

select name from Country where ST_Contains(geometry, “POINT(0 0)”) = true

Any of this gives NPE:

select name from Country where ST_Contains(geometry, (select location from POI)) = true
select name from Country LET $foo = (select * from POI) where ST_Contains(geometry, $foo[0].location) = true
select name from Country LET $foo = (select location from POI) where ST_Contains(geometry, $foo[0]) = true

by the way, congrats with 3.0.27, good job