Search in sources :

Example 16 with ConstantExpressionExecutor

use of org.wso2.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.

the class SortWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
        lengthToKeep = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue()));
    } else {
        throw new UnsupportedOperationException("The first parameter should be an integer");
    }
    parameterInfo = new ArrayList<Object[]>();
    eventComparator = new EventComparator();
    for (int i = 1, parametersLength = attributeExpressionExecutors.length; i < parametersLength; i++) {
        if (!(attributeExpressionExecutors[i] instanceof VariableExpressionExecutor)) {
            throw new UnsupportedOperationException("Required a variable, but found a string parameter");
        } else {
            ExpressionExecutor variableExpressionExecutor = attributeExpressionExecutors[i];
            int order;
            String nextParameter;
            if (i + 1 < parametersLength && attributeExpressionExecutors[i + 1].getReturnType() == Attribute.Type.STRING) {
                nextParameter = (String) ((ConstantExpressionExecutor) attributeExpressionExecutors[i + 1]).getValue();
                if (nextParameter.equalsIgnoreCase(DESC)) {
                    order = -1;
                    i++;
                } else if (nextParameter.equalsIgnoreCase(ASC)) {
                    order = 1;
                    i++;
                } else {
                    throw new UnsupportedOperationException("Parameter string literals should only be \"asc\" or " + "\"desc\"");
                }
            } else {
                // assigning the default order: "asc"
                order = 1;
            }
            parameterInfo.add(new Object[] { variableExpressionExecutor, order });
        }
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Aggregations

ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)16 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)10 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)9 Attribute (org.wso2.siddhi.query.api.definition.Attribute)7 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)7 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)6 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)5 ArrayList (java.util.ArrayList)4 AndConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor)4 Test (org.testng.annotations.Test)3 HashMap (java.util.HashMap)2 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)2 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)2 GreaterThanCompareConditionExpressionExecutorIntInt (org.wso2.siddhi.core.executor.condition.compare.greaterthan.GreaterThanCompareConditionExpressionExecutorIntInt)2 AddExpressionExecutorFloat (org.wso2.siddhi.core.executor.math.add.AddExpressionExecutorFloat)2 List (java.util.List)1 Map (java.util.Map)1 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)1 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)1 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)1