Search in sources :

Example 1 with ExpressionExecutor

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

the class CoalesceFunctionExecutor method init.

@Override
public void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    if (attributeExpressionExecutors.length == 0) {
        throw new SiddhiAppValidationException("Coalesce must have at least one parameter");
    }
    Attribute.Type type = attributeExpressionExecutors[0].getReturnType();
    for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) {
        if (type != expressionExecutor.getReturnType()) {
            throw new SiddhiAppValidationException("Coalesce cannot have parameters with different type");
        }
    }
    returnType = type;
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ReturnAttribute(org.wso2.siddhi.annotation.ReturnAttribute) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 2 with ExpressionExecutor

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

the class FunctionExecutor method cloneExecutor.

@Override
public ExpressionExecutor cloneExecutor(String key) {
    try {
        FunctionExecutor functionExecutor = this.getClass().newInstance();
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeSize];
        for (int i = 0; i < attributeSize; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors[i].cloneExecutor(key);
        }
        functionExecutor.elementId = elementId + "-" + key;
        functionExecutor.functionId = functionId;
        functionExecutor.initExecutor(innerExpressionExecutors, siddhiAppContext, queryName, configReader);
        return functionExecutor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException)

Example 3 with ExpressionExecutor

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

the class AbstractStreamProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        AbstractStreamProcessor abstractStreamProcessor = this.getClass().newInstance();
        abstractStreamProcessor.inputDefinition = inputDefinition;
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
        ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
        for (int i = 0; i < attributeExpressionLength; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
        }
        abstractStreamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
        abstractStreamProcessor.attributeExpressionLength = attributeExpressionLength;
        abstractStreamProcessor.additionalAttributes = additionalAttributes;
        abstractStreamProcessor.complexEventPopulater = complexEventPopulater;
        abstractStreamProcessor.siddhiAppContext = siddhiAppContext;
        abstractStreamProcessor.elementId = elementId + "-" + key;
        abstractStreamProcessor.configReader = configReader;
        abstractStreamProcessor.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
        abstractStreamProcessor.queryName = queryName;
        abstractStreamProcessor.siddhiAppContext.getSnapshotService().addSnapshotable(queryName, abstractStreamProcessor);
        abstractStreamProcessor.siddhiAppContext.addEternalReferencedHolder(abstractStreamProcessor);
        abstractStreamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        abstractStreamProcessor.start();
        return abstractStreamProcessor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)

Example 4 with ExpressionExecutor

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

the class LogStreamProcessor method init.

/**
 * The init method of the StreamFunction
 *
 * @param inputDefinition              the incoming stream definition
 * @param attributeExpressionExecutors the executors for the function parameters
 * @param siddhiAppContext         siddhi app context
 * @param configReader this hold the {@link LogStreamProcessor} configuration reader.
 * @return the additional output attributes introduced by the function
 */
@Override
protected List<Attribute> init(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    int inputExecutorLength = attributeExpressionExecutors.length;
    if (inputExecutorLength == 1) {
        if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING) {
            logMessageExpressionExecutor = attributeExpressionExecutors[0];
        } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.BOOL) {
            isLogEventExpressionExecutor = attributeExpressionExecutors[0];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'isEventLogged (Bool)' " + "or 'logMessage (String)' or 'isEventLogged (Bool), logMessage (String)' or 'priority " + "(String), isEventLogged (Bool), logMessage (String)', but its 1st attribute is " + attributeExpressionExecutors[0].getReturnType());
        }
    } else if (inputExecutorLength == 2) {
        if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING && attributeExpressionExecutors[1].getReturnType() == Attribute.Type.BOOL) {
            logMessageExpressionExecutor = attributeExpressionExecutors[0];
            isLogEventExpressionExecutor = attributeExpressionExecutors[1];
        } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING && attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING) {
            if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
                logPriority = LogPriority.valueOf(((String) attributeExpressionExecutors[0].execute(null)).toUpperCase());
            } else {
                logPriorityExpressionExecutor = attributeExpressionExecutors[0];
            }
            logMessageExpressionExecutor = attributeExpressionExecutors[1];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'logMessage (String), " + "isEventLogged (Bool)' or 'priority (String), logMessage (String)', but its returning are '" + attributeExpressionExecutors[0].getReturnType() + ", " + attributeExpressionExecutors[1].getReturnType() + "'");
        }
    } else if (inputExecutorLength == 3) {
        if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING) {
            if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
                logPriority = LogPriority.valueOf(((String) attributeExpressionExecutors[0].execute(null)).toUpperCase());
            } else {
                logPriorityExpressionExecutor = attributeExpressionExecutors[0];
            }
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 1st attribute is returning " + attributeExpressionExecutors[0].getReturnType());
        }
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING) {
            logMessageExpressionExecutor = attributeExpressionExecutors[1];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 2nd attribute is returning " + attributeExpressionExecutors[1].getReturnType());
        }
        if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.BOOL) {
            isLogEventExpressionExecutor = attributeExpressionExecutors[2];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 3rd attribute is returning " + attributeExpressionExecutors[2].getReturnType());
        }
    } else if (inputExecutorLength > 3) {
        throw new SiddhiAppValidationException("Input parameters for Log can be logMessage (String), " + "isEventLogged (Bool), but there are " + attributeExpressionExecutors.length + " in the input!");
    }
    logPrefix = siddhiAppContext.getName() + ": ";
    return new ArrayList<Attribute>();
}
Also used : ArrayList(java.util.ArrayList) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 5 with ExpressionExecutor

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

the class AggregateWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        AggregateWindowProcessor streamProcessor = new AggregateWindowProcessor(aggregationRuntime, within, per);
        streamProcessor.inputDefinition = inputDefinition;
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
        ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
        for (int i = 0; i < attributeExpressionLength; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
        }
        streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
        streamProcessor.attributeExpressionLength = attributeExpressionLength;
        streamProcessor.additionalAttributes = additionalAttributes;
        streamProcessor.complexEventPopulater = complexEventPopulater;
        streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        streamProcessor.start();
        return streamProcessor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)

Aggregations

ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)46 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)35 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)21 Attribute (org.wso2.siddhi.query.api.definition.Attribute)19 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)15 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)15 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)13 HashMap (java.util.HashMap)12 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)11 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)9 Expression (org.wso2.siddhi.query.api.expression.Expression)9 Variable (org.wso2.siddhi.query.api.expression.Variable)9 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)8 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)7 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)6 OutputAttribute (org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute)6 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)5 AndConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor)5