Search in sources :

Example 1 with FunctionDefinition

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

the class PartitionTestCase1 method testPartitionQuery46.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery46() {
    log.info("Partition test46");
    SiddhiApp siddhiApp = new SiddhiApp("plan46");
    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 = null;
    siddhiApp.defineFunction(functionDefinition);
}
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 2 with FunctionDefinition

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

the class PartitionTestCase1 method testPartitionQuery48.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery48() {
    log.info("Partition test48");
    SiddhiApp siddhiApp = new SiddhiApp("plan48");
    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("e1").type(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 3 with FunctionDefinition

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

the class PartitionTestCase1 method testPartitionQuery49.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery49() {
    log.info("Partition test49");
    SiddhiApp siddhiApp = new SiddhiApp("plan49");
    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("e1").type(Attribute.Type.STRING).body(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 4 with FunctionDefinition

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

the class SimpleQueryTestCase method testFunctionDefinition.

@Test
public void testFunctionDefinition() throws SiddhiParserException {
    FunctionDefinition functionDefinition = SiddhiCompiler.parseFunctionDefinition("define function concatFn[javascript] return string " + "{var str1 = data[0];};");
    AssertJUnit.assertEquals(functionDefinition.getId(), "concatFn");
    AssertJUnit.assertEquals(functionDefinition.getBody(), "var str1 = data[0]");
    AssertJUnit.assertEquals(functionDefinition.getLanguage(), "javascript");
    AssertJUnit.assertEquals(functionDefinition.getReturnType(), Attribute.Type.STRING);
}
Also used : FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition) Test(org.testng.annotations.Test)

Example 5 with FunctionDefinition

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

the class SiddhiCompiler method parseFunctionDefinition.

public static FunctionDefinition parseFunctionDefinition(String functionDefinition) throws SiddhiParserException {
    CharStream input = CharStreams.fromString(functionDefinition);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.definition_function_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (FunctionDefinition) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) FunctionDefinition(io.siddhi.query.api.definition.FunctionDefinition) SiddhiQLBaseVisitorImpl(io.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) CharStream(org.antlr.v4.runtime.CharStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

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