我正在siddhi中构建一个自定义聚合函数,我怀疑有关官方文档,放在https://docs.wso2.com/display/CEP420/Writing+a+Custom+Aggregate+Function
在示例中,它创建了一个聚合函数扩展,其中自定义作为命名空间, std 作为函数名称“,所以我的第一个问题是,为什么然后,何时它从siddhi调用函数,它使用:
from pizzaOrder#window.length(20)
select custom:count(orderNo) as totalOrders
insert into orderCount;
不应该是这样的吗?
from pizzaOrder#window.length(20)
select custom:std(orderNo) as totalOrders
insert into orderCount;
我的第二个问题与custom.siddhiext扩展映射文件有关,据我所知,在这个文件中我们必须用新创建的函数引用我们的新类,所以,我会写这样的东西
std=org.wso2.siddhi.extension.customAggregateFunction.CountAggregateFunction
但同样,它使用
std=org.wso2.siddhi.core.query.selector.attribute.aggregator.StrandedDeviationAggregateFunction
StrandedDeviationAggregateFunction来自哪里?并使用该扩展映射文件,¿siddhi如何知道在哪里找到新的计数函数?
已更新
我最后使用放置在https://docs.wso2.com/display/SIDDHIEXTENSIONS/Creating+a+Siddhi+Extension+and+Publishing+in+WSO2+Store的文档通过maven生成聚合函数。但我仍然不能使用新的聚合函数。
聚合类:
package org.wso2.extension.siddhi.aggregation.string_utils;
import org.wso2.siddhi.core.config.ExecutionPlanContext;
import org.wso2.siddhi.core.executor.ExpressionExecutor;
import org.wso2.siddhi.core.query.selector.attribute.aggregator.AttributeAggregator;
import org.wso2.siddhi.query.api.definition.Attribute;
/**
* This Sample implemented for count you can implement based on this sample.
*/
public class string_utilsAggregateFunction extends AttributeAggregator {
private static Attribute.Type type = Attribute.Type.STRING;
private String value = "";
/**
* The initialization method for string_utilsAggregatorFunction.
*
* @param attributeExpressionExecutors are the executors of each attributes in the function.
* @param executionPlanContext Execution plan runtime context.
*/
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) {
}
public Attribute.Type getReturnType() {
return type;
}
/**
* The process add method of the string_utilsAggregateFunction, used when zero or one function parameter is provided.
*
* @param data null if the function parameter string_utils is zero or runtime data value of the function parameter.
* @return the string_utils value.
*/
@Override
public Object processAdd(Object data) {
//Sample code.
value = value + "," + data.toString();
return value;
}
/**
* The process add method of the string_utilsAggregateFunction, used when more than one function parameters are provided.
*
* @param data the data values for the function parameters.
* @return the string_utils value.
*/
@Override
public Object processAdd(Object[] data) {
//Sample code.
value = value + "," + data.toString();
return value;
}
/**
* The process remove method of the string_utilsAggregateFunction, used when zero or one function parameter is provided.
*
* @param data null if the function parameter string_utils is zero or runtime data value of the function parameter.
* @return the string_utils value.
*/
@Override
public Object processRemove(Object data) {
return value;
//Sample code.
}
/**
* The process remove method of the string_utilsAggregateFunction, used when more than one function parameters are provided.
*
* @param data the data values for the function parameters.
* @return the string_utils value.
*/
@Override
public Object processRemove(Object[] data) {
//Sample code.
return value;
}
/**
* Reset string_utils value.
*
* @return reset value.
*/
@Override
public Object reset() {
//Sample code.
value = "";
return value;
}
/**
* This will be called only once and this can be used to acquire
* required resources for the processing element.
* This will be called after initializing the system and before
* starting to process the events.
*/
@Override
public void start() {
//Nothing to start.
}
/**
* This will be called only once and this can be used to release
* the acquired resources for processing.
* This will be called before shutting down the system.
*/
@Override
public void stop() {
//nothing to stop.
}
/**
* Used to collect the serializable state of the processing element, that need to be
* persisted for the reconstructing the element to the same state on a different point of time.
*
* @return stateful objects of the processing element as an array.
*/
@Override
public Object[] currentState() {
return new Object[]{value};
}
/**
* Used to restore serialized state of the processing element, for reconstructing
* the element to the same state as if was on a previous point of time.
*
* @param state the stateful objects of the element as an array on
* the same order provided by currentState().
*/
@Override
public void restoreState(Object[] state) {
//Sample code.
value = (String) state[0];
}
}
siddhiext文件:
#
# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
string_utilsAggregator=org.wso2.extension.siddhi.aggregation.string_utils.string_utilsAggregateFunction
当我尝试在执行计划中使用此方法时,它表示“string_utilsAggregator既不是函数扩展也不是执行计划中的聚合属性扩展”。模块的stauts(通过-DosgiConsole检查)是ACTIVE。知道缺少什么吗?