biokoda / actordb

ActorDB distributed SQL database
Mozilla Public License 2.0
1.9k stars 71 forks source link

How to send multiple parameterised queries through the thrift interface? #70

Open ashwinswy opened 6 years ago

ashwinswy commented 6 years ago

I couldn't find this anywhere in the documentation. I've tried the following:

client.exec_single_param('user_1', 'type', query_1 + query_2, [], [bindings_1, bindings_2])
client.exec_sql_param('actor type(user_1)' + query_1 + query_2, [bindings_1, bindings_2])

In both cases, I'm getting InvalidRequestException(info='not an error', code=6).

First off, is this even possible? If not, how can I execute multiple queries within a transaction?

SergejJurecko commented 6 years ago

You can not with parameterized queries unfortunately. You can if it’s all in the sql statement.

ashwinswy commented 6 years ago

I'd like to try and add this functionality here. Can you point me in the right direction so that I can setup a development environment? Do you have some kind of wiki/documentation which will give me a top level view of all the components involved and how they are working together?

SergejJurecko commented 6 years ago

By writing the thrift spec: https://github.com/biokoda/actordb/blob/master/adbt.thrift You need an additional level of lists, so bindingvals type must be: list<list<list>> List of statements, list of rows and list of columns.

Implementing the call to actordb: https://github.com/biokoda/actordb_thrift/blob/master/src/adbt.erl

The adbt.erl file wraps parameters in a list with a single parameter (prepare/1 function) because it assumes only one statement. It sends bindingvals as a list three layers deep, but first layer is always single element. This is what you need to expand.

ashwinswy commented 6 years ago

How can I setup a development environment? I can see that you have a bash script startdev.sh, but it is not working for me probably because of some missing dependencies. Are these dependencies documented? Am I even looking at the correct file?

Further to that, can you please tell me how to build actordb?

I tried doing make but got the following error

cat: /etc/redhat-release: No such file or directory
Makefile:168: warning: overriding recipe for target `ballclean'
Makefile:65: warning: ignoring old recipe for target `ballclean'
./rebar get-deps

=ERROR REPORT==== 30-Oct-2018::11:35:46 ===
beam/beam_load.c(1365): Error loading module rebar:
  use of opcode 153; this emulator supports only up to 152

=ERROR REPORT==== 30-Oct-2018::11:35:46 ===
Loading of /home/ftpcmbin/workspace/actordb/actordb/rebar/rebar/ebin/rebar.beam failed: badfile
escript: exception error: undefined function rebar:main/1
  in function  escript:run/2
  in call from escript:start/1
  in call from init:start_it/1
  in call from init:start_em/1
make: *** [deps] Error 127
SergejJurecko commented 6 years ago
  1. Install erlang 21
  2. Checkout actordb
  3. ./rebar get-deps
  4. ./rebar co
  5. If you are working on a dependency such as actordb_thrift, I simply go to deps folder and manage it directly. Rebar annoyingly checks out in a detached state, so make sure you are on master or whatever branch you want.
  6. ./startdev.sh will start actor. Anything you change in deps will automaticaly be compiled and running as you work on it.
ashwinswy commented 6 years ago

I've extended the thrift interface to support one more level of nesting for BindingVals0. Now the problem is that, when I'm executing multiple queries it is only returning the result of the very last query in Result(rdRes, wrRes).

I'm assuming I need to modify the Result struct so that it returns a list of ReadResult & WriteResult structs in response. If so, how do you suggest I go about that?

ashwinsadeep commented 6 years ago

I've raised pull requests for this feature in the following repos: actordb, actordb_thrift, and adbt

Please review these when you get a chance. Further to that, can you please let me know how to build actordb for production on CentOS?

SergejJurecko commented 6 years ago

Thank you. Building a package is basically as simple as make package

Requirements:

SergejJurecko commented 6 years ago

Keep in mind it will checkout according to tags and branches set for the various subprojects in rebar.config. Main actordb references actordb_core, which then references the other projects that were updated. If you have a fork of everything, you have to commit your own rebar.configs pointing to your forks.