Search in sources :

Example 61 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitDefinition_window.

@Override
public Object visitDefinition_window(@NotNull SiddhiQLParser.Definition_windowContext ctx) {
    Source source = (Source) visit(ctx.source());
    if (source.isInnerStream) {
        throw newSiddhiParserException(ctx, "'#' cannot be used, because Windows can't be defined as InnerStream!");
    }
    WindowDefinition windowDefinition = WindowDefinition.id(source.streamId);
    List<SiddhiQLParser.Attribute_nameContext> attribute_names = ctx.attribute_name();
    List<SiddhiQLParser.Attribute_typeContext> attribute_types = ctx.attribute_type();
    for (int i = 0; i < attribute_names.size(); i++) {
        SiddhiQLParser.Attribute_nameContext attributeNameContext = attribute_names.get(i);
        SiddhiQLParser.Attribute_typeContext attributeTypeContext = attribute_types.get(i);
        windowDefinition.attribute((String) visit(attributeNameContext), (Attribute.Type) visit(attributeTypeContext));
    }
    for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
        windowDefinition.annotation((Annotation) visit(annotationContext));
    }
    AttributeFunction attributeFunction = (AttributeFunction) visit(ctx.function_operation());
    Window window = new Window(attributeFunction.getNamespace(), attributeFunction.getName(), attributeFunction.getParameters());
    windowDefinition.window(window);
    // Optional output event type
    if (ctx.output_event_type() != null) {
        windowDefinition.setOutputEventType((OutputStream.OutputEventType) visit(ctx.output_event_type()));
    }
    populateQueryContext(windowDefinition, ctx);
    return windowDefinition;
}
Also used : Window(org.wso2.siddhi.query.api.execution.query.input.handler.Window) SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) OutputAttribute(org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute) Attribute(org.wso2.siddhi.query.api.definition.Attribute) OrderByAttribute(org.wso2.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputStream(org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream) AttributeFunction(org.wso2.siddhi.query.api.expression.AttributeFunction) WindowDefinition(org.wso2.siddhi.query.api.definition.WindowDefinition)

Example 62 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitDefinition_aggregation.

@Override
public AggregationDefinition visitDefinition_aggregation(@NotNull SiddhiQLParser.Definition_aggregationContext ctx) {
    // Read the name of the aggregation
    String aggregationName = (String) visitAggregation_name(ctx.aggregation_name());
    // Create the aggregation using the extracted aggregation name
    AggregationDefinition aggregationDefinition = AggregationDefinition.id(aggregationName);
    // Get all annotation and populate the aggregation
    for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
        aggregationDefinition.annotation((Annotation) visit(annotationContext));
    }
    // Attach the input stream
    BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.standard_stream());
    aggregationDefinition.from(basicSingleInputStream);
    // Extract the selector and attach it to the new aggregation
    BasicSelector selector = (BasicSelector) visit(ctx.group_by_query_selection());
    aggregationDefinition.select(selector);
    // Get the variable (if available) and aggregate on that variable
    if (ctx.attribute_reference() != null) {
        Variable aggregatedBy = (Variable) visit(ctx.attribute_reference());
        aggregationDefinition.aggregateBy(aggregatedBy);
    }
    // Extract the specified time-durations and attache it to the aggregation definition
    TimePeriod timePeriod = (TimePeriod) visit(ctx.aggregation_time());
    aggregationDefinition.every(timePeriod);
    populateQueryContext(aggregationDefinition, ctx);
    return aggregationDefinition;
}
Also used : SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) Variable(org.wso2.siddhi.query.api.expression.Variable) AggregationDefinition(org.wso2.siddhi.query.api.definition.AggregationDefinition) TimePeriod(org.wso2.siddhi.query.api.aggregation.TimePeriod) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) BasicSelector(org.wso2.siddhi.query.api.execution.query.selection.BasicSelector)

Example 63 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class DefineStreamTestCase method testMultilevelNestedAnnotations1.

@Test
public void testMultilevelNestedAnnotations1() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("@sink(url='http://foo.com/test/{{data}}', " + "   @map(type='xml', " + "@payload('<test><time>{{time}}</time></test>')" + "   )" + ") " + "define stream fooStream (id int, name string);");
    AssertJUnit.assertEquals(StreamDefinition.id("fooStream").attribute("id", Attribute.Type.INT).attribute("name", Attribute.Type.STRING).annotation(Annotation.annotation("sink").element("url", "http://foo.com/test/{{data}}").annotation(Annotation.annotation("map").element("type", "xml").annotation(Annotation.annotation("payload").element("<test><time>{{time}}</time></test>")))), streamDefinition);
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 64 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class DefineStreamTestCase method testEqualObjects.

@Test
public void testEqualObjects() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("@Foo(name='bar','Custom')define " + "stream cseStream ( symbol string, price int, volume float )");
    AssertJUnit.assertEquals(StreamDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).annotation(Annotation.annotation("Foo").element("name", "bar").element("Custom")), streamDefinition);
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 65 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class DefineStreamTestCase method testMultilevelNestedAnnotations2.

@Test
public void testMultilevelNestedAnnotations2() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("" + "@source(" + "   type='http', " + "   context='/test', " + "   transport='http,https', " + "   @map(" + "       type='xml', " + "       namespace = \"h=uri, a=uri\", " + "       @attributes(" + "           '//h:time', " + "           '//h:data'" + "       )" + "   )" + ") " + "define stream fooStream (id int, name string);");
    AssertJUnit.assertEquals(StreamDefinition.id("fooStream").attribute("id", Attribute.Type.INT).attribute("name", Attribute.Type.STRING).annotation(Annotation.annotation("source").element("type", "http").element("context", "/test").element("transport", "http,https").annotation(Annotation.annotation("map").element("type", "xml").element("namespace", "h=uri, a=uri").annotation(Annotation.annotation("attributes").element("//h:time").element("//h:data")))), streamDefinition);
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7