Hi all,
I have a bunch of vertices and edges to insert into orientDB, hopefully 
using pyorient.

I've got a bunch of parent vertices, let's call them documents. Then I have 
a bunch of metadata vertices that are shard amongst the documents.

If I have a collection of records that look like:
{"document_id":"abc123", "metadata":"good", "weight":0.1}
{"document_id":"abc124", "metadata":"bad", "weight":0.3}
{"document_id":"abc125", "metadata":"ugly", "weight":0.2}
{"document_id":"abc126", "metadata":"good", "weight":0.6}
{"document_id":"abc127", "metadata":"good", "weight":0.3}
{"document_id":"abc128", "metadata":"good", "weight":0.74}
{"document_id":"abc129", "metadata":"ugly", "weight":0.2}

I have a document class and a metadata "V" type class created.


I see the following in the pyorient documentation

cmd = ("begin;"
    "let a = create vertex set script = true;"
    "let b = select from v limit 1;"
    "let e = create edge from $a to $b;"
    "commit retry 100;")

    edge_result = self.client.batch(cmd)


What I'd ultimately like to be able to do is something like:


   - for each record
      - Insert document if document_id doesn't exist, capture ID in either 
      case
      - Insert metadata name id metadata name doesn't exist, capture ID, in 
      either case
      - Insert edge with weight "weight" between document and metadata ID
   
>>> documents = [{"document_id":"abc123", "metadata":"good", "weight":0.1},
... {"document_id":"abc124", "metadata":"bad", "weight":0.3},
... {"document_id":"abc125", "metadata":"ugly", "weight":0.2},
... {"document_id":"abc126", "metadata":"good", "weight":0.6},
... {"document_id":"abc127", "metadata":"good", "weight":0.3},
... {"document_id":"abc128", "metadata":"good", "weight":0.74},
... {"document_id":"abc129", "metadata":"ugly", "weight":0.2}]
... 
>>> cmdlist = ["begin;"]
>>> for doc in documents:
...     cmdlist.append("let a = UPDATE doc_test SET doc_id='%s' UPSERT 
WHERE doc_id='%s';"%(doc["document_id"],doc["document_id"]))
...     cmdlist.append("let b = UPDATE meta_test SET name='%s' UPSERT WHERE 
name='%s';"%(doc["metadata"],doc["metadata"]))
...     cmdlist.append("let e = CREATE edge from $a to $b SET 
weight=%s;"%(doc["weight"],))
...
>>> cmdlist
['begin;', "let a = UPDATE doc_test SET doc_id='abc123' UPSERT WHERE 
doc_id='abc123';", "let b = UPDATE meta_test SET name='good' UPSERT WHERE 
name='good';", 'let e = CREATE edge from $a to $b SET weight=0.1;', "let a 
= UPDATE doc_test SET doc_id='abc124' UPSERT WHERE doc_id='abc124';", "let 
b = UPDATE meta_test SET name='bad' UPSERT WHERE name='bad';", 'let e = 
CREATE edge from $a to $b SET weight=0.3;', "let a = UPDATE doc_test SET 
doc_id='abc125' UPSERT WHERE doc_id='abc125';", "let b = UPDATE meta_test 
SET name='ugly' UPSERT WHERE name='ugly';", 'let e = CREATE edge from $a to 
$b SET weight=0.2;', "let a = UPDATE doc_test SET doc_id='abc126' UPSERT 
WHERE doc_id='abc126';", "let b = UPDATE meta_test SET name='good' UPSERT 
WHERE name='good';", 'let e = CREATE edge from $a to $b SET weight=0.6;', 
"let a = UPDATE doc_test SET doc_id='abc127' UPSERT WHERE 
doc_id='abc127';", "let b = UPDATE meta_test SET name='good' UPSERT WHERE 
name='good';", 'let e = CREATE edge from $a to $b SET weight=0.3;', "let a 
= UPDATE doc_test SET doc_id='abc128' UPSERT WHERE doc_id='abc128';", "let 
b = UPDATE meta_test SET name='good' UPSERT WHERE name='good';", 'let e = 
CREATE edge from $a to $b SET weight=0.74;', "let a = UPDATE doc_test SET 
doc_id='abc129' UPSERT WHERE doc_id='abc129';", "let b = UPDATE meta_test 
SET name='ugly' UPSERT WHERE name='ugly';", 'let e = CREATE edge from $a to 
$b SET weight=0.2;']
>>> cmdlist.append("commit retry 100;")


I tried doing this but get an exception:
begin;
let a = UPDATE doc_test SET doc_id='abc123' UPSERT WHERE doc_id='abc123';
let b = UPDATE meta_test SET name='good' UPSERT WHERE name='good';
let e = CREATE edge from $a to $b SET weight=0.1;
let a = UPDATE doc_test SET doc_id='abc124' UPSERT WHERE doc_id='abc124';
let b = UPDATE meta_test SET name='bad' UPSERT WHERE name='bad';
let e = CREATE edge from $a to $b SET weight=0.3;
let a = UPDATE doc_test SET doc_id='abc125' UPSERT WHERE doc_id='abc125';
let b = UPDATE meta_test SET name='ugly' UPSERT WHERE name='ugly';
let e = CREATE edge from $a to $b SET weight=0.2;
let a = UPDATE doc_test SET doc_id='abc126' UPSERT WHERE doc_id='abc126';
let b = UPDATE meta_test SET name='good' UPSERT WHERE name='good';
let e = CREATE edge from $a to $b SET weight=0.6;
let a = UPDATE doc_test SET doc_id='abc127' UPSERT WHERE doc_id='abc127';
let b = UPDATE meta_test SET name='good' UPSERT WHERE name='good';
let e = CREATE edge from $a to $b SET weight=0.3;
let a = UPDATE doc_test SET doc_id='abc128' UPSERT WHERE doc_id='abc128';
let b = UPDATE meta_test SET name='good' UPSERT WHERE name='good';
let e = CREATE edge from $a to $b SET weight=0.74;
let a = UPDATE doc_test SET doc_id='abc129' UPSERT WHERE doc_id='abc129';
let b = UPDATE meta_test SET name='ugly' UPSERT WHERE name='ugly';
let e = CREATE edge from $a to $b SET weight=0.2;
commit retry 100;

Anyone have any hints on what I'm missing? I'd very much like to use the 
bulk interface in an intelligent way.

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to