nickva commented on PR #5494:
URL: https://github.com/apache/couchdb/pull/5494#issuecomment-2755151026

   Start with a draft pr to gauge interest. Needs tests obviously.
   
   Here is a simple python script to try it out: 
https://gist.github.com/nickva/17c85d5e7081f31dca5a2bf3917ef2f3
   
   With a simple map function to keep track of sales for some random years and 
months:
   
   ```javascript
   function(doc){
       emit([doc.year, doc.month], doc.sales);
   }
   ```
   
   ```
   % http $DB/db/_design/d1/_view/top10'?group=true&group_level=1&limit=3'
   HTTP/1.1 200 OK
   
   {
       "rows": [
           {
               "key": [
                   2001
               ],
               "value": [
                   931.021664033225,
                   829.0717011821488,
                   775.5360993378665,
                   683.0977590565661,
                   276.51499916212737,
                   266.4315223593118,
                   222.90260934980307,
                   216.76802801301613,
                   215.68095305906292,
                   209.32930207334888
               ]
           },
           {
               "key": [
                   2002
               ],
               "value": [
                   328966.2202201642,
                   5447.123292157605,
                   539.0773556077951,
                   307.63403941541753,
                   294.4198798831839,
                   281.49331767967436,
                   248.46343368068253,
                   245.5418654674753,
                   240.29692621507647,
                   235.05686309321763
               ]
           },
           {
               "key": [
                   2003
               ],
               "value": [
                   2349.6558110810374,
                   1782.184922248414,
                   1747.2645751778125,
                   1233.396982485958,
                   1030.6886567619686,
                   775.6718095876206,
                   752.2617494897446,
                   402.6604976482621,
                   382.0057134025877,
                   248.0430488012996
               ]
           }
       ]
   }
   ```
   
   ```
   http 
$DB/db/_design/d1/_view/top1'?group=true&group_level=2&start_key=[2021]&limit=3'
   HTTP/1.1 200 OK
   
   {
       "rows": [
           {
               "key": [
                   2021,
                   1
               ],
               "value": [
                   145.47625983483155
               ]
           },
           {
               "key": [
                   2021,
                   2
               ],
               "value": [
                   250.70341326647355
               ]
           },
           {
               "key": [
                   2021,
                   3
               ],
               "value": [
                   4484.3909590737285
               ]
           }
       ]
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to