Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Newbie question

6 replies [Last post]
  • Login or register to post comments
Mon, 10/15/2012 - 16:19
ashdamle
Offline
Joined: 10/15/2012
Groups: None

Newbie question: (Sorry if this isn't the right place for this post)

Working on a reduce and I just don't a response or error. The goal is to simply roll up the results into an array ... Some of the code is quite un-optimized but trying to diagnose why no result and no error message is given. Any help is very very much appreciated. This is with couchbase 2.0 beta rpm linux 2GB or RAM allocated with 100K entries

Below is the code: 

function(key,values,rereduce) {
	if (!rereduce) {
		var res=[];
		for (var i=0;i<values.length;i++) {
&			
			res[res.length]=values[i];
		}
		return res;
	} else {
		var res=[];
		
		for (var i=0;i<values.length;i++) {
			
			var subarr=values[i];
			if (subarr!=undefined && subarr!=null && subarr.length>0) {
				res=res.concat(subarr);
			}
		}
		return res;
	}
}
 
<br type="_moz">

Thanks! Ash

Top
  • Login or register to post comments
Wed, 10/17/2012 - 06:57
deepkaran.salooja
Offline
Joined: 05/21/2012
Groups: None

Hi Ash,

The reduce function you mentioned works fine for me.
Does your view return results without this reduce function? You can try to query the view.
The map reduce errors get logged in mapreduce_errors. under /opt/couchbase/var/lib/couchbase/logs.
Can you email that file to qe@couchbase.com or upload it here after quering with the reduce function.

Please send across your map function and a sample document as well for me to look more.

Thanks,
Deep

Top
  • Login or register to post comments
Thu, 10/18/2012 - 15:07
ashdamle
Offline
Joined: 10/15/2012
Groups: None

Was now able to get the reduce function to work on my side. However
when I do a test against the "full_set" I get the following:

via my java client: SERVER: error Reason: function_clause
 
from the error log
 
couchdb:error,2012-10-18T14:42:38.641,ns_1@127.0.0.1:<0.3461.1>:couch_log:error:42]Set
view `default`, main group `_design/dev_dso`, received error from
updater: function_clause
[couchdb:debug,2012-10-18T14:42:38.641,ns_1@127.0.0.1:<0.27999.0>:couch_log:debug:36]Minor
error in HTTP request: {error,function_clause}
[couchdb:debug,2012-10-18T14:42:38.641,ns_1@127.0.0.1:<0.27999.0>:couch_log:debug:36]Stacktrace:
[{couch_set_view,get_group,3},
             {couch_set_view,get_map_view,4},
             {couch_view_merger,get_set_view,5},
             {couch_view_merger,simple_set_view_query,3},
             {capi_view,design_doc_view_loop,6},
             {couch_httpd,handle_request,6},
             {menelaus_web,loop,3},
             {mochiweb_http,headers,5}]
[couchdb:info,2012-10-18T14:42:38.642,ns_1@127.0.0.1:<0.27999.0>:couch_log:info:39]128.100.5.78
- - GET /default/_design/dev_dso/_view/doctorlocation_state?full_set=true&key=%22IL%22&reduce=true&stale=false&connection_timeout=600000&limit=10&skip=0&_=1350596518118
500
[couchdb:debug,2012-10-18T14:42:38.642,ns_1@127.0.0.1:<0.27999.0>:couch_log:debug:36]httpd
500 error response:
 {"error":"error","reason":"function_clause"}
 
[couchdb:debug,2012-10-18T14:42:38.642,ns_1@127.0.0.1:couch_task_status:couch_log:debug:36]New
task status for <0.7398.0>: [{limit,4},
                                 {running,0},
                                 {started_on,1350589936},
                                 {type,couch_main_index_barrier},
                                 {updated_on,1350596558},
                                 {waiting,0}]

Please see the below for the map,reduce, and sample doc.

Map:
function (doc, meta) {
  emit(doc.state, doc.name);
}
 
 
 
 
Reduce:
function(key,values,rereduce) {
        if (!rereduce) {
                var result = {arr: null, er: '',rc: 0};
                result.arr=values;
                return result;
        } else {
                var result = {arr: null, er: '',rc: 0};
                var res=[];
                var ee='';
 
                if (values.length>0) {
 
                        for (var i=0;i<values.length;i++) {
                                //ee=ee+' ** '+values[i].er+' ** ' ;
 
 
                                if (values[i].arr instanceof Array) {
                                        //ee=ee+' ARR '+(typeof values[i].arr) ;
                                        if (values[i].arr.length>0) {
                                                res=res.concat(values[i].arr)
                                                //ee=ee+' '+(typeof values[i].arr[0]) ;
 
                                        }
                                }
 
                        }
                        result.rc=result.rc+values.length;
                }
                result.er=ee;
                result.arr=res;
                return result;
        }
}
 
 
Sample Doc:
{
   "**DOCUMENTTYPE**": "document",
   "**OBJECTTYPE**": "com.i2028.Document.Document",
   "**CREATETEXTSEARCH**": "**ALL**",
   "**DATATYPE**": "doctorlocation",
   "adddate": "2008-4-15",
   "address": "8314 SOUTHWEST FRWY",
   "city": "HOUSTON",
   "collection": "DOCTORLOCATION",
   "degree": [
       "NP"
   ],
   "fullname": "NDI CHUKWUMERIJE",
   "lastname": "CHUKWUMERIJE",
   "moddate": "1208280927816",
   "name": "135034870853480",
   "rev": "0",
   "speciality": [
       "Nurse Practitioner"
   ],
   "state": "TX",
   "zip": "77074"
}

Top
  • Login or register to post comments
Sat, 10/20/2012 - 08:29
deepkaran.salooja
Offline
Joined: 05/21/2012
Groups: None

As you are using "key" in your query on a reduced result set, you need to have group=true included in your query.
The group option controls whether the reduce function reduces to a set of distinct keys or to a single result row.

Right now your reduce function is reducing to a single row. But as you need to query on "key", group=true needs to be used.

For all the query options, please see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-query....

Please let me know if it works for you.

Top
  • Login or register to post comments
Sat, 10/20/2012 - 13:56
ashdamle
Offline
Joined: 10/15/2012
Groups: None

Tried that but it still fails on the full set

Please see:

(This works via the dev view)

http://128.100.10.170:8092/default/_design/dev_dso/_view/doctorlocation_state?group=true&debug=true&key=%22IL%22&reduce=true&stale=false&connection_timeout=60000&limit=10&skip=0
 
 
{"rows":[
{"key":"IL","value":{"arr":["135034870402860","135034870399310","135034870399280","135034870329600","135034870279350","135034870229900","135034870223040","135034870215540","135034870165990","135034870139820","135034870039720","135034869999120","135034869975410","135034869949850","135034869943080","135034869915870","135034869893760","135034869873820","135034869823270","135034869813440","135034869760950","135034869730300","135034869496400","135034869490730","135034869410410","135034869381620","135034869337000","135034869331330","135034869301490","135034869267550","135034869257360","135034869191800","135034869117980","135034869117810","135034868972220","135034868942410","135034868928130","135034868918690","135034868894150","135034868892260","135034868878460","135034868824440","135034868812140","135034868781310","135034868781280","135034868701030","135034868657650","135034868651560"],"er":"","rc":0}}
]
}

vs in prod or with full_set=true

http://128.100.10.170:8092/default/_design/dso/_view/doctorlocation_state?group=true&debug=true&key=%22IL%22&reduce=true&stale=false&connection_timeout=60000&limit=10&skip=0
 
results in
 
{"error":"error","reason":"function_clause"}

Thoughts?

Top
  • Login or register to post comments
Tue, 10/23/2012 - 10:01
deepkaran.salooja
Offline
Joined: 05/21/2012
Groups: None

Can you please run the command /opt/couchbase/bin/cbcollect_info on your node and send the output to me at qe@couchbase.com.
I need to have a look at the complete logs.

Top
  • Login or register to post comments
Mon, 10/29/2012 - 09:49
deepkaran.salooja
Offline
Joined: 05/21/2012
Groups: None

Hi,

Looking at the logs, I see you are hitting the "reduction_too_long" error in your reduce function due to large size of array reduce function is creating.

For the reduce, the general guideline is:
"If you are building a composite return structure in your reduce, or only transforming the values field, rather than summarizing it, you might be misusing this feature."

Reduce functions are supposed to shrink map values (or other reductions, when doing re-reduce).

So I think it would be better to move the logic to build the array in your client application code. Reduce function is not the correct place to do it in this case.

Deep

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker