0

I tried monitoring changes on a query with a join

r.table("presence").innerJoin(r.table('authors'), function(presence, author){
  return r.expr(author('highlights')).contains(presence('name'));
}).getField('left').changes()

and I'm getting the following error

e: Cannot call `changes` after `concat_map` in:
r.table("presence").innerJoin(r.table("authors"), function(var_115, var_116) { return var_116("highlights").contains(var_115("name")); }).getField("left").changes()

is that legal and which part is the part that is doing the concat_map ?

MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460

1 Answers1

0

I think innerJoin is sugar syntax on top of concat_map. Actually, you can always use concatMap to solve join problem.

Unfortunately you cannot use changes after concatMap, according to https://rethinkdb.com/docs/changefeeds/ruby/

We have an issue to track this, and it is probably landed in 2.3 or 2.4 as they said. https://github.com/rethinkdb/rethinkdb/issues/3997

So yes, you cannot use changes after join at this moment.

However, I'm trying to go a bit further to see if I can produce something that may work. Just give it a try.

From what I understand, you have a presence table, your join is actually used as a filter/where author. highlights contains presence.name, then listen for change on it. How about trying to get the change first, then call filter later to filter out data. Like this:

r.table("presence")
  .changes()
  .map(function(change) {
    return change('new_val')
  })
  .filter(function(change) {
    return r.table('authors').filter(function(author) {
      return author('highlights').contains(change('name'))
    }).count().gt(0)
  })

Note that this query is not optimized. If it works for you, we can continue on adding index to make it run faster.

kureikain
  • 2,304
  • 2
  • 14
  • 9
  • so I think that covers the case where the presence table is updated, but what if the authors.highlights embedded array is updated in real-time, that won't emit a changes event right? If that's the case is there a standard way of modifying an existing changes watcher? Should I just flush it or delete it in some safe way and re-create ( I don't want to say lose out on any updates while I nil out the previous changes observer and re-initialize a new one). Is there something I should do flush and deallocate a `changes()` observer in javascript to make sure its not holding on to any resources? – MonkeyBonkey Oct 11 '15 at 12:06