Search in sources :

Example 6 with FunctionDefinition

use of io.siddhi.query.api.definition.FunctionDefinition in project siddhi by wso2.

the class DefineFunctionTestCase method testFunction1.

@Test
public void testFunction1() {
    SiddhiApp siddhiApp = SiddhiApp.siddhiApp("test").defineFunction(new FunctionDefinition().id("foo").language("JS").type(Attribute.Type.STRING).body("return 'hello world!'"));
    SiddhiApp siddhiApp1 = SiddhiApp.siddhiApp("test").defineFunction(new FunctionDefinition().id("foo").language("JS").type(Attribute.Type.STRING).body("return 'hello world!'"));
    Assert.assertTrue(siddhiApp.getFunctionDefinitionMap().containsKey("foo"));
    Assert.assertTrue(siddhiApp.equals(siddhiApp1));
    Assert.assertEquals(siddhiApp.hashCode(), siddhiApp1.hashCode());
}
Also used : FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition) Test(org.testng.annotations.Test)

Example 7 with FunctionDefinition

use of io.siddhi.query.api.definition.FunctionDefinition in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery47.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery47() {
    log.info("Partition test47");
    SiddhiApp siddhiApp = new SiddhiApp("plan47");
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    siddhiApp.defineStream(streamDefinition);
    FunctionDefinition functionDefinition = new FunctionDefinition();
    siddhiApp.defineFunction(functionDefinition.id(null));
}
Also used : SiddhiApp(io.siddhi.query.api.SiddhiApp) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition) Test(org.testng.annotations.Test)

Example 8 with FunctionDefinition

use of io.siddhi.query.api.definition.FunctionDefinition in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitDefinition_function.

@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;
}
Also used : ValuePartitionType(io.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(io.siddhi.query.api.execution.partition.PartitionType) RangePartitionType(io.siddhi.query.api.execution.partition.RangePartitionType) Attribute(io.siddhi.query.api.definition.Attribute) OrderByAttribute(io.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition)

Aggregations

FunctionDefinition (io.siddhi.query.api.definition.FunctionDefinition)8 Test (org.testng.annotations.Test)6 SiddhiApp (io.siddhi.query.api.SiddhiApp)4 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)4 Attribute (io.siddhi.query.api.definition.Attribute)1 PartitionType (io.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (io.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (io.siddhi.query.api.execution.partition.ValuePartitionType)1 OrderByAttribute (io.siddhi.query.api.execution.query.selection.OrderByAttribute)1 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)1 SiddhiQLBaseVisitorImpl (io.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl)1 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1