我在mixpanel中有一个JQL。我设法得到以下格式的结果:
key, count1, count2, count3
a , 10, 0, 0
a , 0, 3, 0
a , 0, 0, 7
b , 2, 0, 0
b , 0, 3, 0
b , 0, 0, 5
我希望得到如下结果:
key, count1, count2, count3
a , 10, 3, 7
b , 2, 3, 5
换句话说:groupBy(['key'],WHAT_REDUCER_DO_I_NEED ???)
答案 0 :(得分:1)
您可以在groupBy语句中使用多个reducer,如下所示
.groupBy(['key'], [
mixpanel.reducer.sum('count1'),
mixpanel.reducer.sum('count2'),
mixpanel.reducer.sum('count3')
])
答案 1 :(得分:0)
.groupBy(["key"], function(accumulators, events){
var sum = {"count1":0,"count2":0,"count3":0};
for (var i = 0; i < accumulators.length; ++i) {
sum["count1"] += accumulators[i]["count1"];
sum["count2"] += accumulators[i]["count2"];
sum["count3"] += accumulators[i]["count3"];
}
for (i = 0; i < events.length; ++i) {
var event = events[i];
sum["count1"] += event["count1"];
sum["count2"] += event["count2"];
sum["count3"] += event["count3"];
}
return sum;
})