Get results from batch commands

已查看 39 次
跳至第一个未读帖子

Diarmaid de Burca

未读,
2018年4月25日 12:42:592018/4/25
收件人 OrientDB
Currently, in OrientDB it is possible to batch up commands so that you can run multiple commands at once.   At the moment, it will return the return value of the final command executed (by default).   Is there any way to get it to return a list of the commands, such that each element in the list corresponds to the return value of the sent command?

e.g. I want to send:

begin;
insert into class content {"blah": "blah1"};
insert into class content {"blah": "blah2"};
insert into class content {"blah": "blah3"};
commit;

and have it return an array with 3 elements, with the first element corresponding to blah1, the second blah2, etc.

user.w...@gmail.com

未读,
2018年5月2日 02:15:212018/5/2
收件人 OrientDB
Hi,

I tried this in OrientDB Studio:

begin
let a
= insert into class content {"blah": "blah1"}
let b
= insert into class content {"blah": "blah2"}
let c
= insert into class content {"blah": "blah3"}
commit
retry 100
return [$a,$b,$c]

this is the output


Hope it helps

Regards,

Michela

Diarmaid de Burca

未读,
2018年5月2日 05:22:122018/5/2
收件人 OrientDB
What version of OrientDB are you using? I am using version 2.2.30, and when I try to run your example script in Studio I get:

com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.begin let a = insert into class content {"blah": "blah1"} let b = insert into class content {"blah": "blah2"} let c = insert into class content {"blah": "blah3"} commit retry 100 return [$a,$b,$c] DB name="df"

I also tried to run it through PyOrient (I have to use pyOrient unfortunately at the moment) with the following script:

    from __future__ import print_function, unicode_literals
    import pyorient
    
    client = pyorient.OrientDB("localhost", 2424)
    
    try:
        client.connect(<username>, <password>)
        client.db_open("df", <username>, <password>)
    except:
        print({"message": "Unauthorised"},403)
    
    query = """begin;let a = insert into u_df_product content {"blah": "blah1" };let b = intest into u_df_product content {"blah": "blah2" };let c = insert into u_df_product content {"blah" : "blah3"};commit retry 100; return [$a, $b, $c];"""
    
    print(query)
    working_query = """ select from u_df_product where name = "name" """
    res = client.query(working_query)
    
    print (res)
     
    res = client.batch(query)
    print(res)

Which causes my socket to time out:
Traceback (most recent call last):
  File "~/.PyCharmCE2018.1/config/scratches/scratch_2.py", line 20, in <module>
    res = client.batch(query)
  File "~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/orient.py", line 466, in batch
    .prepare(( QUERY_SCRIPT, ) + args).send().fetch_response()
  File "~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/messages/commands.py", line 144, in fetch_response
    super( CommandMessage, self ).fetch_response()
  File ~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/messages/base.py", line 265, in fetch_response
    self._decode_all()
  File "~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/messages/base.py", line 249, in _decode_all
    self._decode_header()
  File "~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/messages/base.py", line 176, in _decode_header
    serialized_exception = self._decode_field( FIELD_STRING )
  File "~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/messages/base.py", line 366, in _decode_field
    _decoded_string = self._orientSocket.read( _len )
  File "~/anaconda3/envs/ever/lib/python2.7/site-packages/pyorient/orient.py", line 167, in read
    n_bytes = self._socket.recv_into(view, _len_to_read)
socket.timeout: timed out
回复全部
回复作者
转发
0 个新帖子