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

.net not showing all values

3 replies [Last post]
  • Login or register to post comments
Sun, 03/10/2013 - 08:00
jarushepic
Offline
Joined: 03/10/2013
Groups: None

I'm sure that I'm just doing something wrong since I haven't been playing with this for very long and its all new to me. I've got documents that look like this:

{
   "key": 2185335,
   "metric": "CLR_AUTO_EVENT_wait_time_ms",
   "sample_dt": "2013-03-07T22:29:18",
   "value": 0
}

My map function just spits out the key, the metric name, and the value:

function (doc, meta) {
  emit([doc.key, doc.metric], doc.value)
}

My reduce function returns the total, count, average, and eightieth percentile.

function(key, values, rereduce)
{
  values.sort();
  var result = {total: 0, count: 0, eightieth: 0, average: 0};
  for(i=0; i < values.length; i++)
  {
    if (rereduce)
    {
      result.total = result.total + values[i].total;
      result.count = result.count + values[i].count;
      result.average = result.total / result.count;
    }
    else
    {
      result.total = sum(values);
      result.count = values.length;
      result.average = result.total / result.count;
    }
  }
  result.eightieth = values[Math.round(values.length * 0.8)];
  return(result);
}

If I view the results via the webGUI, all the values show up. If I do it via .NET, the eightyth key is missing. All I'm doing is iterating over the rows from this:

CouchbaseClient db = new CouchbaseClient();
var rows = db.GetView("test", "all_metrics").GroupAt(2);

Top
  • Login or register to post comments
Mon, 03/11/2013 - 09:09
john
Offline
Joined: 01/05/2012
Groups: None

I ran the sample view after creating some test records based on the JSON you provided. I found that Math.round(values.length * 0.8) was resulting in an index out of bounds error in the JavaScript. Math.floor seems to work though - both in the console and in .NET.

Top
  • Login or register to post comments
Mon, 03/11/2013 - 11:45
jarushepic
Offline
Joined: 03/10/2013
Groups: None

Thats great! How did you find that out?

Top
  • Login or register to post comments
Mon, 03/11/2013 - 12:02
john
Offline
Joined: 01/05/2012
Groups: None

Trial and error... I've debugged my fair share of views now. I take an approach similar to debugging web page JavaScript (i.e., conosole.log). It took me 4 steps to debug the result.eightieth issue.

1. Verify that the out-of-loop assignments were working, which they were

result.foo = "";
result.eightieth = values[Math.floor(values.length * 0.8)];

2. Eliminate the right hand side of the assignment as a source of a bug

result.eightieth = "foo"; //foo was in the value

3. Test the indexing of the values array as a source of the bug

result.eightieth = Math.round(values.length * 0.8); //no error, but I saw with 2 docs in my bucket, the indexes were 1 and 2

4. Test the indexing of the values with a lower bound index

result.eightieth = values[Math.floor(values.length * 0.8)]; //no error

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