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
GMR: polymorphism for grouped_data/groups_to_array #2024
No such luck -- my orderBy works on each reduction, not on whole grouped_data object. This is really bad because to do anything useful with grouped_data I have to first run groups_to_array.
I think it should work completely differently. Every time we call anything on grouped_data, it should be called on the object (as if it were an array or a stream), not on each reduction. So I should be able to call coerce_to('array') on grouped_data and actually get an array.
The current implementation allows me to do r.table('wiki_articles')('text').group(r.row.split(), {multi:true}).count().add(1), but that's not useful -- I almost never ever want to do that. Instead, I should be forced to map.
I also don't think groups_to_array should be equivalent to coerce_to('array') when called on grouped_data and should work on grouped_stream (which I thought was the whole point of groups_to_array).
I think that's the exact opposite of the behavior we want. Let's say you do r(SOME_ARRAY).group('a') -- you get back GROUPED_DATA, where the data are arrays. We want r(SOME_ARRAY).group('a').count to call count on those arrays, not count the number of groups, because that's what tbl.group('a').count does.
95% of the time what you want to do is operate on the content of the groups.
Also, automatically coercing GROUPED_DATA to its array form would be incredibly confusing. (If you're using the data explorer it might not feel too confusing because the array form of GROUPED_DATA happens to be the same as what the javascript driver displays, but if you're using Ruby it's crazy -- r.table('test').group('a').count returns an object, but r.table('test').group('a').map{...} return an array?)
(Actually, this is a pretty solid argument for not having the JS driver turn GROUPED_DATA into an array of objects that matches the output of groups_to_array -- it's likely to confuse users as well.)
Let's say you do r(SOME_ARRAY).group('a') -- you get back GROUPED_DATA, where the data are arrays. We want r(SOME_ARRAY).group('a').count to call count on those arrays, not count the number of groups, because that's what tbl.group('a').count does.
This is orthogonal to the issue. I agree with you that this is exactly what you want, but I don't think you should get that by having r(SOME_ARRAY).group('a') return GROUPED_DATA and defining things on that in a certain way. We should have GROUPING<STREAM> and GROUPING<ARRAY> instead.
This way:
table.group returns GROUPING<STREAM>
array.group returns GROUPING<ARRAY>
a reduction on GROUPING<*> returns GROUPED_DATA
That would get everything behaving properly.
Also, automatically coercing GROUPED_DATA to its array form would be incredibly confusing. ([...] if you're using Ruby it's crazy -- r.table('test').group('a').count returns an object, but r.table('test').group('a').map{...} return an array?)
I'm not sure what you mean. Assuming we automatically coerce grouped streams to arrays, both of the examples above return an object in Ruby.
Another example where you want to act on the values of the groups
That would do exactly what you want because grouped_data.map(...) -> grouped_data.
You were proposing that if you have GROUPED_DATA, and you called order_by on it, that it be converted from GROUPED_DATA to an ARRAY of the form [{group: ..., reduction: ...}, ...]. This is confusing. It doesn't seem confusing in JS because we turn GROUPED_DATA into that form in the clients, but in Ruby you would get an array instead of an object back.
On the topic of GROUPING<ARRAY> vs. GROUPED_DATA, I really don't think we want two different ways to have grouped data. Why should stream.coerce_to('array').group(...) behave differently from stream.group(...).coerce_to('array')? Or if you want to special case the second, why should it be different from stream.group(...).map{|x| [x]}.reduce{|a,b| a+b}? An array is just a datum like any other.
Another example where you want to act on the values of the groups
That would do exactly what you want because grouped_data.map(...) -> grouped_data.
The ['game_id'] at the end is the part that you want to be distributed. You want it to call get_field on each of the groups, not call get_field on the {group: ..., reduction: ...} objects in some implicitly created array.
Also, sorry for opening these issues now. I realize it's annoying, but I think we spoke past each other in the original GMR spec in some cases without realizing it.
So, entirely separate from talking about what we should do, I'd like to sit down with Slava and hammer out:
Terminology.
What we currently do.
What we could plausibly do.
Anyone's of course welcome to join for some or all of that, but I'm expecting a lot of typing, pointing, and saying "so what do you think the return type of that is?", and it might be pretty boring.
Activity
neumino commentedon Feb 26, 2014
What is a
group<array>? Is it agrouped_streamor agrouped_data?mlucy commentedon Feb 26, 2014
I think that's the exact opposite of the behavior we want. Let's say you do
r(SOME_ARRAY).group('a')-- you get back GROUPED_DATA, where the data are arrays. We wantr(SOME_ARRAY).group('a').countto call count on those arrays, not count the number of groups, because that's whattbl.group('a').countdoes.95% of the time what you want to do is operate on the content of the groups.
mlucy commentedon Feb 26, 2014
Also, automatically coercing GROUPED_DATA to its array form would be incredibly confusing. (If you're using the data explorer it might not feel too confusing because the array form of GROUPED_DATA happens to be the same as what the javascript driver displays, but if you're using Ruby it's crazy --
r.table('test').group('a').countreturns an object, butr.table('test').group('a').map{...}return an array?)mlucy commentedon Feb 26, 2014
(Actually, this is a pretty solid argument for not having the JS driver turn GROUPED_DATA into an array of objects that matches the output of
groups_to_array-- it's likely to confuse users as well.)mlucy commentedon Feb 26, 2014
Another example where you want to act on the values of the groups:
coffeemug commentedon Feb 26, 2014
This is orthogonal to the issue. I agree with you that this is exactly what you want, but I don't think you should get that by having
r(SOME_ARRAY).group('a')returnGROUPED_DATAand defining things on that in a certain way. We should haveGROUPING<STREAM>andGROUPING<ARRAY>instead.This way:
table.groupreturnsGROUPING<STREAM>array.groupreturnsGROUPING<ARRAY>GROUPING<*>returnsGROUPED_DATAThat would get everything behaving properly.
I'm not sure what you mean. Assuming we automatically coerce grouped streams to arrays, both of the examples above return an object in Ruby.
That would do exactly what you want because
grouped_data.map(...) -> grouped_data.mlucy commentedon Feb 26, 2014
Sorry, let me try again.
You were proposing that if you have GROUPED_DATA, and you called
order_byon it, that it be converted from GROUPED_DATA to an ARRAY of the form[{group: ..., reduction: ...}, ...]. This is confusing. It doesn't seem confusing in JS because we turn GROUPED_DATA into that form in the clients, but in Ruby you would get an array instead of an object back.On the topic of
GROUPING<ARRAY>vs. GROUPED_DATA, I really don't think we want two different ways to have grouped data. Why shouldstream.coerce_to('array').group(...)behave differently fromstream.group(...).coerce_to('array')? Or if you want to special case the second, why should it be different fromstream.group(...).map{|x| [x]}.reduce{|a,b| a+b}? An array is just a datum like any other.mlucy commentedon Feb 26, 2014
The
['game_id']at the end is the part that you want to be distributed. You want it to callget_fieldon each of the groups, not callget_fieldon the{group: ..., reduction: ...}objects in some implicitly created array.mlucy commentedon Feb 26, 2014
Er, why don't we just talk about this in person tomorrow. I get the feeling we aren't really making forward progress.
coffeemug commentedon Feb 26, 2014
Ok.
Also, sorry for opening these issues now. I realize it's annoying, but I think we spoke past each other in the original GMR spec in some cases without realizing it.
neumino commentedon Feb 26, 2014
If you talk about it tomorrow in person, please let me in.
mlucy commentedon Feb 26, 2014
So, entirely separate from talking about what we should do, I'd like to sit down with Slava and hammer out:
Anyone's of course welcome to join for some or all of that, but I'm expecting a lot of typing, pointing, and saying "so what do you think the return type of that is?", and it might be pretty boring.
coffeemug commentedon Feb 26, 2014
Yep, the two of us should first get together and agree on what we both think is happening. Then of course @neumino you're welcome to join!
coffeemug commentedon Feb 27, 2014
Ok, everyone is in agreement to rename
groupsToArraytoungroup. @mlucy will open an issue about it, we'll close this one then.mlucy commentedon Feb 27, 2014
#2033