You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/08/22 19:57:56 UTC
[GitHub] davisp commented on issue #1574: Fix builtin _sum reduce function
davisp commented on issue #1574: Fix builtin _sum reduce function
URL: https://github.com/apache/couchdb/pull/1574#issuecomment-415159645
Trivially reproduced with this Python script:
I wanted to get the PR out but I'm also going to try and contemplate how to test this a bit more directly.
```python
#!/usr/bin/env python
import base64
import json
import os
import random
import requests
S = requests.session()
S.auth = ("adm", "pwd")
S.headers["Content-Type"] = "application/json"
BASE = "http://127.0.0.1:15986/"
DB = BASE + "foo"
DDOC = DB + "/_design/bar"
VIEW = DDOC + "/_view/bam"
SIG = "1d2f27b7abd18837599f078927c7bc1f"
def gen_key():
data = os.urandom(50)
return base64.b64encode(data)
def gen_device():
return {
"tx_bytes": random.randint(1, 8192),
"rx_bytes": random.randint(1, 8192)
}
def gen_data():
ret = {}
for i in range(1024):
ret[gen_key()] = gen_device()
return ret
def load_docs():
for i in range(25):
print "Generating: %d - %d" % (i*100, (i+1)*100)
docs = []
for j in range(100):
docs.append({
"_id": "%06d" % ((i*100) + j),
"data": gen_data()
})
body = json.dumps({"docs": docs})
r = S.post(DB + "/_bulk_docs", data=body)
r.raise_for_status()
def load_ddoc():
ddoc = {
"language": "javascript",
"views": {
"bam": {
"map": """
function(doc) {
emit(doc._id, doc.data);
}""",
#"reduce": "_sum"
"reduce": """
function(keys, values) {
var obj = {};
for(var v in values) {
for(var k in values[v]) {
log(k);
obj[k] = values[v][k];
}
}
return obj;
}
"""
}
}
}
body = json.dumps(ddoc)
r = S.put(DB + "/_design/bar", data=body)
r.raise_for_status()
def get_size():
fname = "dev/lib/node1/data/.foo_design/mrview/%s.view" % SIG
return os.stat(fname).st_size
def get_task():
r = S.get(BASE + "/_active_tasks")
for t in r.json():
return t
def main():
S.delete(DB)
r = S.put(DB)
r.raise_for_status()
load_docs()
load_ddoc()
r = S.get(VIEW, params={"limit": 0})
r.raise_for_status()
print "Initial build: %d" % get_size()
r = S.post(DDOC + "/_compact")
r.raise_for_status()
print get_task()
if __name__ == "__main__":
main()
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services