You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Curt Arnold <ca...@apache.org> on 2009/09/17 16:11:35 UTC

Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

On Sep 16, 2009, at 11:51 PM, Paul Davis wrote:
>>>
>>> In Governator voice: "It's not a JOIN."
>>>
>>> But you can use it if you have a doc like:
>>>
>>> {"_id":"my-outline",
>>> "other_docs":["docid,"other-docid"]
>>> }
>>>
>>> and then a view like
>>>
>>> function(doc) {
>>> for (var i=0; i < doc.other_docs.length; i++) {
>>>  emit([doc._id, i], {"_id" : doc.other_docs[i]}
>>> };
>>> }


So if I do,

emit(key, doc)

am I specifying the key value and overriding the default document to  
be included since the value would contain _id and _rev members?   
They'd have the same value, so it wouldn't be detectable, but still no  
clear boundary between the value parts of the parameter and the  
document part of the parameter.


>
>> I'm thinking it would be cleaner to support an optional 3 argument  
>> to emit
>> with { _id:"", _rev:"" }?  The current two argument emit() would be  
>> the
>> equivalent of emit(key, value, { _id:doc._id, _rev:doc.rev}).
>>
>
> I think this is a pretty good idea. Though unless I'm missing
> something the implementation difficulty rises noticeably. The only
> initial drawback I see is how we explain the semantics of default
> behavior. For ?include_docs=true it was simply "current version or
> version specified by _rev". Obviously adding _id makes that weirder,
> but I'm don't see a more clear explanation with the third parameter
> version.
>
> Paul Davis


A three parameter version would also allow like:

emit(key, value, null);

when you intentionally do not want any documents provided if the user  
specifies include_docs=true.


Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Chris Anderson <jc...@apache.org>.
On Sun, Oct 25, 2009 at 9:24 PM, Nathan Stott <nr...@gmail.com> wrote:
> Sorry for dragging up an old discussion, but I'm curious as to if this
> feature is in 0.10 and if there's documentation about it.  I did some
> searching and could not locate any.

This didn't make the cut for 0.10. The closest documentation is the
test portion of the patch:

http://svn.apache.org/viewvc?view=revision&revision=815984

>
> On Thu, Sep 17, 2009 at 10:44 PM, Chris Anderson <jc...@apache.org> wrote:
>
>> On Thu, Sep 17, 2009 at 4:33 PM, Paul Davis <pa...@gmail.com>
>> wrote:
>> >> I guess what I'm saying is that I think the include doc "pointer"
>> >> belongs in the value, not in some other place. It strikes me as
>> >> exactly what emitted values are for, to hold arbitrary data associated
>> >> with the key.
>> >
>> > By assigning implicit behavior based on the value, its no longer
>> > arbitrary. _rev and now _id are restricted in what they can represent.
>> > For instance, what happens if I emit {"_id": true} with
>> > include_docs=true?
>> >
>> > Think of the third value as a "row options" variable. The two concepts
>> > are basically "We make assumptions about what you wanted based on what
>> > you emit" or "We make no assumptions. You must be precise in what you
>> > want". Being precise is important because it keeps the concept-API
>> > simpler, easier to remember, and easier to reason about.
>> >
>> > It may seem trivial at this point, but what if we add a feature for
>> > following keys instead of id's? And then what if we allow a row to
>> > stop traversal in a breadth first search scheme? Putting these into an
>> > "options variable" makes more sense to me because the concept is that
>> > they affect how the row is interpreted by the server vs what the row
>> > represents to the client.
>> >
>> > Granted that's just the purist argument and it doesn't really mean
>> > anything until there's an implementation. So until someone gives it a
>> > go and puts a patch in JIRA there's no reason to change the current
>> > behavior. I just don't want any future contributors to think this
>> > isn't an idea worth pursuing.
>> >
>> > Paul Davis
>> >
>>
>> I can see the argument now that you describe future features we might
>> build in this manner. However, I still think it's generally OK to muck
>> around in the value namespace, and I wouldn't be opposed to reserving
>> the _ namespace in view values (but I don't think it's necessary).
>>
>> We don't need to be very formal here. If someone is writing a view to
>> take advantage of include_docs special features (or key following, or
>> other future features) they will be able to write their view around
>> the feature implementation.
>>
>> So for hypothetical future instance, if you absolutely must have a
>> view with row values that look like {"_stop":true}, and you don't want
>> to trigger the stop-iteration, then simply don't query the view with
>> ?stop_on_stop=true. If you plan to use the (hypothetical) stop
>> iterator feature, then it's up to you to only have "_stop" : true in
>> your value when you mean it. I don't think this is a big deal, as
>> you'll be writing the map functions around these features anyway, so
>> you can always envelope anything: eg {"my_real_data":{"_stop":true},
>> "_stop" : false}.
>>
>> The bigger question is philosophical. I generally tend to recoil from
>> the purist argument, because once you start to go down that road you
>> face a danger of lots of implementation (and API) complexity for very
>> little practical benefit. I'm not saying I'd vote against a patch
>> here, but I think energy could be put to better use.
>>
>> Chris
>>
>>
>> --
>> Chris Anderson
>> http://jchrisa.net
>> http://couch.io
>>
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Nathan Stott <nr...@gmail.com>.
Sorry for dragging up an old discussion, but I'm curious as to if this
feature is in 0.10 and if there's documentation about it.  I did some
searching and could not locate any.

On Thu, Sep 17, 2009 at 10:44 PM, Chris Anderson <jc...@apache.org> wrote:

> On Thu, Sep 17, 2009 at 4:33 PM, Paul Davis <pa...@gmail.com>
> wrote:
> >> I guess what I'm saying is that I think the include doc "pointer"
> >> belongs in the value, not in some other place. It strikes me as
> >> exactly what emitted values are for, to hold arbitrary data associated
> >> with the key.
> >
> > By assigning implicit behavior based on the value, its no longer
> > arbitrary. _rev and now _id are restricted in what they can represent.
> > For instance, what happens if I emit {"_id": true} with
> > include_docs=true?
> >
> > Think of the third value as a "row options" variable. The two concepts
> > are basically "We make assumptions about what you wanted based on what
> > you emit" or "We make no assumptions. You must be precise in what you
> > want". Being precise is important because it keeps the concept-API
> > simpler, easier to remember, and easier to reason about.
> >
> > It may seem trivial at this point, but what if we add a feature for
> > following keys instead of id's? And then what if we allow a row to
> > stop traversal in a breadth first search scheme? Putting these into an
> > "options variable" makes more sense to me because the concept is that
> > they affect how the row is interpreted by the server vs what the row
> > represents to the client.
> >
> > Granted that's just the purist argument and it doesn't really mean
> > anything until there's an implementation. So until someone gives it a
> > go and puts a patch in JIRA there's no reason to change the current
> > behavior. I just don't want any future contributors to think this
> > isn't an idea worth pursuing.
> >
> > Paul Davis
> >
>
> I can see the argument now that you describe future features we might
> build in this manner. However, I still think it's generally OK to muck
> around in the value namespace, and I wouldn't be opposed to reserving
> the _ namespace in view values (but I don't think it's necessary).
>
> We don't need to be very formal here. If someone is writing a view to
> take advantage of include_docs special features (or key following, or
> other future features) they will be able to write their view around
> the feature implementation.
>
> So for hypothetical future instance, if you absolutely must have a
> view with row values that look like {"_stop":true}, and you don't want
> to trigger the stop-iteration, then simply don't query the view with
> ?stop_on_stop=true. If you plan to use the (hypothetical) stop
> iterator feature, then it's up to you to only have "_stop" : true in
> your value when you mean it. I don't think this is a big deal, as
> you'll be writing the map functions around these features anyway, so
> you can always envelope anything: eg {"my_real_data":{"_stop":true},
> "_stop" : false}.
>
> The bigger question is philosophical. I generally tend to recoil from
> the purist argument, because once you start to go down that road you
> face a danger of lots of implementation (and API) complexity for very
> little practical benefit. I'm not saying I'd vote against a patch
> here, but I think energy could be put to better use.
>
> Chris
>
>
> --
> Chris Anderson
> http://jchrisa.net
> http://couch.io
>

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Chris Anderson <jc...@apache.org>.
On Thu, Sep 17, 2009 at 4:33 PM, Paul Davis <pa...@gmail.com> wrote:
>> I guess what I'm saying is that I think the include doc "pointer"
>> belongs in the value, not in some other place. It strikes me as
>> exactly what emitted values are for, to hold arbitrary data associated
>> with the key.
>
> By assigning implicit behavior based on the value, its no longer
> arbitrary. _rev and now _id are restricted in what they can represent.
> For instance, what happens if I emit {"_id": true} with
> include_docs=true?
>
> Think of the third value as a "row options" variable. The two concepts
> are basically "We make assumptions about what you wanted based on what
> you emit" or "We make no assumptions. You must be precise in what you
> want". Being precise is important because it keeps the concept-API
> simpler, easier to remember, and easier to reason about.
>
> It may seem trivial at this point, but what if we add a feature for
> following keys instead of id's? And then what if we allow a row to
> stop traversal in a breadth first search scheme? Putting these into an
> "options variable" makes more sense to me because the concept is that
> they affect how the row is interpreted by the server vs what the row
> represents to the client.
>
> Granted that's just the purist argument and it doesn't really mean
> anything until there's an implementation. So until someone gives it a
> go and puts a patch in JIRA there's no reason to change the current
> behavior. I just don't want any future contributors to think this
> isn't an idea worth pursuing.
>
> Paul Davis
>

I can see the argument now that you describe future features we might
build in this manner. However, I still think it's generally OK to muck
around in the value namespace, and I wouldn't be opposed to reserving
the _ namespace in view values (but I don't think it's necessary).

We don't need to be very formal here. If someone is writing a view to
take advantage of include_docs special features (or key following, or
other future features) they will be able to write their view around
the feature implementation.

So for hypothetical future instance, if you absolutely must have a
view with row values that look like {"_stop":true}, and you don't want
to trigger the stop-iteration, then simply don't query the view with
?stop_on_stop=true. If you plan to use the (hypothetical) stop
iterator feature, then it's up to you to only have "_stop" : true in
your value when you mean it. I don't think this is a big deal, as
you'll be writing the map functions around these features anyway, so
you can always envelope anything: eg {"my_real_data":{"_stop":true},
"_stop" : false}.

The bigger question is philosophical. I generally tend to recoil from
the purist argument, because once you start to go down that road you
face a danger of lots of implementation (and API) complexity for very
little practical benefit. I'm not saying I'd vote against a patch
here, but I think energy could be put to better use.

Chris


-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Paul Davis <pa...@gmail.com>.
> I guess what I'm saying is that I think the include doc "pointer"
> belongs in the value, not in some other place. It strikes me as
> exactly what emitted values are for, to hold arbitrary data associated
> with the key.

By assigning implicit behavior based on the value, its no longer
arbitrary. _rev and now _id are restricted in what they can represent.
For instance, what happens if I emit {"_id": true} with
include_docs=true?

Think of the third value as a "row options" variable. The two concepts
are basically "We make assumptions about what you wanted based on what
you emit" or "We make no assumptions. You must be precise in what you
want". Being precise is important because it keeps the concept-API
simpler, easier to remember, and easier to reason about.

It may seem trivial at this point, but what if we add a feature for
following keys instead of id's? And then what if we allow a row to
stop traversal in a breadth first search scheme? Putting these into an
"options variable" makes more sense to me because the concept is that
they affect how the row is interpreted by the server vs what the row
represents to the client.

Granted that's just the purist argument and it doesn't really mean
anything until there's an implementation. So until someone gives it a
go and puts a patch in JIRA there's no reason to change the current
behavior. I just don't want any future contributors to think this
isn't an idea worth pursuing.

Paul Davis

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Chris Anderson <jc...@apache.org>.
On Thu, Sep 17, 2009 at 3:57 PM, Paul Davis <pa...@gmail.com> wrote:
> On Thu, Sep 17, 2009 at 6:54 PM, Chris Anderson <jc...@apache.org> wrote:
>> On Thu, Sep 17, 2009 at 9:08 AM, Paul Davis <pa...@gmail.com> wrote:
>>> On Thu, Sep 17, 2009 at 11:58 AM, Chris Anderson <jc...@apache.org> wrote:
>>>> On Thu, Sep 17, 2009 at 7:11 AM, Curt Arnold <ca...@apache.org> wrote:
>>>>>
>>>>> On Sep 16, 2009, at 11:51 PM, Paul Davis wrote:
>>>>>>>>
>>>>>>>> In Governator voice: "It's not a JOIN."
>>>>>>>>
>>>>>>>> But you can use it if you have a doc like:
>>>>>>>>
>>>>>>>> {"_id":"my-outline",
>>>>>>>> "other_docs":["docid,"other-docid"]
>>>>>>>> }
>>>>>>>>
>>>>>>>> and then a view like
>>>>>>>>
>>>>>>>> function(doc) {
>>>>>>>> for (var i=0; i < doc.other_docs.length; i++) {
>>>>>>>>  emit([doc._id, i], {"_id" : doc.other_docs[i]}
>>>>>>>> };
>>>>>>>> }
>>>>>
>>>>>
>>>>> So if I do,
>>>>>
>>>>> emit(key, doc)
>>>>>
>>>>> am I specifying the key value and overriding the default document to be
>>>>> included since the value would contain _id and _rev members?  They'd have
>>>>> the same value, so it wouldn't be detectable, but still no clear boundary
>>>>> between the value parts of the parameter and the document part of the
>>>>> parameter.
>>>>>
>>>>>
>>>>>>
>>>>>>> I'm thinking it would be cleaner to support an optional 3 argument to
>>>>>>> emit
>>>>>>> with { _id:"", _rev:"" }?  The current two argument emit() would be the
>>>>>>> equivalent of emit(key, value, { _id:doc._id, _rev:doc.rev}).
>>>>>>>
>>>>>>
>>>>>> I think this is a pretty good idea. Though unless I'm missing
>>>>>> something the implementation difficulty rises noticeably. The only
>>>>>> initial drawback I see is how we explain the semantics of default
>>>>>> behavior. For ?include_docs=true it was simply "current version or
>>>>>> version specified by _rev". Obviously adding _id makes that weirder,
>>>>>> but I'm don't see a more clear explanation with the third parameter
>>>>>> version.
>>>>>>
>>>>>> Paul Davis
>>>>>
>>>>>
>>>>> A three parameter version would also allow like:
>>>>>
>>>>> emit(key, value, null);
>>>>>
>>>>> when you intentionally do not want any documents provided if the user
>>>>> specifies include_docs=true.
>>>>>
>>>>>
>>>>
>>>> I don't see a use case for the 3 parameter version.
>>>>
>>>
>>> I think its more about having a clean API. Using members on the value
>>> does confuse the semantics quite a bit. Pragmatically though, it
>>> wouldn't really change the end result.
>>>
>>>> If you are writing a view to take advantage of the linking feature,
>>>> you would know that you are working to specify the linked doc _id and
>>>> perhaps _rev in the value.
>>>>
>>>> If you aren't planning on using include docs, or just want the normal
>>>> version of the feature, (include the doc that emitted) then you can
>>>> just ignore the whole thing.
>>>>
>>>> Generally I'm leaning strongly toward keep-it-super-simple, as
>>>> anything that a user wants to do is possible with the API as it
>>>> exists. (If you want to emit a full doc but link to another, you can
>>>> stick the emitted doc in an envelope.)
>>>>
>>>> Chris
>>>>
>>>>
>>>>
>>>> --
>>>> Chris Anderson
>>>> http://jchrisa.net
>>>> http://couch.io
>>>>
>>>
>>> While the third parameter option is definitely cleaner in terms of API
>>> design, I would have to agree that the cost in terms of added
>>> implementation complexity is a bit forbidding. For the moment without
>>> attempting the implementation I'd leave it as is, but would be in
>>> favor of the three parameter version if someone provides a patch.
>>>
>>> Specifically, the added complexity is going to come from how the third
>>> parameter is stored in the btree, how it affects sorting semantics,
>>> and how it relates to reductions. And that's just off the top of my
>>> head without trying to write the code.
>>>
>>
>> Yeah let's just punt on that, I don't see any value there. If people
>> are getting concerned about semantics I'd be fine suggesting we change
>> the whole thing to be emit(key, {"foo":"bar", "_include_doc" : {"_id"
>> : "X", "_rev":"1-abc"}}) but that just seems gratuitous and
>> overthought.
>>
>
> There's plenty of value to adding it. Its just that there's also
> plenty of complexity. I may or may not take a crack at implementing
> it, but for now I agree that its not a priority.

I guess what I'm saying is that I think the include doc "pointer"
belongs in the value, not in some other place. It strikes me as
exactly what emitted values are for, to hold arbitrary data associated
with the key.

Chris

>
>>> Paul Davis
>>>
>>
>>
>>
>> --
>> Chris Anderson
>> http://jchrisa.net
>> http://couch.io
>>
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Paul Davis <pa...@gmail.com>.
On Thu, Sep 17, 2009 at 6:54 PM, Chris Anderson <jc...@apache.org> wrote:
> On Thu, Sep 17, 2009 at 9:08 AM, Paul Davis <pa...@gmail.com> wrote:
>> On Thu, Sep 17, 2009 at 11:58 AM, Chris Anderson <jc...@apache.org> wrote:
>>> On Thu, Sep 17, 2009 at 7:11 AM, Curt Arnold <ca...@apache.org> wrote:
>>>>
>>>> On Sep 16, 2009, at 11:51 PM, Paul Davis wrote:
>>>>>>>
>>>>>>> In Governator voice: "It's not a JOIN."
>>>>>>>
>>>>>>> But you can use it if you have a doc like:
>>>>>>>
>>>>>>> {"_id":"my-outline",
>>>>>>> "other_docs":["docid,"other-docid"]
>>>>>>> }
>>>>>>>
>>>>>>> and then a view like
>>>>>>>
>>>>>>> function(doc) {
>>>>>>> for (var i=0; i < doc.other_docs.length; i++) {
>>>>>>>  emit([doc._id, i], {"_id" : doc.other_docs[i]}
>>>>>>> };
>>>>>>> }
>>>>
>>>>
>>>> So if I do,
>>>>
>>>> emit(key, doc)
>>>>
>>>> am I specifying the key value and overriding the default document to be
>>>> included since the value would contain _id and _rev members?  They'd have
>>>> the same value, so it wouldn't be detectable, but still no clear boundary
>>>> between the value parts of the parameter and the document part of the
>>>> parameter.
>>>>
>>>>
>>>>>
>>>>>> I'm thinking it would be cleaner to support an optional 3 argument to
>>>>>> emit
>>>>>> with { _id:"", _rev:"" }?  The current two argument emit() would be the
>>>>>> equivalent of emit(key, value, { _id:doc._id, _rev:doc.rev}).
>>>>>>
>>>>>
>>>>> I think this is a pretty good idea. Though unless I'm missing
>>>>> something the implementation difficulty rises noticeably. The only
>>>>> initial drawback I see is how we explain the semantics of default
>>>>> behavior. For ?include_docs=true it was simply "current version or
>>>>> version specified by _rev". Obviously adding _id makes that weirder,
>>>>> but I'm don't see a more clear explanation with the third parameter
>>>>> version.
>>>>>
>>>>> Paul Davis
>>>>
>>>>
>>>> A three parameter version would also allow like:
>>>>
>>>> emit(key, value, null);
>>>>
>>>> when you intentionally do not want any documents provided if the user
>>>> specifies include_docs=true.
>>>>
>>>>
>>>
>>> I don't see a use case for the 3 parameter version.
>>>
>>
>> I think its more about having a clean API. Using members on the value
>> does confuse the semantics quite a bit. Pragmatically though, it
>> wouldn't really change the end result.
>>
>>> If you are writing a view to take advantage of the linking feature,
>>> you would know that you are working to specify the linked doc _id and
>>> perhaps _rev in the value.
>>>
>>> If you aren't planning on using include docs, or just want the normal
>>> version of the feature, (include the doc that emitted) then you can
>>> just ignore the whole thing.
>>>
>>> Generally I'm leaning strongly toward keep-it-super-simple, as
>>> anything that a user wants to do is possible with the API as it
>>> exists. (If you want to emit a full doc but link to another, you can
>>> stick the emitted doc in an envelope.)
>>>
>>> Chris
>>>
>>>
>>>
>>> --
>>> Chris Anderson
>>> http://jchrisa.net
>>> http://couch.io
>>>
>>
>> While the third parameter option is definitely cleaner in terms of API
>> design, I would have to agree that the cost in terms of added
>> implementation complexity is a bit forbidding. For the moment without
>> attempting the implementation I'd leave it as is, but would be in
>> favor of the three parameter version if someone provides a patch.
>>
>> Specifically, the added complexity is going to come from how the third
>> parameter is stored in the btree, how it affects sorting semantics,
>> and how it relates to reductions. And that's just off the top of my
>> head without trying to write the code.
>>
>
> Yeah let's just punt on that, I don't see any value there. If people
> are getting concerned about semantics I'd be fine suggesting we change
> the whole thing to be emit(key, {"foo":"bar", "_include_doc" : {"_id"
> : "X", "_rev":"1-abc"}}) but that just seems gratuitous and
> overthought.
>

There's plenty of value to adding it. Its just that there's also
plenty of complexity. I may or may not take a crack at implementing
it, but for now I agree that its not a priority.

>> Paul Davis
>>
>
>
>
> --
> Chris Anderson
> http://jchrisa.net
> http://couch.io
>

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Chris Anderson <jc...@apache.org>.
On Thu, Sep 17, 2009 at 9:08 AM, Paul Davis <pa...@gmail.com> wrote:
> On Thu, Sep 17, 2009 at 11:58 AM, Chris Anderson <jc...@apache.org> wrote:
>> On Thu, Sep 17, 2009 at 7:11 AM, Curt Arnold <ca...@apache.org> wrote:
>>>
>>> On Sep 16, 2009, at 11:51 PM, Paul Davis wrote:
>>>>>>
>>>>>> In Governator voice: "It's not a JOIN."
>>>>>>
>>>>>> But you can use it if you have a doc like:
>>>>>>
>>>>>> {"_id":"my-outline",
>>>>>> "other_docs":["docid,"other-docid"]
>>>>>> }
>>>>>>
>>>>>> and then a view like
>>>>>>
>>>>>> function(doc) {
>>>>>> for (var i=0; i < doc.other_docs.length; i++) {
>>>>>>  emit([doc._id, i], {"_id" : doc.other_docs[i]}
>>>>>> };
>>>>>> }
>>>
>>>
>>> So if I do,
>>>
>>> emit(key, doc)
>>>
>>> am I specifying the key value and overriding the default document to be
>>> included since the value would contain _id and _rev members?  They'd have
>>> the same value, so it wouldn't be detectable, but still no clear boundary
>>> between the value parts of the parameter and the document part of the
>>> parameter.
>>>
>>>
>>>>
>>>>> I'm thinking it would be cleaner to support an optional 3 argument to
>>>>> emit
>>>>> with { _id:"", _rev:"" }?  The current two argument emit() would be the
>>>>> equivalent of emit(key, value, { _id:doc._id, _rev:doc.rev}).
>>>>>
>>>>
>>>> I think this is a pretty good idea. Though unless I'm missing
>>>> something the implementation difficulty rises noticeably. The only
>>>> initial drawback I see is how we explain the semantics of default
>>>> behavior. For ?include_docs=true it was simply "current version or
>>>> version specified by _rev". Obviously adding _id makes that weirder,
>>>> but I'm don't see a more clear explanation with the third parameter
>>>> version.
>>>>
>>>> Paul Davis
>>>
>>>
>>> A three parameter version would also allow like:
>>>
>>> emit(key, value, null);
>>>
>>> when you intentionally do not want any documents provided if the user
>>> specifies include_docs=true.
>>>
>>>
>>
>> I don't see a use case for the 3 parameter version.
>>
>
> I think its more about having a clean API. Using members on the value
> does confuse the semantics quite a bit. Pragmatically though, it
> wouldn't really change the end result.
>
>> If you are writing a view to take advantage of the linking feature,
>> you would know that you are working to specify the linked doc _id and
>> perhaps _rev in the value.
>>
>> If you aren't planning on using include docs, or just want the normal
>> version of the feature, (include the doc that emitted) then you can
>> just ignore the whole thing.
>>
>> Generally I'm leaning strongly toward keep-it-super-simple, as
>> anything that a user wants to do is possible with the API as it
>> exists. (If you want to emit a full doc but link to another, you can
>> stick the emitted doc in an envelope.)
>>
>> Chris
>>
>>
>>
>> --
>> Chris Anderson
>> http://jchrisa.net
>> http://couch.io
>>
>
> While the third parameter option is definitely cleaner in terms of API
> design, I would have to agree that the cost in terms of added
> implementation complexity is a bit forbidding. For the moment without
> attempting the implementation I'd leave it as is, but would be in
> favor of the three parameter version if someone provides a patch.
>
> Specifically, the added complexity is going to come from how the third
> parameter is stored in the btree, how it affects sorting semantics,
> and how it relates to reductions. And that's just off the top of my
> head without trying to write the code.
>

Yeah let's just punt on that, I don't see any value there. If people
are getting concerned about semantics I'd be fine suggesting we change
the whole thing to be emit(key, {"foo":"bar", "_include_doc" : {"_id"
: "X", "_rev":"1-abc"}}) but that just seems gratuitous and
overthought.

> Paul Davis
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Paul Davis <pa...@gmail.com>.
On Thu, Sep 17, 2009 at 11:58 AM, Chris Anderson <jc...@apache.org> wrote:
> On Thu, Sep 17, 2009 at 7:11 AM, Curt Arnold <ca...@apache.org> wrote:
>>
>> On Sep 16, 2009, at 11:51 PM, Paul Davis wrote:
>>>>>
>>>>> In Governator voice: "It's not a JOIN."
>>>>>
>>>>> But you can use it if you have a doc like:
>>>>>
>>>>> {"_id":"my-outline",
>>>>> "other_docs":["docid,"other-docid"]
>>>>> }
>>>>>
>>>>> and then a view like
>>>>>
>>>>> function(doc) {
>>>>> for (var i=0; i < doc.other_docs.length; i++) {
>>>>>  emit([doc._id, i], {"_id" : doc.other_docs[i]}
>>>>> };
>>>>> }
>>
>>
>> So if I do,
>>
>> emit(key, doc)
>>
>> am I specifying the key value and overriding the default document to be
>> included since the value would contain _id and _rev members?  They'd have
>> the same value, so it wouldn't be detectable, but still no clear boundary
>> between the value parts of the parameter and the document part of the
>> parameter.
>>
>>
>>>
>>>> I'm thinking it would be cleaner to support an optional 3 argument to
>>>> emit
>>>> with { _id:"", _rev:"" }?  The current two argument emit() would be the
>>>> equivalent of emit(key, value, { _id:doc._id, _rev:doc.rev}).
>>>>
>>>
>>> I think this is a pretty good idea. Though unless I'm missing
>>> something the implementation difficulty rises noticeably. The only
>>> initial drawback I see is how we explain the semantics of default
>>> behavior. For ?include_docs=true it was simply "current version or
>>> version specified by _rev". Obviously adding _id makes that weirder,
>>> but I'm don't see a more clear explanation with the third parameter
>>> version.
>>>
>>> Paul Davis
>>
>>
>> A three parameter version would also allow like:
>>
>> emit(key, value, null);
>>
>> when you intentionally do not want any documents provided if the user
>> specifies include_docs=true.
>>
>>
>
> I don't see a use case for the 3 parameter version.
>

I think its more about having a clean API. Using members on the value
does confuse the semantics quite a bit. Pragmatically though, it
wouldn't really change the end result.

> If you are writing a view to take advantage of the linking feature,
> you would know that you are working to specify the linked doc _id and
> perhaps _rev in the value.
>
> If you aren't planning on using include docs, or just want the normal
> version of the feature, (include the doc that emitted) then you can
> just ignore the whole thing.
>
> Generally I'm leaning strongly toward keep-it-super-simple, as
> anything that a user wants to do is possible with the API as it
> exists. (If you want to emit a full doc but link to another, you can
> stick the emitted doc in an envelope.)
>
> Chris
>
>
>
> --
> Chris Anderson
> http://jchrisa.net
> http://couch.io
>

While the third parameter option is definitely cleaner in terms of API
design, I would have to agree that the cost in terms of added
implementation complexity is a bit forbidding. For the moment without
attempting the implementation I'd leave it as is, but would be in
favor of the three parameter version if someone provides a patch.

Specifically, the added complexity is going to come from how the third
parameter is stored in the btree, how it affects sorting semantics,
and how it relates to reductions. And that's just off the top of my
head without trying to write the code.

Paul Davis

Re: Its not a JOIN (was Re: svn commit: r815984 - in /couchdb/trunk: share/www/script/test/view_include_docs.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl)

Posted by Chris Anderson <jc...@apache.org>.
On Thu, Sep 17, 2009 at 7:11 AM, Curt Arnold <ca...@apache.org> wrote:
>
> On Sep 16, 2009, at 11:51 PM, Paul Davis wrote:
>>>>
>>>> In Governator voice: "It's not a JOIN."
>>>>
>>>> But you can use it if you have a doc like:
>>>>
>>>> {"_id":"my-outline",
>>>> "other_docs":["docid,"other-docid"]
>>>> }
>>>>
>>>> and then a view like
>>>>
>>>> function(doc) {
>>>> for (var i=0; i < doc.other_docs.length; i++) {
>>>>  emit([doc._id, i], {"_id" : doc.other_docs[i]}
>>>> };
>>>> }
>
>
> So if I do,
>
> emit(key, doc)
>
> am I specifying the key value and overriding the default document to be
> included since the value would contain _id and _rev members?  They'd have
> the same value, so it wouldn't be detectable, but still no clear boundary
> between the value parts of the parameter and the document part of the
> parameter.
>
>
>>
>>> I'm thinking it would be cleaner to support an optional 3 argument to
>>> emit
>>> with { _id:"", _rev:"" }?  The current two argument emit() would be the
>>> equivalent of emit(key, value, { _id:doc._id, _rev:doc.rev}).
>>>
>>
>> I think this is a pretty good idea. Though unless I'm missing
>> something the implementation difficulty rises noticeably. The only
>> initial drawback I see is how we explain the semantics of default
>> behavior. For ?include_docs=true it was simply "current version or
>> version specified by _rev". Obviously adding _id makes that weirder,
>> but I'm don't see a more clear explanation with the third parameter
>> version.
>>
>> Paul Davis
>
>
> A three parameter version would also allow like:
>
> emit(key, value, null);
>
> when you intentionally do not want any documents provided if the user
> specifies include_docs=true.
>
>

I don't see a use case for the 3 parameter version.

If you are writing a view to take advantage of the linking feature,
you would know that you are working to specify the linked doc _id and
perhaps _rev in the value.

If you aren't planning on using include docs, or just want the normal
version of the feature, (include the doc that emitted) then you can
just ignore the whole thing.

Generally I'm leaning strongly toward keep-it-super-simple, as
anything that a user wants to do is possible with the API as it
exists. (If you want to emit a full doc but link to another, you can
stick the emitted doc in an envelope.)

Chris



-- 
Chris Anderson
http://jchrisa.net
http://couch.io