public void defineFunction(FunctionDefinition functionDefinition) { if (functionDefinition == null) { throw new SiddhiAppValidationException("Function Definition should not be null"); } else if (functionDefinition.getId() == null) { throw new SiddhiAppValidationException("Function Id should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } else if (functionDefinition.getReturnType() == null) { throw new SiddhiAppValidationException("Return type should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } else if (functionDefinition.getBody() == null) { throw new SiddhiAppValidationException("Body should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } else if (functionDefinition.getLanguage() == null) { throw new SiddhiAppValidationException("Language should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } checkDuplicateFunctionExist(functionDefinition); this.functionDefinitionMap.put(functionDefinition.getId(), functionDefinition); }
private void checkDuplicateFunctionExist(FunctionDefinition functionDefinition) { if (this.functionDefinitionMap.get(functionDefinition.getId()) != null) { throw new DuplicateDefinitionException("The function definition with the same id exists " + functionDefinition.getId(), functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } }
/** * Generates FunctionConfig from the given Siddhi FunctionDefinition * * @param functionDefinition Siddhi FunctionDefinition * @return FunctionConfig object */ public FunctionConfig generateFunctionConfig(FunctionDefinition functionDefinition) { FunctionConfig functionConfig = new FunctionConfig(functionDefinition.getId(), functionDefinition.getLanguage(), functionDefinition.getReturnType().toString(), functionDefinition.getBody()); preserveAndBindCodeSegment(functionDefinition, functionConfig); return functionConfig; } }
@Override public FunctionDefinition visitDefinition_function(@NotNull SiddhiQLParser.Definition_functionContext ctx) { String functionName = (String) visitFunction_name(ctx.function_name()); String languageName = (String) visitLanguage_name(ctx.language_name()); Attribute.Type attributeType = (Attribute.Type) visit(ctx.attribute_type()); String functionBody = (String) visitFunction_body(ctx.function_body()); FunctionDefinition functionDefinition = new FunctionDefinition(); functionDefinition.id(functionName).language(languageName). type(attributeType).body(functionBody); populateQueryContext(functionDefinition, ctx); return functionDefinition; }
/** * obtains information of all the user defined Functions. */ private void loadFunctionData(SiddhiApp siddhiApp, List<OutputAttribute> functionList, SiddhiAppElements siddhiAppElements, String appData) { for (FunctionDefinition functionDefinition : siddhiApp.getFunctionDefinitionMap().values()) { for (OutputAttribute app : functionList) { if (app.getExpression() instanceof AttributeFunction) { if (functionDefinition.getId().equals(((AttributeFunction) app.getExpression()).getName())) { String functionDefinitionStr = getDefinition(functionDefinition, appData); siddhiAppElements.setFunction(functionDefinition.getId()); siddhiAppElements.setFunctionQuery(functionDefinitionStr); break; } } } } }
private void checkDuplicateFunctionExist(FunctionDefinition functionDefinition) { if (this.functionDefinitionMap.get(functionDefinition.getId()) != null) { throw new DuplicateDefinitionException("The function definition with the same id exists " + functionDefinition.getId(), functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } }
public void defineFunction(FunctionDefinition functionDefinition) { if (functionDefinition == null) { throw new SiddhiAppValidationException("Function Definition should not be null"); } else if (functionDefinition.getId() == null) { throw new SiddhiAppValidationException("Function Id should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } else if (functionDefinition.getReturnType() == null) { throw new SiddhiAppValidationException("Return type should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } else if (functionDefinition.getBody() == null) { throw new SiddhiAppValidationException("Body should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } else if (functionDefinition.getLanguage() == null) { throw new SiddhiAppValidationException("Language should not be null for Function Definition", functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex()); } checkDuplicateFunctionExist(functionDefinition); this.functionDefinitionMap.put(functionDefinition.getId(), functionDefinition); }