2

I want to squash two requests:

a = r.table('A').run(conn)
b = r.table('B').run(conn)

in a single one. Something like:

out = some_reql({
    'a': r.table('A'),
    'b': r.table('B')
}).run(conn)
out['a']
out['b']
Robert Zaremba
  • 8,081
  • 7
  • 47
  • 78

1 Answers1

1

If you want to get both back in a single query you can do it with union like so

r.union(r.table("A"), r.table("B"))

This will give you back a single stream object that's a concatenation of the 2 streams. However you won't be able to tell where one stream ends and the next begins. There's currently no way to return 2 separate stream objects in the same query. So if you want to be able to use them as separate streams you need to do 2 separate queries. Is there a reason that doesn't work for you?


If your streams are big then this won't have a big impact on performance because to evaluate the results of each stream will require multiple requests anyways. However if they're small then you can just coerce them to arrays like so:

{"a" : r.table("A").coerce_to("ARRAY"),
 "b" : r.table("B").coerce_to("ARRAY")}

Only do this if your streams will fit in memory.

Joe Doliner
  • 2,058
  • 2
  • 15
  • 19
  • Optimization. I just want to make a one query instead of 3 (in my case). I know union and as you noticed - I doesn't work for me. – Robert Zaremba Oct 22 '13 at 08:15
  • How big are the streams? If they're big then you're going to be doing several requests to evaluate them anyways so there isn't much point in putting them in a single request. However if they're small then you can just coerce them to arrays. I'm going to edit my answer to show this syntax. – Joe Doliner Oct 22 '13 at 18:29