Reputation: 342
I'm actually trying to use sql-batch insert with pyorient.
I actually have unique index on Edge(in, out) to prevent duplication because i didn't find a way to UPSERT Edge.
session_orientdb.command("CREATE INDEX indexRegroupe ON Regroupe (out, in) UNIQUE")
If I send my command every 100 rows and if one row throw an expection because orientdb found duplicateIndex (in, out) then the entire 100 rows are not insert.
So here is my loop :
i = 0
cmd = "BEGIN;"
# Loop untill receiving the "poison pill" item (meaning : no more element to read)
poison_pill = False
while not(poison_pill):
queries = p_queue.get()
# Manage poison pill
if queries is None:
poison_pill = True
p_queue.task_done()
cmd += "commit;"
session_orientdb.batch(cmd)
else:
for query in queries:
i += 1
cmd += query + ";"
if (i > 100):
i = 0
cmd += "COMMIT retry 20;"
try:
session_orientdb.batch(cmd)
except Exception as e:
print (e)
cmd = "BEGIN;"
queries are something like :
[
'UPDATE Expression SET libelle = "internat fille" UPSERT WHERE libelle = "internat fille";',
'CREATE EDGE Regroupe FROM (SELECT FROM Ontologie WHERE id = "40") to (SELECT FROM Expression WHERE libelle = "internat fille") set score=8;',
'UPDATE Cri SET id = "INTERNAT", libelle = "internat" UPSERT WHERE id = "INTERNAT";',
'CREATE EDGE Identifie FROM (SELECT FROM Expression WHERE libelle = "internat fille") to (SELECT FROM Cri WHERE id = "INTERNAT");'
]
What can i do?
Upvotes: 1
Views: 123
Reputation: 3570
You shoud use the condition if
Example
begin
let a= select from Regroupe where out=#9:0 and in=#10:0
if($a.size()>0){
// edge exists so do other query
}
return $a
Hope it helps.
Upvotes: 2