couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mauro Fagnoni <mauro.fagn...@gmail.com>
Subject Re: convert data query into map/reduce function
Date Wed, 18 May 2011 14:21:09 GMT
since you asked me many try to be more clear.
I'm trying to verifing in my thesis, what are the cases where it is best to
use a relational database, and what a nosql.
I'm now considering if and in what cases can pass from a relational database
to a nosql.
I took two columns in the TPC-H test and their query and am trying to convert
them so they can be processed on couchdb. (i've created alredy a valid json
document )
That's why I posted the SQL standard and I wondered how it was possible to
convert couch because I query the database via curl.


at the moment i tried to write the query in this way but now I'm stopped in the
conversion can we give me an hands and correct my errors???


curl -X POST http://127.0.0.1:5984/testdb/_temp_view -H "Content-Type:
application/json" -d'{
    "map":"function("doc")
        {if(doc.l_shipdate <= 1998-09-01) emit([doc.l_returnflag,
doc.l_linestate], doc)}"
    "reduce":"function(key,value,rereduce)
        {var sum_qty=0, sum_base_price=0, sum_disc_price=0, sum_charge,
avg_qty=0;
            for(var i=0; i<values.lenght; i++)
                {
                    sum_qty += values[i].l_quantity;
                    sum_base_price += values[i].l_extendedprice;
                    sum_disc_price +=
values[i].l_extendedprice*(1-values[i].l_discount);
                    sum charge +=
values[i].l_exetendedprice*(1-values[i].l_discount)*(1+values[i].l_tax);
                    avg_qty = values[i].l_quantity/ values.lenght;

                    /*The last two are still missing and avg count command*/
                }

                return {/*return object which are they?/}
         }
}


Best regard and thanks for us patience


2011/5/16 Sean Copenhaver <sean.copenhaver@gmail.com>

> Dang hit the wrong key!
>
> Usually the convention is you have some kind of 'type' attribute (so type
> checking) on your documents or you check that all the fields you are
> interested in exist (more of the duck approach) in your map function. So
> perhaps your map function is something like:
>
> function(doc){
>    if (doc.type != 'line_item') return;
>
>     emit([doc.l_shipdate, doc.l_returnflag, doc.l_linestate], doc);
> }
>
> reduce function would then aggregate everything:
>
> function(key, values, rereduce){
>   var sum_qty = 0;
>   for(var i = 0; i < values.length; i++){
>       sum_qty += values[i].l_quantity;
>   }
>
>   /* aggregate others */
>
>   return {
>      /* build return object */
>   }
> }
>
> You can filter by date with parameters to the view something like
> 'startkey=["<date to filter>"]' in the query parameters.
>
> Just trying to give you a rough idea (hopefully helping more the hurting
> yoru understanding), although there is probably a better way to do this.
> You
> may want to check out the book for some basic info.
> http://guide.couchdb.org/draft/cookbook.html
>
> On Mon, May 16, 2011 at 11:35 AM, Sean Copenhaver <
> sean.copenhaver@gmail.com
> > wrote:
>
> > Usually the convention is you have some kind of 'type' attribute (so type
> > checking) on your documents or you check that all the fields you are
> > interested in exist (more of the duck approach) in your map function. So
> > perhaps your map function is something like:
> >
> > function(doc){
> >     if (doc.type != 'line_item') return;
> >
> >     var value = {
> >
> >
> >
> >     emit([doc.l_shipdate, doc.l_returnflag, doc.l_linestate], {
> > }
> >
> > On Mon, May 16, 2011 at 11:06 AM, Mauro Fagnoni <mauro.fagnoni@gmail.com
> >wrote:
> >
> >> Stefan I'm trying to convert this sql query in an identical to the
> >> document
> >> I created in couchdb. Unfortunately, it is the first time using this
> >> database and would like to understand how to translate the query using
> >> only
> >> the wiki because I have not figured out how to do a lot
> >>
> >> 2011/5/16 Stefan Matheis <matheis.stefan@googlemail.com>
> >>
> >> > i think a short example would be really helpful .. especially related
> >> > to your data-structure .. and the expected behaviour. do you already
> >> > have an reduce function, but it does not work like you'd have it to?
> >> >
> >>
> >>
> >>
> >> --
> >> -----------------------------------------------
> >> [-------WHOAMI------] Mauro Fagnoni
> >> [----------ICQ#---------] 279572903
> >> [--------MSNID--------] maurofagnoni@yahoo.it
> >> [--YAHOOMSNID--] maurofagnoni@gmail.com
> >> [--GOOGLETALK--] mauro.fagnoni@gmail.com
> >> [-GOOGLEWAVE-] mauro.fagnoni@googlewave.com
> >> [------JABBER-------] mauro.fagnoni@gmail.com
> >> [------SKYPE--------] mauro.fagnoni
> >> [-----LinuxUser#----] 346345
> >> [----------Blog---------] http://kingmauro.wordpress.com
> >> -----------------------------------------------
> >>
> >
> >
> >
> > --
> > “The limits of language are the limits of one's world. “ -Ludwig von
> > Wittgenstein
> >
>
>
>
> --
> “The limits of language are the limits of one's world. “ -Ludwig von
> Wittgenstein
>



-- 
-----------------------------------------------
[-------WHOAMI------] Mauro Fagnoni
[----------ICQ#---------] 279572903
[--------MSNID--------] maurofagnoni@yahoo.it
[--YAHOOMSNID--] maurofagnoni@gmail.com
[--GOOGLETALK--] mauro.fagnoni@gmail.com
[-GOOGLEWAVE-] mauro.fagnoni@googlewave.com
[------JABBER-------] mauro.fagnoni@gmail.com
[------SKYPE--------] mauro.fagnoni
[-----LinuxUser#----] 346345
[----------Blog---------] http://kingmauro.wordpress.com
-----------------------------------------------

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message