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
Similar to how we have a multi optarg for indexes it would be cool if you could return an array from a group function and have it count the document in multiple groups. For example suppose I have a table, "blog_posts" and I want to count comments based on tags. I could write:
Alright I guess we're fast tracking this. As far as I can see this is a dead simple implementation. Anyone have any misgivings about the API? It seems pretty obvious to me that this should mimic the multi index API. Also just to be specific This is going to affect gmr in the same was as group_by.
No objections. But just so you know, I'm going to bide my time until multi slowly makes its way into various functions in the API, and then gently reintroduce #334 (comment).
@coffeemug the real lulz begin when grouped_map_reduce now takes a multi arg for group and a multi arg for map. Obviously this isn't actual a problem we could solve it by splitting the 2 components up.
I think it's a little weird in eq_join and the same thing can easily be accomplished by prepending a concatMap. So I'm not sure we should do that here, but if other people are cool with it, I don't have a strong objection.
which I think is tricky enough that it's worth having a shorthand for. Why does it seem weird to you? I think it's pretty analogous to our other multis.
My immediate reaction was that it's not obvious at first glance that it applies to the leftmost argument in eq_join. You sort of have to think about it for a bit, and at first glance you might think "is it affecting how it treats the second argument?"
But the bigger reason is that in other cases multi always means "treat the output of this command differently", whereas in case of eq_join it means "treat the input to this command differently". For index creation, grouping, and mapping (if we choose to get rid of concatMap) , multi affects what the function spits out, and there is really no other way to do it in the language. For eq_join it affects the input, and there is another way to do it in the language.
That's not to say that we shouldn't fix cumbersome cases, just that this particular one seems different enough that I think it's worth thinking about.
Also note that the reason you have to go through the annoying map.merge step is that merge doesn't accept a lambda. After #1167 this problem will go away, so you'll be able to just say merge (though admittedly it doesn't make your example all that much nicer).
Basically adding multi to eq_join (i.e. making it a modifier for the input argument) seems like special casing something that might be better represented as a more general purpose primitive. Consider an alternative (made up) query that would do what you want:
Note, that I'm not saying the proposals above are good ideas that we should implement (they may or may not be, I'm not sure). It's more of a way to hint at why adding multi to eq_join smells funny.
I'm a bit confused about what you mean about the multi argument to eq_join affecting the input while the others affect the output. I think they all affect the output and they all affect it in exactly the same way. Consider the following:
For any f the following holds:
stream.map(f, multi=True).count() ==stream.eq_join(f, table, multi=True).count() ==stream.group(f, multi=True).count() ==# this doesn't exist but it couldtable.order_by(index="multi_index_on_f").count() # this is kind of a hack but you get the idea
Assuming that you don't hit the error cases such as the f erroring or the corresponding row not existing.
I think trying to come up with a primitive for this is not going to yield good results (there's some obvious problems with both the ones you proposed) but also I think you'll wind up with a primitive that's impossible to describe to users unless you show them how it interacts with these functions.
Activity
jdoliner commentedon Oct 10, 2013
Putting this in backlog for now, we'll get to it when we get to it.
coffeemug commentedon Oct 10, 2013
FYI, a few people asked me for this.
mlucy commentedon Oct 10, 2013
I also think this is a great idea. Tagging as a proposal and moving to subsequent, since people have asked for it.
jdoliner commentedon Oct 10, 2013
Alright I guess we're fast tracking this. As far as I can see this is a dead simple implementation. Anyone have any misgivings about the API? It seems pretty obvious to me that this should mimic the multi index API. Also just to be specific This is going to affect
gmrin the same was asgroup_by.mlucy commentedon Oct 10, 2013
No objections to the api.
coffeemug commentedon Oct 10, 2013
No objections. But just so you know, I'm going to bide my time until
multislowly makes its way into various functions in the API, and then gently reintroduce #334 (comment).jdoliner commentedon Oct 10, 2013
@coffeemug you mean the
emitsyntax? How would that work ingroup_by?coffeemug commentedon Oct 10, 2013
No, I meant removing
concatMapand replacing it with the following:jdoliner commentedon Oct 10, 2013
@coffeemug the real lulz begin when
grouped_map_reducenow takes amultiarg forgroupand amultiarg formap. Obviously this isn't actual a problem we could solve it by splitting the 2 components up.jdoliner commentedon Oct 11, 2013
Also while we're adding it any objections to adding this to
eq_join? i.e.I just ran in to a situation where I need this.
mlucy commentedon Oct 11, 2013
No objections to adding it to
eq_join.coffeemug commentedon Oct 11, 2013
I think it's a little weird in
eq_joinand the same thing can easily be accomplished by prepending aconcatMap. So I'm not sure we should do that here, but if other people are cool with it, I don't have a strong objection.jdoliner commentedon Oct 11, 2013
@coffeemug it's awkward to do with a
concat_map. So in my example the document representing a blog post might look like:{ "comment_ids" : [0,1,2,3] }to join this to the comment table I'd have to do:
which I think is tricky enough that it's worth having a shorthand for. Why does it seem weird to you? I think it's pretty analogous to our other
multis.coffeemug commentedon Oct 11, 2013
My immediate reaction was that it's not obvious at first glance that it applies to the leftmost argument in
eq_join. You sort of have to think about it for a bit, and at first glance you might think "is it affecting how it treats the second argument?"But the bigger reason is that in other cases
multialways means "treat the output of this command differently", whereas in case ofeq_joinit means "treat the input to this command differently". For index creation, grouping, and mapping (if we choose to get rid ofconcatMap) ,multiaffects what the function spits out, and there is really no other way to do it in the language. Foreq_joinit affects the input, and there is another way to do it in the language.That's not to say that we shouldn't fix cumbersome cases, just that this particular one seems different enough that I think it's worth thinking about.
coffeemug commentedon Oct 11, 2013
Also note that the reason you have to go through the annoying
map.mergestep is thatmergedoesn't accept a lambda. After #1167 this problem will go away, so you'll be able to just saymerge(though admittedly it doesn't make your example all that much nicer).Basically adding
multitoeq_join(i.e. making it a modifier for the input argument) seems like special casing something that might be better represented as a more general purpose primitive. Consider an alternative (made up) query that would do what you want:Or may be we could add a porcelain primitive to make the
mergepart above less cumbersome:That seems far more general than adding
multitoeq_join.coffeemug commentedon Oct 11, 2013
Note, that I'm not saying the proposals above are good ideas that we should implement (they may or may not be, I'm not sure). It's more of a way to hint at why adding
multitoeq_joinsmells funny.jdoliner commentedon Oct 11, 2013
I'm a bit confused about what you mean about the
multiargument toeq_joinaffecting the input while the others affect the output. I think they all affect the output and they all affect it in exactly the same way. Consider the following:For any
fthe following holds:Assuming that you don't hit the error cases such as the
ferroring or the corresponding row not existing.I think trying to come up with a primitive for this is not going to yield good results (there's some obvious problems with both the ones you proposed) but also I think you'll wind up with a primitive that's impossible to describe to users unless you show them how it interacts with these functions.
coffeemug commentedon Oct 11, 2013
Ok, my not-so-strong objection just got even weaker.
coffeemug commentedon Feb 25, 2014
Moving to 1.12 and assigning to @mlucy. I've opened a separate issue for adding
multito joins (see #2008).mlucy commentedon Feb 25, 2014
Marking as API_settled.
mlucy commentedon Feb 25, 2014
This is in review 1262 by @Tryneus .
mlucy commentedon Feb 26, 2014
This is in next.