Search in sources :

Example 46 with ExpressionExecutor

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

the class AbstractStreamProcessor method initProcessor.

public AbstractDefinition initProcessor(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext, boolean outputExpectsExpiredEvents, String queryName, SiddhiElement siddhiElement) {
    this.configReader = configReader;
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    try {
        this.inputDefinition = inputDefinition;
        this.attributeExpressionExecutors = attributeExpressionExecutors;
        this.siddhiAppContext = siddhiAppContext;
        this.attributeExpressionLength = attributeExpressionExecutors.length;
        this.queryName = queryName;
        if (elementId == null) {
            elementId = "AbstractStreamProcessor-" + siddhiAppContext.getElementIdGenerator().createNewId();
        }
        siddhiAppContext.getSnapshotService().addSnapshotable(queryName, this);
        this.additionalAttributes = init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        siddhiAppContext.addEternalReferencedHolder(this);
        StreamDefinition outputDefinition = StreamDefinition.id(inputDefinition.getId());
        outputDefinition.setQueryContextStartIndex(siddhiElement.getQueryContextStartIndex());
        outputDefinition.setQueryContextEndIndex(siddhiElement.getQueryContextEndIndex());
        for (Attribute attribute : inputDefinition.getAttributeList()) {
            outputDefinition.attribute(attribute.getName(), attribute.getType());
        }
        for (Attribute attribute : additionalAttributes) {
            outputDefinition.attribute(attribute.getName(), attribute.getType());
        }
        return outputDefinition;
    } catch (Throwable t) {
        throw new SiddhiAppCreationException(t);
    }
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException)

Example 47 with ExpressionExecutor

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

the class ExternalTimeBatchWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    if (outputExpectsExpiredEvents) {
        this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
        this.storeExpiredEvents = true;
    }
    if (attributeExpressionExecutors.length >= 2 && attributeExpressionExecutors.length <= 5) {
        if (!(attributeExpressionExecutors[0] instanceof VariableExpressionExecutor)) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be a" + " variable, but found " + attributeExpressionExecutors[0].getClass());
        }
        if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.LONG) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be " + "type long, but found " + attributeExpressionExecutors[0].getReturnType());
        }
        timestampExpressionExecutor = (VariableExpressionExecutor) attributeExpressionExecutors[0];
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            timeToKeep = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
            timeToKeep = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        } else {
            throw new SiddhiAppValidationException("ExternalTimeBatch window's 2nd parameter windowTime " + "should be either int or long, but found " + attributeExpressionExecutors[1].getReturnType());
        }
        if (attributeExpressionExecutors.length >= 3) {
            isStartTimeEnabled = true;
            if ((attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor)) {
                if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.INT) {
                    startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
                } else if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.LONG) {
                    startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
                } else {
                    throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter " + "startTime should either be a constant (of type int or long) or an attribute (of type" + " long), but found " + attributeExpressionExecutors[2].getReturnType());
                }
            } else if (attributeExpressionExecutors[2].getReturnType() != Attribute.Type.LONG) {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter startTime " + "should either be a constant (of type int or long) or an attribute (of type long), but " + "found " + attributeExpressionExecutors[2].getReturnType());
            } else {
                startTimeAsVariable = attributeExpressionExecutors[2];
            }
        }
        if (attributeExpressionExecutors.length >= 4) {
            if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.INT) {
                schedulerTimeout = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
            } else if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.LONG) {
                schedulerTimeout = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
            } else {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 4th parameter timeout " + "should be either int or long, but found " + attributeExpressionExecutors[3].getReturnType());
            }
        }
        if (attributeExpressionExecutors.length == 5) {
            if (attributeExpressionExecutors[4].getReturnType() == Attribute.Type.BOOL) {
                replaceTimestampWithBatchEndTime = Boolean.parseBoolean(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[4]).getValue()));
            } else {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 5th parameter " + "replaceTimestampWithBatchEndTime should be bool, but found " + attributeExpressionExecutors[4].getReturnType());
            }
        }
    } else {
        throw new SiddhiAppValidationException("ExternalTimeBatch window should only have two to five " + "parameters (<long> timestamp, <int|long|time> windowTime, <long> startTime, <int|long|time> " + "timeout, <bool> replaceTimestampWithBatchEndTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    if (schedulerTimeout > 0) {
        if (expiredEventChunk == null) {
            this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 48 with ExpressionExecutor

use of org.wso2.siddhi.core.executor.ExpressionExecutor 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)

Example 49 with ExpressionExecutor

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

the class TableWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        TableWindowProcessor streamProcessor = new TableWindowProcessor(table);
        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)

Example 50 with ExpressionExecutor

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

the class WindowWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        WindowWindowProcessor streamProcessor = new WindowWindowProcessor(window);
        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