You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Roll the nested pluck syntax into other commands #1094
Whoops, sorry. Do you mind if I close #1091 instead of closing this one? (I linked a bunch of things to it, and don't want to go through all those links)
This seems the most analogous to what pluck does and is probably what people want since saying without({"foo" : "bar"}) will leave the key "foo" in the map in the non error case.
has_fields:
This one seems easier since we're returning just returning whether or not we match. For example:
The rest of these I'm pretty sure have an obvious command that they behave the same as in this regard. orderby and group_by are like pluck and with_fields is a combination of has_fields and pluck.
So having thought about this a bit I think we should just drop the nested syntax from order_by the main reason is that it can potentially be very confusing since the order of the arguments matters in order_by but doesn't in other functions where we're applying this such as pluck. Specifically:
table.order_by("foo", "bar")
# might be expected to be equivalent to
table.order_by(["foo", "bar"])
# which we could conceivably make be equivalent but then what of
table.order_by({"foo" : True, "bar" : True})
# which is by definition equivalent to
table.order_by({"bar" : True, "foo" : True})
The pattern matching syntax also doesn't play great with r.desc and r.asc.
I think a better thing to do would be to just have order_by accept a function in which one can use pluck.
You can't do: table.index_create({"foo" : "bar"}) because we wouldn't know what to name the index. You can do: table.index_create("name", lambda x: x.pluck({"foo" : "bar"}))
I don't think my index works; it returns nothing. Is there a way to get all contents by index (so I can debug and see if I actually wrote my index correctly)?
How are you trying to get things from it? Also maybe you'd like to stop by #rethinkdb on freenode. We can offer help a lot easier there and github issues aren't really the right forum for discussions like this.
Activity
jdoliner commentedon Jun 29, 2013
This is that #1091 was for.
coffeemug commentedon Jun 29, 2013
Whoops, sorry. Do you mind if I close #1091 instead of closing this one? (I linked a bunch of things to it, and don't want to go through all those links)
mlucy commentedon Jul 2, 2013
I'm totally cool with:
But:
get_field-- what does this do if someone writesr({:a => 1, :b => 2}).get_field([:a, :b])?jdoliner commentedon Jul 2, 2013
mlucy commentedon Jul 2, 2013
That seems bad to me. I would rather just not make
get_fieldtake that syntax.jdoliner commentedon Jul 2, 2013
So one thing that we should consider is what happens with errors like #1095 in the other operations. Here's what I think we should do:
without:This seems the most analogous to what
pluckdoes and is probably what people want since sayingwithout({"foo" : "bar"})will leave the key "foo" in the map in the non error case.has_fields:This one seems easier since we're returning just returning whether or not we match. For example:
The rest of these I'm pretty sure have an obvious command that they behave the same as in this regard.
orderbyandgroup_byare likepluckandwith_fieldsis a combination ofhas_fieldsandpluck.jdoliner commentedon Jul 2, 2013
So another question here is how you can use negatives in
orderbywith pattern matching syntax. Is there a way to say something like:coffeemug commentedon Jul 2, 2013
What's wrong with the example you picked?
jdoliner commentedon Jul 3, 2013
So having thought about this a bit I think we should just drop the nested syntax from
order_bythe main reason is that it can potentially be very confusing since the order of the arguments matters inorder_bybut doesn't in other functions where we're applying this such aspluck. Specifically:The pattern matching syntax also doesn't play great with
r.descandr.asc.I think a better thing to do would be to just have
order_byaccept a function in which one can usepluck.coffeemug commentedon Jul 3, 2013
👍
To clarify, this is what we talked about in person:
This syntax is clear, unambiguous, and more than sufficient to get the job done.
jdoliner commentedon Jul 3, 2013
We should also have a separate issue for this would you mind opening it @coffeemug?
coffeemug commentedon Jul 3, 2013
NP, see #1120.
jdoliner commentedon Jul 8, 2013
This is mostly implemented it just needs a bit of pair programming with @mlucy to complete.
mlucy commentedon Jul 9, 2013
This seems basically settled.
13 remaining items
AtnNn commentedon Aug 19, 2013
@chrisabrams you can create an index on the nested attribute and get on that index, or use filter.
chrisabrams commentedon Aug 19, 2013
Let's say I have an object in RethinkDB in the database 'mydb' and the table 'mytable' (I'm working in Node.js):
I want to find a specific object called "something"; I tried filter like so:
Am I doing filter wrong? I think I should make the md5 an index, but I'm curious about my use of filter and whether it is correct.
Filter returns with no results, even if there are multiple entries with the same value.
jdoliner commentedon Aug 19, 2013
filterdoesn't yet support nest syntax like that.chrisabrams commentedon Aug 19, 2013
OK that is what I figured...what about creating an index on a nested attribute?
jdoliner commentedon Aug 19, 2013
You can't do:
table.index_create({"foo" : "bar"})because we wouldn't know what to name the index. You can do:table.index_create("name", lambda x: x.pluck({"foo" : "bar"}))chrisabrams commentedon Aug 19, 2013
Makes sense. Alright I'll try that!
chrisabrams commentedon Aug 19, 2013
Is there an example of how to do lambda in Node?
jdoliner commentedon Aug 19, 2013
I think in Node say:
function (row) { return row.pluck({"foo" : "bar"}); }neumino commentedon Aug 19, 2013
@chrisabrams, "lambda function" are what we call "anonymous function" in JavaScript.
chrisabrams commentedon Aug 19, 2013
@neumino thanks :)
So...I did this:
But in the admin UI it says zero secondary indexes. When I run the following code (referencing the same code from above)
I get the error:
Did I miss something?
jdoliner commentedon Aug 19, 2013
Looks like your forgot to add
.run()to the end of the first query.chrisabrams commentedon Aug 19, 2013
Heh I did forget something.
chrisabrams commentedon Aug 19, 2013
K that created my index. Now to test a search :)
chrisabrams commentedon Aug 19, 2013
I don't think my index works; it returns nothing. Is there a way to get all contents by index (so I can debug and see if I actually wrote my index correctly)?
jdoliner commentedon Aug 19, 2013
How are you trying to get things from it? Also maybe you'd like to stop by #rethinkdb on freenode. We can offer help a lot easier there and github issues aren't really the right forum for discussions like this.