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
r.table('foo').group('a','b').typeOf()// GROUPEDSTREAMr.table('foo').group('a','b')// Errors: `GROUPEDSTREAM is an opaque type`r.table('foo').group('a','b').map(...).typeOf()// GROUPEDSTREAM// Finally, google/hadoop-style map reduce is accessible to regular people:r.table('foo').group('a','b').map(...).reduce(...).typeOf()// STREAM
Get rid of base in reduce, and make reduce variadic. Have reduce accept either reduction functions, or aggregators:
Allow naming groups and reductions because calling them group and reduction1, reduction2 isn't extremely useful.
r.table('users').group('location',{'name': location}).reduce(r.sum('age',{name: 'age_sum'}),r.avg('age',{name: 'age_avg'}),function(i,j){return ...;}// TODO: not sure how to name this. Ideas?)// returns [{location: ..., age_sum: ..., age_avg: ..., ???: ...}]
Consider dropping groupBy. We might want to consider leaving it as sugar for .group.reduce, because people are used to things like groupBy. I'm not 100% sure what to do here.
I was imagining rather than having 'reduction1' : ..., 'reduction2' : ... you'd just have {'reduction' : [reduction_val_1, ...]} that seems like the cleanest to me.
Also this is nitpicky but I'd prefer to say that GROUPEDSTREAM is an unprintable type rather than an opaque type. I'd be mostly in favor of calling it an unspeakable type for the lulz.
I was imagining rather than having 'reduction1' : ..., 'reduction2' : ... you'd just have {'reduction' : [reduction_val_1, ...]} that seems like the cleanest to me.
That would be cleaner, but offers the following problem. If we do support naming reductions as described, it would mean that the resulting object would have a different structure depending on whether the reductions are named or not (and what if some reductions are named and some aren't?) SQL dbs do a good job automagically naming grouping/reduction columns, which is really useful in practice. A few people have asked about naming these columns, so I think it's pretty important to figure out a way to do it if we can. (Alternatively, we can drop it from this proposal, implement the rest, and then come back to this question later)
Also this is nitpicky but I'd prefer to say that GROUPEDSTREAM is an unprintable type rather than an opaque type
I think we use the term "opaque type" elsewhere in the server to describe types that can't be printed, so I just used the same terminology.
Also as a side note, the following is valid [...]
Do you mean you'd like it to be valid or that it follows from the proposal? I think we should disable all coercing of the GROUPEDSTREAM type for now. When we implement proper array size limiting, we can allow coercing it to arrays.
SQL dbs automatically rename but that's not really feasible for us because we support such a wider variety of aggregations than SQL that we can't just default to "Count(foo.bar)" long term I like the syntax we've discussed where you could say:
reduce({"foo" : lambda x,y x + y, "bar" : lambda x,y: x * y})
I think that would really be awesome but a bit tougher so I think we should just do the simple thing and come back later
We return:
Query result must be of type DATUM or STREAM (got FUNCTION).
if the person tries to print a FUNCTION. I think that's a much better error message than either.
It seems kind of inconsistent to me to let people coerce streams to arrays but not let them coerce groupedstream to something (I realized coercing to an object actually doesn't work but stream does). This is actually a really useful feature when you're dealing with a smaller dataset and what to just take a quick peek at the computation between steps.
Another open question. Suppose I want group to place a document into two or more groups (for example, if I'm doing word counting on text stored in a document, I have to split a single document into many groups). Currently, I'd have to first run concatMap on the stream, and then call group on that. Should we leave it this way, or find a way to allow group to return multiple groups?
In most existing map/reduce implementations it's extremely common to have the grouping function return multiple groups per entry. We can go for composability and tell people to use a combination of concatMap and group, or we can extend group to allow returning multiple groups. What does everyone think?
I know that it can break because we have to keep things in memory (and that it probably require a lot of work), but that would be so cool to have this syntax -- since it's a common operation.
And by so cool I mean really really cool.
I don't know how to give a name for the stream in group but it should be doable to find a good way to name it.
The current proposal makes aggregators be opaque, builtin types that cannot be combined or defined by the users. I agree that it's a limitation, but I feel like it's orthogonal to this proposal (i.e. we could always give aggregators a type and make them be composable and user-definable later, and the current proposal would still stand).
@coffeemug -- it's in a state where you can play with it now (it still needs testing). You can check out branch 1096_gmr. It's only implemented for Ruby though.
We return an array of key-value pairs rather than a {group: ..., reduction: ...} object because it's faster to serialize and deserialize, especially for things like table.group('a').count, where the names group and reduction are actually a majority of the data returned.
The thing is we can't return such results in JavaScript, and we probably don't want the drivers to return different type of results for the same query right?
@neumino: I think returning different types in different drivers is ok. We already have that problem with times. Some languages don't have a special Time type, and there is no way around having inconsistencies between clients.
We have been able to avoid this issue in the official drivers so far, but I don't think it's worth maintaining that property at all costs. Eventually we have to accept that different languages just have different capabilities and may require different representations I think.
I'd like to hear what @coffeemug thinks of this, but I agree that returning a different type in different languages is acceptable -- otherwise more expressive languages end up being dragged down by the common denominator.
The API docs / guides should all specify the language being used, and allow switching between languages to provide different code samples to help avoid confusion.
@neumino brought up a couple of independent concerns about the GMR API. Here are two we discussed today:
Returning different formats by default in different drivers
Having to call ungroup (or whatever we call it) to operate on the grouped object
I disagree with both of these concerns. I think the API is really good as is, the alternative would be worse, and good documentation will take care of any remaining questions or issues. I think users will love it.
I'm prepared to be proven wrong, of course. If people don't like the API, we'll fix it. I would ask to refrain from reopening this discussion so close to the release. We settled on these issues earlier, so now isn't a good time to debate them or reopen closed questions. Let's ship this, see the response, and then decide whether we need to make any course corrections.
The behavior is not the one I thought we agreed on, but it may be my fault, I may have misunderstood something.
I thought that calling coerceTo("array") on a group<stream> would return an array of arrays (so basically coerceTo("array") was ungroup.
I thought that calling coerceTo("array") on a group<stream> would return an array of arrays
Hmm, this might have been ambiguous and we left it for later (and then somehow arrived at a decision in person?) Sorry about that. It means we should have a hard spec for as much as possible for reql proposals, but GMR turned out pretty big, so it isn't always easy to do. I'll try to be more strict about that in the future.
Python and Javascript driver implementations are up in review 1223. Still a couple problems with the ReQL tests test harness, but everything else seems to be working fine.
Activity
jdoliner commentedon Jun 30, 2013
I was imagining rather than having
'reduction1' : ..., 'reduction2' : ...you'd just have{'reduction' : [reduction_val_1, ...]}that seems like the cleanest to me.Also this is nitpicky but I'd prefer to say that
GROUPEDSTREAMis an unprintable type rather than an opaque type. I'd be mostly in favor of calling it an unspeakable type for the lulz.Also as a side note, the following is valid:
coffeemug commentedon Jun 30, 2013
That would be cleaner, but offers the following problem. If we do support naming reductions as described, it would mean that the resulting object would have a different structure depending on whether the reductions are named or not (and what if some reductions are named and some aren't?) SQL dbs do a good job automagically naming grouping/reduction columns, which is really useful in practice. A few people have asked about naming these columns, so I think it's pretty important to figure out a way to do it if we can. (Alternatively, we can drop it from this proposal, implement the rest, and then come back to this question later)
I think we use the term "opaque type" elsewhere in the server to describe types that can't be printed, so I just used the same terminology.
Do you mean you'd like it to be valid or that it follows from the proposal? I think we should disable all coercing of the
GROUPEDSTREAMtype for now. When we implement proper array size limiting, we can allow coercing it to arrays.jdoliner commentedon Jun 30, 2013
SQL dbs automatically rename but that's not really feasible for us because we support such a wider variety of aggregations than SQL that we can't just default to "Count(foo.bar)" long term I like the syntax we've discussed where you could say:
reduce({"foo" : lambda x,y x + y, "bar" : lambda x,y: x * y})I think that would really be awesome but a bit tougher so I think we should just do the simple thing and come back later
We return:
if the person tries to print a FUNCTION. I think that's a much better error message than either.
It seems kind of inconsistent to me to let people coerce streams to arrays but not let them coerce groupedstream to something (I realized coercing to an object actually doesn't work but stream does). This is actually a really useful feature when you're dealing with a smaller dataset and what to just take a quick peek at the computation between steps.
jdoliner commentedon Jun 30, 2013
Oh god I messed up the formatting terribly.
coffeemug commentedon Jun 30, 2013
Another open question. Suppose I want
groupto place a document into two or more groups (for example, if I'm doing word counting on text stored in a document, I have to split a single document into many groups). Currently, I'd have to first runconcatMapon the stream, and then callgroupon that. Should we leave it this way, or find a way to allowgroupto return multiple groups?In most existing map/reduce implementations it's extremely common to have the grouping function return multiple groups per entry. We can go for composability and tell people to use a combination of
concatMapandgroup, or we can extendgroupto allow returning multiple groups. What does everyone think?jdoliner commentedon Jun 30, 2013
I'm pretty opposed to using
concatMapfor that. The best I can come up with right now is:basically the multi_group flag means "interpret the array returned as a set of groups not a single group which is an array.
coffeemug commentedon Jul 1, 2013
The
multi_groupoption sounds cool, I'm strongly in favor of that (though I'd like to sleep on it and think about it a bit more).However, what do you mean by "opposed to using
concatMapfor that"? It's just a query a user can write:We wouldn't have to implementing anything new for this query to work.
jdoliner commentedon Jul 1, 2013
I meant I'm opposed to telling users that's how you have a row be applied to multiple groups. Obviously the query will still work.
coffeemug commentedon Jul 1, 2013
Ok, I see.
neumino commentedon Jul 1, 2013
I really like this syntax.
And I would force users to pass an object when using
reduceon a groupedstream object.If we introduce a groupedstream object, would it be possible to have something like this:
Which would be currently written as
I know that it can break because we have to keep things in memory (and that it probably require a lot of work), but that would be so cool to have this syntax -- since it's a common operation.
neumino commentedon Jul 1, 2013
And by so cool I mean really really cool.
I don't know how to give a name for the stream in
groupbut it should be doable to find a good way to name it.coffeemug commentedon Jul 1, 2013
👍
AtnNn commentedon Jul 1, 2013
In this proposal, what would r.sum('age').typeOf() be?
I think it is essential to be able to combine aggregators:
And to have direct way to build these aggregators:
All the examples in this thread use r.table.group.reduce, but I assume aggregators will also work on regular streams:
I don't like the name aggregator. It sounds like a Google Reader replacement.
coffeemug commentedon Jul 1, 2013
The current proposal makes aggregators be opaque, builtin types that cannot be combined or defined by the users. I agree that it's a limitation, but I feel like it's orthogonal to this proposal (i.e. we could always give aggregators a type and make them be composable and user-definable later, and the current proposal would still stand).
AtnNn commentedon Jul 1, 2013
I've opened issue #1102.
Another suggestion is to allow foo.group(bar).contactMap
94 remaining items
mlucy commentedon Feb 18, 2014
@coffeemug -- it's in a state where you can play with it now (it still needs testing). You can check out branch 1096_gmr. It's only implemented for Ruby though.
coffeemug commentedon Feb 18, 2014
I suppose one can't have everything :)
neumino commentedon Feb 19, 2014
What is
going to return?
@mlucy mentioned an object like
I think we should send back
mlucy commentedon Feb 19, 2014
The server sends this to the clients:
And the Ruby driver turns it into this:
Which you can iterate over like so:
We return an array of key-value pairs rather than a
{group: ..., reduction: ...}object because it's faster to serialize and deserialize, especially for things liketable.group('a').count, where the namesgroupandreductionare actually a majority of the data returned.mlucy commentedon Feb 19, 2014
(To be clear, it's using actual time objects as the keys in the Hash, not strings representing time objects.)
neumino commentedon Feb 19, 2014
The thing is we can't return such results in JavaScript, and we probably don't want the drivers to return different type of results for the same query right?
danielmewes commentedon Feb 19, 2014
@neumino: I think returning different types in different drivers is ok. We already have that problem with times. Some languages don't have a special Time type, and there is no way around having inconsistencies between clients.
We have been able to avoid this issue in the official drivers so far, but I don't think it's worth maintaining that property at all costs. Eventually we have to accept that different languages just have different capabilities and may require different representations I think.
mglukhovsky commentedon Feb 19, 2014
I'd like to hear what @coffeemug thinks of this, but I agree that returning a different type in different languages is acceptable -- otherwise more expressive languages end up being dragged down by the common denominator.
The API docs / guides should all specify the language being used, and allow switching between languages to provide different code samples to help avoid confusion.
coffeemug commentedon Feb 19, 2014
@neumino brought up a couple of independent concerns about the GMR API. Here are two we discussed today:
ungroup(or whatever we call it) to operate on the grouped objectI disagree with both of these concerns. I think the API is really good as is, the alternative would be worse, and good documentation will take care of any remaining questions or issues. I think users will love it.
I'm prepared to be proven wrong, of course. If people don't like the API, we'll fix it. I would ask to refrain from reopening this discussion so close to the release. We settled on these issues earlier, so now isn't a good time to debate them or reopen closed questions. Let's ship this, see the response, and then decide whether we need to make any course corrections.
neumino commentedon Feb 19, 2014
The behavior is not the one I thought we agreed on, but it may be my fault, I may have misunderstood something.
I thought that calling
coerceTo("array")on agroup<stream>would return an array of arrays (so basicallycoerceTo("array")wasungroup.But your point stands, let's ship it first.
coffeemug commentedon Feb 19, 2014
Hmm, this might have been ambiguous and we left it for later (and then somehow arrived at a decision in person?) Sorry about that. It means we should have a hard spec for as much as possible for reql proposals, but GMR turned out pretty big, so it isn't always easy to do. I'll try to be more strict about that in the future.
Tryneus commentedon Feb 20, 2014
Python and Javascript driver implementations are up in review 1223. Still a couple problems with the ReQL tests test harness, but everything else seems to be working fine.
mlucy commentedon Feb 21, 2014
This is in next. There are probably a few small API things to work out; see Review 1223.
I'm going to open some new issues for cleanup stuff that I'd like to get done before 1.12 if there's time.
coffeemug commentedon Feb 21, 2014
Congrats on merging GMR!! Compiling...