- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我的应用程序将多种文档类型存储在同一个存储桶中。我知道这不是好的做法,但我对可以在服务器上创建的存储桶数量有限制,目前没有办法解决。这些文档以它们的类型为前缀,所以当我得到一个文档时,我只需要连接前缀和 id 来获取 key ,然后我就可以进行 key 查找。
我需要创建一个报告,其中包含来自多种文档类型的信息。
我的 map 是这样的:
function(doc, meta) {
var getStep = function(stepName, exit, mapper) {
if (meta.id.indexOf(stepName) !== -1) {
var hotelId = parseInt(meta.id.replace(stepName + '_', ''));
if (hotelId > 0) {
var result = {
hotelId: hotelId,
exit: exit
};
if (mapper !== undefined) {
mapper(result);
}
return result;
}
}
return null;
};
var photos = getStep('PHOTOS', 7);
if (photos != null) {
emit(photos.hotelId, photos);
}
var pricing = getStep('PICR', 5);
if (pricing != null) {
emit(pricing.hotelId, pricing);
}
var owner = getStep('OWNER', 1);
if (owner != null) {
emit(owner.hotelId, owner);
}
var amenity = getStep('AM', 4);
if (amenity != null) {
emit(amenity.hotelId, amenity);
}
var description = getStep('HDESC', 3, function(result) {
result.description = doc.description;
result.hotelRoomTypeId = doc.hotelRoomTypeId;
result.starRating = doc.starRating;
});
if (description != null) {
emit(description.hotelId, description);
}
var contact = getStep('DC', 3, function(result) {
result.email = doc.emailAddress;
result.contact = doc.mainContactName;
});
if (contact != null) {
emit(contact.hotelId, contact);
}
var location = getStep('LOC', 2, function(result) {
result.city = doc.cityName;
result.zip = doc.postalCode;
result.country = doc.countryName;
result.street = doc.stateName + ', ' + doc.streetName;
});
if (location != null) {
emit(location.hotelId, location);
}
var property = getStep('PRP', 1, function(result) {
result.paymentMethodId = doc.paymentMethodId
});
if (property != null) {
emit(property.hotelId, property);
}
}
它生成这个输出:
"total_rows":...,"rows":[
{"id":"DC_1","key":1,"value":{"hotelId":1,"exit":3,"email":"test@example.com","contact":"Jeno"}},
{"id":"HDESC_1","key":1,"value":{"hotelId":1,"exit":3,"description":".","hotelRoomTypeId":0,"starRating":5}},
{"id":"LOC_1","key":1,"value":{"hotelId":1,"exit":2,"city":"Barcelona","zip":"1222","country":"Spain","street":"Catalonia, someplacenice"}},
{"id":"PRP_1","key":1,"value":{"hotelId":1,"exit":1}},
{"id":"PRP_2","key":2,"value":{"hotelId":2,"exit":1}},
{"id":"AM_3","key":3,"value":{"hotelId":3,"exit":4}},
{"id":"AM_4","key":4,"value":{"hotelId":4,"exit":4}},
{"id":"PHOTOS_4","key":4,"value":{"hotelId":4,"exit":7}},
{"id":"PRP_4","key":4,"value":{"hotelId":4"exit":1}},
{"id":"AM_4","key":4,"value":{"hotelId":4,"exit":4}},
{"id":"PRP_4","key":4,"value":{"hotelId":4,"exit":1}},
{"id":"PHOTOS_5","key":5,"value":{"hotelId":5,"exit":7}}
...
]
我正在尝试按新键 hotelId 对日期进行分组,并使用自定义缩减器将字段合并到一个文档中。根据错误类型,我收到不同的错误,但所有错误似乎都表明 reducer 可以返回多少日期是有限制的。如果我将返回类型从一个对象更改为一个关联数组,它的工作方式几乎相同,我会得到一个更好的错误。
function(key, values, rereduce) {
if (rereduce) {
return values;
} else {
var results = {}; // Object!
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (!results[row.hotelId]) {
results[row.hotelId] = {
phone: '',
exit: 1
};
}
var result = results[row.hotelId];
for (var name in row) {
result[name] = row[name];
}
if (row.exit > row.exit) {
result.exit = row.exit;
}
};
return results;
}
}
给我 RangeError: Maximum call stack size exceeded
function(key, values, rereduce) {
if (rereduce) {
return values;
} else {
var results = []; // Array!
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (!results[row.hotelId]) {
results[row.hotelId] = {
phone: '',
exit: 1
};
}
var result = results[row.hotelId];
for (var name in row) {
result[name] = row[name];
}
if (row.exit > row.exit) {
result.exit = row.exit;
}
};
return results;
}
}
给我 reduction too large error
function(key, values, rereduce) {
if (rereduce) {
return values;
} else {
return values;
}
}
给我 RangeError: Maximum call stack size exceeded
如果我运行:
function(key, values, rereduce) {
if (rereduce) {
return values;
} else {
return values.length;
}
}
我回来了:
[ 68, 72, 65, 66, 68, 68, 70, 114 ]
JavaScript 引擎应该能够减少最大 114 大小的数组,输出数据应该更小。显然,reduce 可以返回多少数据 max_kv_size_per_doc
是有限制的,即 1Mb 也有 10 秒的执行限制,但在我的例子中是另外一回事。有没有办法通过改变算法、返回数组或数组之类的东西来绕过这些限制?我可以在 map 上做些什么,或者我可以在 rereduce 中使用一些技巧吗?
最佳答案
我想通了。如果我使用复合键和 group_level,它会起作用。
因此,如果我更改我的 map 以返回一个数组作为酒店 ID 的键,并且我设置 group_level = 1,那么这些值将按照我最初的预期为我分组:
function(doc, meta) {
var getStep = function(stepName, exit, mapper) {
if (meta.id.indexOf(stepName) !== -1) {
var hotelId = parseInt(meta.id.replace(stepName + '_', ''));
if (hotelId > 0) {
var result = {
hotelId: hotelId,
exit: exit
};
if (mapper !== undefined) {
mapper(result);
}
return result;
}
}
return null;
};
var photos = getStep('PHOTOS', 7);
if (photos != null) {
emit([photos.hotelId], photos); // array as key
}
var pricing = getStep('PICR', 5); // array as key
if (pricing != null) {
emit([pricing.hotelId], pricing);
}
var owner = getStep('OWNER', 1); // array as key
if (owner != null) {
emit([owner.hotelId], owner);
}
var amenity = getStep('AM', 4); // array as key
if (amenity != null) {
emit([amenity.hotelId], amenity);
}
var description = getStep('HDESC', 3, function(result) {
result.description = doc.description;
result.hotelRoomTypeId = doc.hotelRoomTypeId;
result.starRating = doc.starRating;
});
if (description != null) {
emit([description.hotelId], description); // array as key
}
var contact = getStep('DC', 3, function(result) {
result.email = doc.emailAddress;
result.contact = doc.mainContactName;
});
if (contact != null) {
emit([contact.hotelId], contact); // array as key
}
var location = getStep('LOC', 2, function(result) {
result.city = doc.cityName;
result.zip = doc.postalCode;
result.country = doc.countryName;
result.street = doc.stateName + ', ' + doc.streetName;
});
if (location != null) {
emit([location.hotelId], location); // array as key
}
var property = getStep('PRP', 1, function(result) {
result.paymentMethodId = doc.paymentMethodId
});
if (property != null) {
emit([property.hotelId], property); // array as key
}
}
然后我需要设置 group_level=1
和 reduce=true
。您可以在 View 编辑器或查询字符串中执行此操作。
最后一点是reduce:
function(key, values, rereduce) {
if (rereduce) {
return values;
} else {
var result = {};
values.forEach(function(item){
for(var name in item){
result[name] = item[name];
}
});
return result;
}
}
结果将按预期由 hotelId 合并 :)
关于javascript - 如何将 Couchbase 中的数据与 map reduce 合并?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44962422/
我不知道如何从 reducerRegister.js 中的 reducerForm.js reducer 访问 bool 值 isLoading 标志。我使用了 combineReducers() 并
我正在尝试找到一种理想的方法来更新我的状态树上的几个顶级字段,同时仍然维护拆分 reducer 。 这是我想出的一个简单的解决方案。 var state = { fileOrder: [0],
如果我们想按相同的键(第一个 reducer 的输出)分组,是否可以将 reducer 的输出直接发送到另一个 reducer 有时在链接时我发现我正在使用一个映射器来读取输入并将其复制到输出。因此想
我有一个如下所示的 reducer : const chart = combineReducers({ data, fetchProgress, fetchError,
当Map Reduce代码中有多个reduce时,它们之间没有任何形式的通信。但是,当执行诸如聚合之类的操作时,所有化简器共同产生单个最终输出。当它们之间没有通信时,聚合如何发生?是通过写入上下文吗?
我在 hive 中有一个表,我想从中获取所有数据。问题是: select * from tbl; 给我的结果与以下情况截然不同: select count(*) from tbl; 这是为什么?第二个
假设我有一个带有两个 reducer 的应用程序 - 使用 combineReducers() 组合的 tables 和 footer。 当我点击某个按钮时,将分派(dispatch)两个操作 - 一
我正在学习更深入的 redux,并且在处理高阶 reducer 时遇到一些麻烦。 我试图使用一个简单的分页示例来了解它是如何工作的。 NB:下面的代码只是 Nodejs 上下文中 redux 的一个快
我调用 RSS 提要并使用解析器对其进行解析。我收到一个数组。我现在想在最后创建一个对象,看起来像这样: { "2019-06-13": { "rates": { "usd":
我有一份学生列表,我的应用程序始终显示当时的一个学生,即 activePupil。到目前为止我有两个 reducer 。其中一个包含并默认返回所有子项的列表(以数组的形式): [ { id:
我有一个叫做 animals 的特征缩减器(切片缩减器)。我想将这些 reducer 拆分为哺乳动物、鸟类、鱼类等。这部分很简单,因为我可以简单地使用 ActionReducerMap。 现在假设哺乳
空数组上的简单reduce会抛出: 线程“main”java.lang.UnsupportedOperationException 中的异常:无法减少空的可迭代对象。 链接时同样的异常: val a
我有一些 25k 文档(原始 json 中为 4 GB)的数据,我想对其执行一些 javascript 操作,以使我的最终数据使用者 (R) 更容易访问这些数据,并且我想通过为每个更改添加一个新集合来
我只是想验证我对这些参数及其关系的理解,如果我错了请通知我。 mapreduce.reduce.shuffle.input.buffer.percent 告诉分配给 reducer 的整个洗牌阶段的内
我想将 redux 状态的值从 reducer 传递到另一个 reducer。在我的例子中,我想将 groups 的值从 groupReducer.js 中的状态传递到 scheduleReducer
所以,我有一个应用程序,它有多个 reducer ,因此有多个关联的 Action 创建者。 有一段时间,我的一个 reducer 更新了状态(由于编辑),因此,我必须确保其他 reducer 看到此
我有一个 reducer ,可以在调度操作时重新调整适当的状态。现在我定期调用 API,因此结果会一次又一次地触发操作。所以我想要的是,如果 reducer 状态已经有数据,那么另一个 reducer
当我尝试执行来自 here 的 DISTINCT reduce 时,出现错误。我已经在啤酒 sample 桶上重现了这个错误,所以这应该很容易重现。我没有在 mapreduce_errors.txt
在以下语法的简单优先级解析(分解)中,我们存在 shift-reduce 和 reduce-reduce 冲突。 X 是开始符号,X'-->$X$ 是添加规则。另外+和下符号是终结符。 X'-->$X
我需要编写一个连续调用两个reducer的Mapreduce程序。即,第一个 reducer 的输出将是第二个 reducer 的输入。我如何实现这一目标? 到目前为止我发现的内容表明我需要在我的驱动
我是一名优秀的程序员,十分优秀!