Reputation: 21
I have done a lot of research but couldn't find a simple solution for the following problem.
I have an OrientDB database which has a "MaltegoLink" class. The MaltegoLink has an UNIQUE index to avoid duplicates.
The script itself follows the idea below:
self.client = pyorient.OrientDB(host, port)
self.client.db_open( database, username, password )
maltego_links = [{"source": "n1", target: "n2"}, {"source": "n2", target: "n1"}]
sql_batch = "begin;"
for link in maltego_links:
sql_batch += "CREATE EDGE MaltegoLink FROM (SELECT FROM MaltegoEntity WHERE id='%s') TO (SELECT FROM MaltegoEntity WHERE id='%s');" % (link["source"], link["target"])
self.client.batch(self.sql_batch + "commit;")
The idea is to speed up inserts to the database by doing it as a batch.
And the question itself: How to make a batch query and skip errors provided by the database when there is a duplicate edge?
As far as I know there is no command in OrientDB SQL syntax that allows to continue if error occurs.
EDITED:
Ok, finally found some kind of workaround by myself. The method increases execution time but it is still beneficial:
LET t = SELECT FROM MaltegoLink WHERE in IN (SELECT FROM MaltegoEntity WHERE maltego_id="n1") AND out IN (SELECT FROM MaltegoEntity WHERE id="n2");
IF ( $t.size() == 0 ) {
LET b = CREATE EDGE MaltegoLink FROM (SELECT FROM MaltegoEntity WHERE maltego_id="n2") TO (SELECT FROM MaltegoEntity WHERE maltego_id="n1");
}
Upvotes: 2
Views: 178