incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hahn <m...@boutiquing.com>
Subject Re: error during map function
Date Sun, 29 May 2011 18:59:50 GMT
Did you fix your syntax errors?  You can use jslint to do that before
I help you. You can ignore the jslint non-syntax errors.

On Sun, May 29, 2011 at 7:40 AM, Mauro Fagnoni <mauro.fagnoni@gmail.com> wrote:
> ok i see the problem but i have no a solution....could you give a hand?
>
> 2011/5/27 Mark Hahn <mark@boutiquing.com>
>
>> Use http://www.jslint.com/ to check your syntax.  I changed the first
>> part to read like this so it looked liked normal js instead of a big
>> string ...
>>
>> x=function(doc){
>>        if{((doc.partkey == doc.parteky) &&
>>
>> It immediately saw the if { which is illegal.  It found other errors as
>> well.
>>
>> On Fri, May 27, 2011 at 10:56 AM, Mauro Fagnoni <mauro.fagnoni@gmail.com>
>> wrote:
>> > Hi all i've to adjust this sql query into a valid .js query for couchdb
>> but
>> > i've an error...someone help to find and solve my error???
>> >
>> > Best regards
>> >
>> > .js query
>> >
>> > {
>> >    "map":"function(doc){
>> >        if{((doc.partkey == doc.parteky) &&
>> >           (doc.brand == 'Brand#12') &&
>> >           (if {(doc.container == 'SM CASE') || (doc.container == 'SM
>> BOX')
>> > (doc.container == 'SM PACK') || (doc.container == 'SM PKG')
>> >               doc.container=true;
>> >            }else{doc.container=false;}
>> >           ) &&
>> >           (doc.quantity >= 1) &&
>> >           (doc.quantity <= 11) &&
>> >           (doc.size > 1) &&
>> >           (doc.size < 5) &&
>> >           (if {(doc.shipmode == 'AIR')|| (doc.shipmode == 'AIR REG')
>> >                    doc.shipmode = true;
>> >                }else {doc.shipmode = falese}&&
>> >           (doc.shipinstruct == 'DELIVER IN PERSON')
>> >        )} ||
>> >         if{((doc.partkey == doc.parteky)&&
>> >               (doc.brand == 'Brand#23') &&
>> >               (if {(doc.container == 'MED BAG') || (doc.container ==
'MED
>> > BOX') (doc.container == 'MED PKG') || (doc.container == 'MED PACK')
>> >                     doc.container=true;
>> >                }else{doc.container=false;}
>> >               ) &&
>> >               (doc.quantity >= 10) &&
>> >               (doc.quantity <= 20) &&
>> >               (doc.size > 1) &&
>> >               (doc.size < 10) &&
>> >               (if {(doc.container == 'MED BAG') || (doc.container ==
'MED
>> > BOX') (doc.container == 'MED PKG') || (doc.container == 'MED PACK')
>> >                     doc.container=true;
>> >                }else{doc.container=false;}
>> >               ) &&
>> >               (doc.shipinstruct == 'DELIVER IN PERSON')
>> >        )} ||
>> >        if{((doc.partkey == doc.parteky) &&
>> >               (doc.brand == 'Brand#34') &&
>> >                    (if {(doc.container == 'LG CASE') || (doc.container
==
>> > 'LG BOX') (doc.container == 'LG PACK') || (doc.container == 'LG PKG')
>> >                   doc.container=true;
>> >                }else{doc.container=false;}
>> >               ) &&
>> >            (doc.quantity >= 20) &&
>> >               (doc.quantity <= 30) &&
>> >               (doc.size > 1) &&
>> >               (doc.size < 15) &&
>> >              (if {(doc.container == 'MED BAG') || (doc.container == 'MED
>> > BOX') (doc.container == 'MED PKG') || (doc.container == 'MED PACK')
>> >                     doc.container=true;
>> >                }else{doc.container=false;}
>> >               ) &&
>> >               (doc.shipinstruct == 'DELIVER IN PERSON')
>> >        )}
>> >    emit (null, doc)
>> >    }" ,
>> >    "reduce": "
>> >        function(keys, values, rereduce){
>> >        var tags = {};
>> >        if(!rereduce){
>> >            for (var k in keys) {
>> >                var extPrice = parseFloat(values[k].extendedprice);
>> >                var disc1 = 1-parseFloat(values[k].discount);
>> >                if(tags[key[k][0]]){
>> >                    tags[keys[k][0]].revenue += extPrice * disc1;
>> >                }
>> >                else tags[keys[k][0]] = {
>> >                    'revenue' : extPrice * disc1
>> >                };
>> >            }
>> >        }else{
>> >            tags = values[0];
>> >                    for(var v = 1; v < values.length; v++)
>> >                    {
>> >                        for(var t in values[v])
>> >                        {
>> >                                if(tags[t]) {
>> >                        tags[t].revenue += values[v][t].revenue;
>> >                        }
>> >                }
>> >            }
>> >        }
>> >        return tags;
>> >    }"
>> > }
>> >
>> >
>> > sql query
>> >
>> > SELECT
>> >               sum(L_EXTENDEDPRICE * (1 - L_DISCOUNT) ) as revenue
>> >               FROM
>> >               LINEITEM,
>> >               PART
>> >               WHERE
>> >               (
>> >               P_PARTKEY = L_PARTKEY
>> >               and P_BRAND = 'Brand#12'
>> >               and P_CONTAINER in ( 'SM CASE', 'SM BOX', 'SM PACK', 'SM
>> > PKG')
>> >               and L_QUANTITY >= 1 and L_QUANTITY <= 1 + 10
>> >               and P_SIZE between 1 and 5
>> >               and L_SHIPMODE in ('AIR', 'AIR REG')
>> >               and L_SHIPINSTRUCT = 'DELIVER IN PERSON'
>> >               )
>> >               or
>> >               (
>> >               P_PARTKEY = L_PARTKEY
>> >               and P_BRAND = 'Brand#23'
>> >               and P_CONTAINER in ('MED BAG', 'MED BOX', 'MED PKG', 'MED
>> > PACK')
>> >               and L_QUANTITY >= 10 and L_QUANTITY <= 10 + 10
>> >               and P_SIZE between 1 and 10
>> >               and L_SHIPMODE in ('AIR', 'AIR REG')
>> >               and L_SHIPINSTRUCT = 'DELIVER IN PERSON'
>> >               )
>> >               or
>> >               (
>> >               P_PARTKEY = L_PARTKEY
>> >               and P_BRAND = 'Brand#34'
>> >               and P_CONTAINER in ( 'LG CASE', 'LG BOX', 'LG PACK', 'LG
>> > PKG')
>> >               and L_QUANTITY >= 20 and L_QUANTITY <= 20 + 10
>> >               and P_SIZE between 1 and 15
>> >               and L_SHIPMODE in ('AIR', 'AIR REG')
>> >               and L_SHIPINSTRUCT = 'DELIVER IN PERSON;
>> >
>> >
>> > error log
>> >
>> > {"error":"compilation_error","reason":"Expression does not eval to a
>> > function. ((new String(\"function(doc){\\n\\t\\tif{((doc.partkey ==
>> > doc.parteky) && \\n\\t\\t   (doc.brand == 'Brand#12') &&\\n\\t\\t
  (if
>> > {(doc.container == 'SM CASE') || (doc.container == 'SM BOX')
>> (doc.container
>> > == 'SM PACK') || (doc.container == 'SM PKG')\\n\\t\\t
>> > \\tdoc.container=true;\\n\\t\\t\\t}else{doc.container=false;}\\n\\t\\t
>> )
>> > &&\\n\\t\\t   (doc.quantity >= 1) &&\\n\\t\\t   (doc.quantity
<= 11)
>> > &&\\n\\t\\t   (doc.size > 1) &&\\n\\t\\t   (doc.size <
5) &&\\n\\t\\t
>> (if
>> > {(doc.shipmode == 'AIR')|| (doc.shipmode == 'AIR
>> > REG')\\n\\t\\t\\t\\t\\tdoc.shipmode = true;\\n\\t\\t\\t\\t}else
>> > {doc.shipmode = falese}&&\\n\\t\\t   (doc.shipinstruct == 'DELIVER
IN
>> > PERSON')\\n\\t\\t)} ||\\n\\t\\t if{((doc.partkey == doc.parteky)&&
>> > \\n\\t\\t   \\t(doc.brand == 'Brand#23') &&\\n\\t\\t   \\t(if
>> > {(doc.container == 'MED BAG') || (doc.container == 'MED BOX')
>> (doc.container
>> > == 'MED PKG') || (doc.container == 'MED PACK')\\n\\t\\t   \\t
>> > doc.container=true;\\n\\t\\t\\t    }else{doc.container=false;}\\n\\t\\t
>> > \\t) &&\\n\\t\\t   \\t(doc.quantity >= 10) &&\\n\\t\\t  
\\t(doc.quantity
>> <=
>> > 20) &&\\n\\t\\t   \\t(doc.size > 1) &&\\n\\t\\t   \\t(doc.size
< 10)
>> > &&\\n\\t\\t   \\t(if {(doc.container == 'MED BAG') || (doc.container
==
>> 'MED
>> > BOX') (doc.container == 'MED PKG') || (doc.container == 'MED
>> > PACK')\\n\\t\\t   \\t      doc.container=true;\\n\\t\\t\\t
>> > }else{doc.container=false;}\\n\\t\\t   \\t) &&\\n\\t\\t
>> > \\t(doc.shipinstruct == 'DELIVER IN PERSON')\\n\\t\\t)}
>> > ||\\n\\t\\tif{((doc.partkey == doc.parteky) && \\n\\t\\t   \\t(doc.brand
>> ==
>> > 'Brand#34') &&\\n        \\t        (if {(doc.container == 'LG
CASE') ||
>> > (doc.container == 'LG BOX') (doc.container == 'LG PACK') ||
>> (doc.container
>> > == 'LG PKG')\\n\\t\\t   \\t\\tdoc.container=true;\\n\\t\\t\\t
>> > }else{doc.container=false;}\\n\\t\\t   \\t) &&\\n\\t\\t\\t(doc.quantity
>> >=
>> > 20) &&\\n\\t\\t   \\t(doc.quantity <= 30) &&\\n\\t\\t  
\\t(doc.size > 1)
>> > &&\\n\\t\\t   \\t(doc.size < 15) &&\\n\\t\\t  \\t(if {(doc.container
==
>> 'MED
>> > BAG') || (doc.container == 'MED BOX') (doc.container == 'MED PKG') ||
>> > (doc.container == 'MED PACK')\\n\\t\\t   \\t
>> > doc.container=true;\\n\\t\\t\\t    }else{doc.container=false;}\\n\\t\\t
>> > \\t) &&\\n\\t\\t   \\t(doc.shipinstruct == 'DELIVER IN
>> > PERSON')\\n\\t\\t)}\\n\\temit (null, doc)\\n\\t}\")))"}
>> >
>> > -- -----------------------------------------------
>> > [-------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
>> > -----------------------------------------------
>> >
>>
>>
>>
>> --
>> Mark Hahn
>> Website Manager
>> mark@boutiquing.com
>> 949-229-1012
>>
>
>
>
> --
> -----------------------------------------------
> [-------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
> -----------------------------------------------
>



-- 
Mark Hahn
Website Manager
mark@boutiquing.com
949-229-1012

Mime
View raw message