用户定义的功能和DolphinDB中的流聚合器

时间:2019-03-18 01:28:13

标签: dolphindb

我想在DolphinDB的流聚合器中使用用户定义的函数。

但是它返回一个异常,我不知道如何处理它:

def mymid(vec){
    return (first(vec) + last(vec))/2
}
share streamTable(10000:0, `time`device`metric, [TIMESTAMP, SYMBOL, DOUBLE] as sensor
output = table(10000:0, `time`mymid, [TIMESTAMP, DOUBLE]);
aggregator = createStreamAggregator("aggregator", 120, 60, <mymid(metric)>, sensor, output, `time)


execution was completed with exception
Usage: createStreamAggregator(name, windowSize, step, metrics, dummyTable, outputTable, timeColumn, [useSystemTime=false], [keyColumn], [garbageSize]). 
the outermost meta code must be aggregated functions.

很显然,mymid是一个聚合函数。我的问题是如何在DolphinDB中创建聚合的用户定义函数?

1 个答案:

答案 0 :(得分:1)

使用关键字defg代替关键字def表示聚合函数

defg mymid(vec){
    return (first(vec) + last(vec))/2
}