Skip to content
Advertisement

PyOrient client.command(“SELECT X FROM Protein”) seems to always return the internal ID of the record (Studio returns the property)

I am trying to develop python programs to set up a multi-omics graph database in OrientDB, starting with the gene-transcript-protein relations from Ensembl. A completely unexpected problem I have run into is that the python interface (pyorient/pyorientdb),for queries like client.command(“SELECT uID FROM Protein”) seems to always return the internal ID of the record, not the property (iUD) I am asking for, as you would expect (and Studio does). This is not a special problem with uID (might be consider an index, triggering a special behaviour), but seems to happen with any property. e.g.

loadedProteinUIDs=client.command(“select uID from Protein LIMIT 5”) print(loadedProteinUIDs) loadedProteinXIDs=client.command(“select xID from Protein LIMIT 5”) print(loadedProteinXIDs) loadedProteinXXXs=client.command(“select xxx from Protein LIMIT 5”) print(loadedProteinXXXs) … [<pyorientdb.otypes.OrientRecord object at 0x14a551a30>, <pyorientdb.otypes.OrientRecord object at 0x14a5517f0>, <pyorientdb.otypes.OrientRecord object at 0x14a551a90>, <pyorientdb.otypes.OrientRecord object at 0x14a551940>, <pyorientdb.otypes.OrientRecord object at 0x14a5512b0>] [<pyorientdb.otypes.OrientRecord object at 0x14a551a30>, <pyorientdb.otypes.OrientRecord object at 0x14a5517f0>, <pyorientdb.otypes.OrientRecord object at 0x14a551a90>, <pyorientdb.otypes.OrientRecord object at 0x14a551940>, <pyorientdb.otypes.OrientRecord object at 0x14a5512b0>] [<pyorientdb.otypes.OrientRecord object at 0x14a551fa0>, <pyorientdb.otypes.OrientRecord object at 0x14a551b50>, <pyorientdb.otypes.OrientRecord object at 0x14a551d30>, <pyorientdb.otypes.OrientRecord object at 0x14a551d90>, <pyorientdb.otypes.OrientRecord object at 0x14ae01040>]

Studio seems to go through the REST interface, giving the correct result. I have, as yet, no idea, why the python interface does not give the same results. Any suggestions would be great. Thanks Hans

Advertisement

Answer

The pyorient driver for OrientDB returns a list of OrientRecord objects when you query the database using client.command() or client.query(). In order to access the data you are looking for, you need to call the oRecordData property of these objects:

import pyorient

client = pyorient.OrientDB("localhost", 2424)
client.set_session_token(True)  # set true to enable the token based auth
client.db_open("GratefulDeadConcerts", "admin", "admin")

song_name_raw = client.query("SELECT count(*) FROM V")
print(song_name_raw)  # [<pyorientdb.otypes.OrientRecord object at 0x000001F9F6C37DC0>]

print(song_name_raw[0].oRecordData)  # {'count': 1234}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement