Giter Club home page Giter Club logo

Comments (9)

coffeemug avatar coffeemug commented on June 20, 2024

@ptrln could you try equiJoin instead of eqJoin? I believe it's a bug in the JS client (the name has changed, but somehow I guess it wasn't updated). We'll fix it first thing Monday.

from rethinkdb.

ptrln avatar ptrln commented on June 20, 2024

yeap, equiJoin worked. However, when I run it I get this error:

> r.table('posts').equiJoin('user_id', r.table('users')).runp()
undefined
> { name: 'Runtime Error',
  message: 'Attribute: id is not the primary key (user_id) and thus cannot be selected upon.\n\tr.table(\'posts\').concatMap(function(arg0_1) {return r.let({\'right\':r.table(\'users\').get(r.letVar(\'arg0_1\')(\'user_id\'), \'id\')}, r.branch(r.letVar(\'right\').ne(r.expr(null)), r.expr([r.expr({\'left\':r.letVar(\'arg0_1\'), \'right\':r.letVar(\'right\')})]), r.expr([])))})\n\t                                                                                                                       ^^^^                                                                                                                                         ' }

But when I run the innerJoin version, it works fine:

> r.table('posts').innerJoin(r.table('users'), function(post, user) {return post('user_id').eq(user('user_id'))}).runp()
undefined
> { left: 
   { title: 'Google',
     url: 'http://google.com',
     user_id: 'peterlin',
     sub_id: 'news',
     post_id: '17af9cb1-e4e6-46b8-8963-fca62d059916' },
  right: { user_id: 'peterlin', name: 'Peter'} }

Is it because eqJoin can only be run on the primary key? The API docs isn't clear on this. I assumed "An inner join with a simple equality filter on the given attribute." means by two queries are equivalent.

from rethinkdb.

coffeemug avatar coffeemug commented on June 20, 2024

Confirmed that's the bug. @wmrowan -- could you change equiJoin to eqJoin in the JS client?

from rethinkdb.

coffeemug avatar coffeemug commented on June 20, 2024

@ptrln -- yes, that's correct, eqJoin only works when you're joining on the primary key of the right table (you can join on any attribute in the left table). Thanks for pointing this out, we'll clarify the docs together with this fix.

from rethinkdb.

mlucy avatar mlucy commented on June 20, 2024

So, I might be reading this wrong, but I believe the problem is that right now all the clients hard-code 'id' as the primary key in a few places, including as the key we select on for the right table in an eq_join.

At least in the Ruby client, the syntax here is that the first argument is the attribute we're selecting from the left table, and then we always use id as the attribute of the right table.

We should just fix this on the server, so that instead of hardcoding the id in the client that part of the protobuf is optional and it's filled in by the server as the primary key of the table.

A simpler client-only fix would be to reintroduce the optional third argument to eq_join, and let users specify the primary key of the right table there. This would also be forward-compatible when we introduce secondary indexes. I'll open a separate issue about that.

from rethinkdb.

coffeemug avatar coffeemug commented on June 20, 2024

@mlucy eq_join still has an optional third argument as best as I can tell (though it seems to be missing from the docs).

from rethinkdb.

mlucy avatar mlucy commented on June 20, 2024

Hm, it doesn't in Ruby. I'll fix that and update the docs.

from rethinkdb.

coffeemug avatar coffeemug commented on June 20, 2024

For this issue, we need to change the JS client from equiJoin to eqJoin, and add a third argument to the Ruby client. We also need to verify that the docs are correct on everything and have good examples.

For deeper server updates, I opened #29.

from rethinkdb.

wmrowan avatar wmrowan commented on June 20, 2024

This has been fixed.

from rethinkdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.