use of org.wso2.siddhi.query.api.execution.query.input.handler.StreamFunction 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>();
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.StreamFunction in project siddhi by wso2.
the class SingleInputStreamParser method generateProcessor.
public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> variableExpressionExecutors, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, String queryName) {
Expression[] parameters = streamHandler.getParameters();
MetaStreamEvent metaStreamEvent;
int stateIndex = SiddhiConstants.UNKNOWN_STATE;
if (metaEvent instanceof MetaStateEvent) {
stateIndex = ((MetaStateEvent) metaEvent).getStreamEventCount() - 1;
metaStreamEvent = ((MetaStateEvent) metaEvent).getMetaStreamEvent(stateIndex);
} else {
metaStreamEvent = (MetaStreamEvent) metaEvent;
}
ExpressionExecutor[] attributeExpressionExecutors;
if (parameters != null) {
if (parameters.length > 0) {
attributeExpressionExecutors = new ExpressionExecutor[parameters.length];
for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) {
attributeExpressionExecutors[i] = ExpressionParser.parseExpression(parameters[i], metaEvent, stateIndex, tableMap, variableExpressionExecutors, siddhiAppContext, false, SiddhiConstants.CURRENT, queryName);
}
} else {
List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
int parameterSize = attributeList.size();
attributeExpressionExecutors = new ExpressionExecutor[parameterSize];
for (int i = 0; i < parameterSize; i++) {
attributeExpressionExecutors[i] = ExpressionParser.parseExpression(new Variable(attributeList.get(i).getName()), metaEvent, stateIndex, tableMap, variableExpressionExecutors, siddhiAppContext, false, SiddhiConstants.CURRENT, queryName);
}
}
} else {
attributeExpressionExecutors = new ExpressionExecutor[0];
}
ConfigReader configReader;
if (streamHandler instanceof Filter) {
return new FilterProcessor(attributeExpressionExecutors[0]);
} else if (streamHandler instanceof Window) {
WindowProcessor windowProcessor = (WindowProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, WindowProcessorExtensionHolder.getInstance(siddhiAppContext));
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((Window) streamHandler).getNamespace(), ((Window) streamHandler).getName());
windowProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler);
return windowProcessor;
} else if (streamHandler instanceof StreamFunction) {
AbstractStreamProcessor abstractStreamProcessor;
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName());
if (supportsBatchProcessing) {
try {
abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiAppContext));
metaStreamEvent.addInputDefinition(abstractStreamProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler));
return abstractStreamProcessor;
} catch (SiddhiAppCreationException e) {
if (!e.isClassLoadingIssue()) {
ExceptionUtil.populateQueryContext(e, streamHandler, siddhiAppContext);
throw e;
}
}
}
abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamFunctionProcessorExtensionHolder.getInstance(siddhiAppContext));
metaStreamEvent.addInputDefinition(abstractStreamProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler));
return abstractStreamProcessor;
} else {
throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported", streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex());
}
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.StreamFunction in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitStream_function.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public StreamFunction visitStream_function(@NotNull SiddhiQLParser.Stream_functionContext ctx) {
AttributeFunction attributeFunction = (AttributeFunction) visit(ctx.function_operation());
StreamFunction streamFunction = new StreamFunction(attributeFunction.getNamespace(), attributeFunction.getName(), attributeFunction.getParameters());
populateQueryContext(streamFunction, ctx);
return streamFunction;
}
Aggregations