Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mapreduce CouchDB:使用Reduce时如何在映射函数中使用数组键?_Mapreduce_Couchdb - Fatal编程技术网

Mapreduce CouchDB:使用Reduce时如何在映射函数中使用数组键?

Mapreduce CouchDB:使用Reduce时如何在映射函数中使用数组键?,mapreduce,couchdb,Mapreduce,Couchdb,我想在CouchDB中编写一个MapReduce函数,其中Map函数以数组的形式发出键,但是reduce函数只使用Map键中的一个值。例如: 地图功能: function(doc) { if (doc.type_ === 'survey') { emit([doc.timeRecorded_, doc.imei_], 1); }; }; function(k,v) { // How to handle only the doc.imei_ as the v

我想在CouchDB中编写一个MapReduce函数,其中Map函数以数组的形式发出键,但是reduce函数只使用Map键中的一个值。例如:

地图功能:

function(doc) {
    if (doc.type_ === 'survey') {
        emit([doc.timeRecorded_, doc.imei_], 1);
    };
};
function(k,v) {

  // How to handle only the doc.imei_ as the value?
  // Or, alternatively, how to filter based on timeRecorded_ somewhere other than the map function?
  return sum(v)
}
Reduce函数:

function(doc) {
    if (doc.type_ === 'survey') {
        emit([doc.timeRecorded_, doc.imei_], 1);
    };
};
function(k,v) {

  // How to handle only the doc.imei_ as the value?
  // Or, alternatively, how to filter based on timeRecorded_ somewhere other than the map function?
  return sum(v)
}

时间记录在一个历元数字中,因此不会有重复(除非偶然)。如果要对其进行合计,则需要将其四舍五入为“日”值。或者,数据的准备方式可以使记录的时间在源数据中已经四舍五入(可能更改为dateRecorded)

此问题的一个众所周知的模式是将日期拆分为一个数组(例如,
[年、月、日、小时、分钟]
;间隔可以不同,但顺序要保持不变)并将数组用作map函数中的键

因此,您可以根据所需的
组级别减少行数
(例如,“按年”、“按月”、“按天”、“按小时”、“按分钟”等)

资料来源: