Search in sources :

Example 1 with BasicSelector

use of org.ballerinalang.siddhi.query.api.execution.query.selection.BasicSelector in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitGroup_by_query_selection.

@Override
public BasicSelector visitGroup_by_query_selection(@NotNull SiddhiQLParser.Group_by_query_selectionContext ctx) {
    BasicSelector selector = new BasicSelector();
    List<OutputAttribute> attributeList = new ArrayList<OutputAttribute>(ctx.output_attribute().size());
    for (SiddhiQLParser.Output_attributeContext output_attributeContext : ctx.output_attribute()) {
        attributeList.add((OutputAttribute) visit(output_attributeContext));
    }
    selector.addSelectionList(attributeList);
    if (ctx.group_by() != null) {
        selector.addGroupByList((List<Variable>) visit(ctx.group_by()));
    }
    populateQueryContext(selector, ctx);
    return selector;
}
Also used : SiddhiQLParser(org.ballerinalang.siddhi.query.compiler.SiddhiQLParser) Variable(org.ballerinalang.siddhi.query.api.expression.Variable) BasicSelector(org.ballerinalang.siddhi.query.api.execution.query.selection.BasicSelector) ArrayList(java.util.ArrayList) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)

Example 2 with BasicSelector

use of org.ballerinalang.siddhi.query.api.execution.query.selection.BasicSelector in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.query.compiler.SiddhiQLParser) Variable(org.ballerinalang.siddhi.query.api.expression.Variable) AggregationDefinition(org.ballerinalang.siddhi.query.api.definition.AggregationDefinition) TimePeriod(org.ballerinalang.siddhi.query.api.aggregation.TimePeriod) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) BasicSelector(org.ballerinalang.siddhi.query.api.execution.query.selection.BasicSelector)

Aggregations

BasicSelector (org.ballerinalang.siddhi.query.api.execution.query.selection.BasicSelector)2 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)2 SiddhiQLParser (org.ballerinalang.siddhi.query.compiler.SiddhiQLParser)2 ArrayList (java.util.ArrayList)1 TimePeriod (org.ballerinalang.siddhi.query.api.aggregation.TimePeriod)1 AggregationDefinition (org.ballerinalang.siddhi.query.api.definition.AggregationDefinition)1 BasicSingleInputStream (org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream)1 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)1