Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E84C04B2C for ; Tue, 31 May 2011 23:57:06 +0000 (UTC) Received: (qmail 31770 invoked by uid 500); 31 May 2011 23:57:05 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 31732 invoked by uid 500); 31 May 2011 23:57:05 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 31724 invoked by uid 99); 31 May 2011 23:57:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 May 2011 23:57:05 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mrtrick@gmail.com designates 209.85.160.52 as permitted sender) Received: from [209.85.160.52] (HELO mail-pw0-f52.google.com) (209.85.160.52) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 May 2011 23:56:58 +0000 Received: by pwi4 with SMTP id 4so3049703pwi.11 for ; Tue, 31 May 2011 16:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=SeKbwQE92nNK9qPnbmii1AmXkMM39su3yCslQa1SATA=; b=x2TH+e4cQnB1h0n2FNQEMHLTUsH1LcxtotLiSdaFQg2WgNGtk3yWl4MvfRD4GqCiaD zTeY6Srafr562Y1X+30sF4+dxXQrtuDxBuINKMh93Tf6g8VfNhkie+XDp0L9w4XMYM4V 3BNCKzdRrSNGOmvYvWANSb2geUmtmeKRk7xxM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=B3FXiy54tgyX5WTe+RQOJ9xWwPo62lZp9YlNUxwgHYUBJ8G6dRtrpRl9obHt/ebl08 wW5Qsvaqlx6A/kB7H7PDTroh4Xg5VJsAbNXz6N7CP+wNkbTk9D537XZV8IsGKBdAnN2Y v70TQJGhjHOY2Z7CvfXuk5AhaR5VTmWGLW4gQ= Received: by 10.68.49.34 with SMTP id r2mr2922856pbn.451.1306886196908; Tue, 31 May 2011 16:56:36 -0700 (PDT) Received: from [192.168.1.101] ([115.187.236.96]) by mx.google.com with ESMTPS id x1sm465086pbb.66.2011.05.31.16.56.33 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 May 2011 16:56:35 -0700 (PDT) Message-ID: <4DE58025.80307@gmail.com> Date: Wed, 01 Jun 2011 09:56:21 +1000 From: Patrick Barnes User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: error during map function References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Try typing 'js' from the server shell - it'll have been installed with couchdb, if it wasn't there already. It gives you an interactive js interpreter. Then, you can paste in your function; var map = function (doc) { .... } and it may tell you where the syntax error lies. Alternatively if you are using couchapp, you can test for syntax errors with 'js views/(view_name)/map.js' These methods may be more helpful than the errors that couchdb generates. Regards, -Patrick On 31/05/2011 6:29 AM, Mauro Fagnoni wrote: > Hi, i've rewrite the query but i've also an error.... > > now whats the problem? > > regards > > { > "map":" > function(doc){ > if ( > ( > (doc.partkey == doc.parteky)&& > (doc.brand == 'Brand#12')&& > ((doc.container == 'SM CASE') || (doc.container == 'SM > BOX') || (doc.container == 'SM PACK') || (doc.container == 'SM PKG'))&& > (doc.quantity>= 1)&& > (doc.quantity<= 11)&& > ((doc.size> 1)&&(doc.size< 5))&& > ((doc.shipmode == 'AIR') || (doc.shipmode == 'AIR > REG'))&& > (doc.shipinstruct == 'DELIVER IN PERSON') > ) > || > ( > (doc.partkey == doc.parteky)&& > (doc.brand == 'Brand#23')&& > (doc.container == 'MED BAG') || (doc.container == 'MED > BOX') || (doc.container == 'MED PKG') || (doc.container == 'MED PACK'))&& > (doc.quantity>= 10)&& > (doc.quantity<= 20)&& > ((doc.size> 1)&& (doc.size< 10))&& > ((doc.shipmode == 'AIR') || (doc.shipmode == 'AIR > REG'))&& > (doc.shipinstruct == 'DELIVER IN PERSON') > ) > || > ( > (doc.partkey == doc.parteky)&& > (doc.brand == 'Brand#34')&& > ((doc.container == 'LG CASE') || (doc.container == 'LG > BOX') || (doc.container == 'LG PACK') || (doc.container == 'LG PKG'))&& > (doc.quantity>= 20)&& > (doc.quantity<= 30)&& > ((doc.size> 1)&&(doc.size< 15))&& > ((doc.shipmode == 'AIR') || (doc.shipmode == 'AIR > REG'))&& > (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; > }" > } > > > 2011/5/29 Mark Hahn > >> I just noticed you seem to have the idea that if looks like if{}. >> This is not correct. It looks like if(){} in javascript. >> >> On Sun, May 29, 2011 at 11:59 AM, Mark Hahn wrote: >>> 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 >> wrote: >>>> ok i see the problem but i have no a solution....could you give a hand? >>>> >>>> 2011/5/27 Mark Hahn >>>> >>>>> 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 >>> >> >> >> >> -- >> Mark Hahn >> Website Manager >> mark@boutiquing.com >> 949-229-1012 >> > > >