Query on edge property gives unexplicable results

699 views
Skip to first unread message

Maverick

unread,
Aug 29, 2019, 8:58:08 AM8/29/19
to OrientDB
Can somebody here explain why the code below produces 1 result (while it should give zero, because the condition >1 is not matched)?
If I query 'Entity similarity' < 1 it gives zero records. The same if I use backticks instead of apex.
I'm using version 3.0.19

package odbtest; import com.orientechnologies.orient.core.db.ODatabasePool; import com.orientechnologies.orient.core.db.ODatabaseType; import com.orientechnologies.orient.core.db.OrientDB; import com.orientechnologies.orient.core.db.OrientDBConfig; import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.record.OEdge; import com.orientechnologies.orient.core.record.OVertex; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; public class ODBTest { public static void main( String[] args ) { new ODBTest().run(); } ODatabaseDocument session; public void run() { OrientDBConfig dbConfig = OrientDBConfig.defaultConfig(); String dbname = "test"; OrientDB orientDB = new OrientDB("memory:", dbConfig); orientDB.createIfNotExists( dbname, ODatabaseType.MEMORY ); session = new ODatabasePool( orientDB, dbname, "admin", "admin" ).acquire(); session.createVertexClass( "Entry" ); session.createEdgeClass( "Distance" ); OVertex v1 = addVertex( "Vertex 1" ); OVertex v2 = addVertex( "Vertex 2" ); addEdge( v1, v2, 0.2 ); query( v1 ); } private OVertex addVertex( String prop ) { OVertex v = session.newVertex( "Entry" ); v.setProperty( "myProp", prop ); v.save(); session.commit(); return v; } public void addEdge( OVertex v1, OVertex v2, double distance ) { OEdge edge = session.newEdge( v1, v2, "Distance" ); edge.setProperty( "Entity similarity", distance ); edge.save(); session.commit(); } public void query( OVertex v ) { for( OIdentifiable id : new OSQLSynchQuery<ODocument>( "SELECT expand(" + "both('Distance').bothE()['Entity similarity' > 1 ]" + ") FROM " + v.getIdentity() )) { ODocument doc = session.getRecord( id ); System.out.println( doc ); } } }

Luigi Dell'Aquila

unread,
Aug 29, 2019, 9:14:07 AM8/29/19
to orient-...@googlegroups.com
Hi,

Please use back-ticks when you refer to property names, and use the new SQL executor (you are using the legacy one), I'm pretty sure it all works fine ;-)

db.query("SELECT expand("

       + "both('Distance').bothE()[`Entity similarity` > 1 ]" 
       + ") FROM " + v.getIdentity());

Thanks

Luigi

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orient-database/5823785e-3843-4253-9bf6-a281be7c06d2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages