I'm building a custom aggregation function in siddhi an I have doubts about the oficial documentation, placed at https://docs.wso2.com/display/CEP420/Writing+a+Custom+Aggregate+Function
In the example it creates "an aggregate function extension with custom as the namespace and std as the function name", so my first question is, why then, when it invokes the function from siddhi, it uses:
from pizzaOrder#window.length(20)
select custom:count(orderNo) as totalOrders
insert into orderCount;
should not be like this instead?
from pizzaOrder#window.length(20)
select custom:std(orderNo) as totalOrders
insert into orderCount;
the second question I have is related to the custom.siddhiext extension mapping file, as far as I understand it, in this file we have to reference our new class with the newly created function, so, I would write something like this
std=org.wso2.siddhi.extension.customAggregateFunction.CountAggregateFunction
but again, it uses
std=org.wso2.siddhi.core.query.selector.attribute.aggregator.StrandedDeviationAggregateFunction
Where does the StrandedDeviationAggregateFunction came from? And using that extension mapping file, ¿how siddhi knows where to find the new count function?
UPDATED
I finally used the documentation placed at https://docs.wso2.com/display/SIDDHIEXTENSIONS/Creating+a+Siddhi+Extension+and+Publishing+in+WSO2+Store to generate the aggregation function through maven. But I can't still use the new aggregation function.
Aggregation class:
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 file:
#
# 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
when I try to use this method in an execution plan it says "string_utilsAggregator is neither a function extension nor an aggregated attribute extension in execution plan". The stauts of the module(checked through -DosgiConsole) is ACTIVE. Any idea what is missing?