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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations