Discussion:
[orientdb] Get results from batch commands
Diarmaid de Burca
2018-04-25 15:41:16 UTC
Permalink
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.
--
---
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 orient-database+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
u***@gmail.com
2018-05-02 06:15:20 UTC
Permalink
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

<Loading Image...>

Hope it helps

Regards,

Michela
--
---
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 orient-database+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Diarmaid de Burca
2018-05-02 09:19:32 UTC
Permalink
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
Post by u***@gmail.com
Hi,
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
<https://lh3.googleusercontent.com/-tds3EmWKtps/WulXXobF0hI/AAAAAAAAAEU/EAA2zXCHh6c8PBkM_hUXlYge3koAcDLKQCLcBGAs/s1600/Cattura.PNG>
Hope it helps
Regards,
Michela
--
---
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 orient-database+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...