use of io.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method init.
@Override
protected StateFactory init(MetaStreamEvent metaStreamEvent, AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
expressionString = (String) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
constructExpression(metaStreamEvent, siddhiQueryContext);
} else {
for (Attribute attribute : inputDefinition.getAttributeList()) {
metaStreamEvent.addData(attribute);
}
expressionStringExecutor = attributeExpressionExecutors[0];
}
if (attributeExpressionExecutors.length > 1) {
if (attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor) {
includeTriggeringEvent = (Boolean) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
} else {
includeTriggeringEventExecutor = attributeExpressionExecutors[1];
}
if (attributeExpressionExecutors.length > 2 && attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor) {
streamInputEvents = (Boolean) ((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue();
}
}
return () -> new WindowState();
}
use of io.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method init.
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
this.findToBeExecuted = findToBeExecuted;
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) {
commonStartTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
} else if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.LONG) {
commonStartTime = 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");
}
return () -> new WindowState(outputExpectsExpiredEvents, schedulerTimeout, commonStartTime);
}
use of io.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.
the class ExpressionWindowProcessor method init.
@Override
protected StateFactory init(MetaStreamEvent metaStreamEvent, AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
expressionString = (String) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
constructExpression(metaStreamEvent, siddhiQueryContext);
} else {
for (Attribute attribute : inputDefinition.getAttributeList()) {
metaStreamEvent.addData(attribute);
}
expressionStringExecutor = attributeExpressionExecutors[0];
}
return () -> new WindowState();
}
use of io.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.
the class LogStreamProcessor method init.
/**
* The init method of the StreamFunction
*
* @param metaStreamEvent the stream event meta
* @param inputDefinition the incoming stream definition
* @param attributeExpressionExecutors the executors for the function parameters
* @param configReader this hold the {@link LogStreamProcessor} configuration reader.
* @param streamEventClonerHolder streamEventCloner Holder
* @param findToBeExecuted find will be executed
* @param siddhiQueryContext current siddhi query context
* @return the additional output attributes introduced by the function
*/
@Override
protected StateFactory init(MetaStreamEvent metaStreamEvent, AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
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 = siddhiQueryContext.getSiddhiAppContext().getName() + ": ";
return null;
}
use of io.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.
the class EventTestCase method testConditionExpressionExecutorValidation.
@Test(expectedExceptions = OperationNotSupportedException.class)
public void testConditionExpressionExecutorValidation() {
// StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
// .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
volumeVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 2 });
ConstantExpressionExecutor constantExpressionExecutor = new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT);
ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(constantExpressionExecutor, compareGreaterThanExecutor);
}
Aggregations