Search in sources :

Example 1 with BasicSingleInputStream

use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.

the class InputStreamParser method parse.

/**
 * Parse an InputStream returning corresponding StreamRuntime.
 *
 * @param inputStream                input stream to be parsed
 * @param siddhiAppContext           associated siddhi siddhiAppContext
 * @param streamDefinitionMap        map containing user given stream definitions
 * @param tableDefinitionMap         table definition map
 * @param windowDefinitionMap        window definition map
 * @param aggregationDefinitionMap   aggregation definition map
 * @param tableMap                   Table Map
 * @param windowMap                  event window map
 * @param aggregationMap             aggregator map
 * @param executors                  List to hold VariableExpressionExecutors to update after query parsing
 * @param latencyTracker             latency tracker
 * @param outputExpectsExpiredEvents is output expects ExpiredEvents
 * @param queryName                  query name of input stream belongs to.
 * @return StreamRuntime
 */
public static StreamRuntime parse(InputStream inputStream, SiddhiAppContext siddhiAppContext, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, Map<String, Window> windowMap, Map<String, AggregationRuntime> aggregationMap, List<VariableExpressionExecutor> executors, LatencyTracker latencyTracker, boolean outputExpectsExpiredEvents, String queryName) {
    if (inputStream instanceof BasicSingleInputStream || inputStream instanceof SingleInputStream) {
        SingleInputStream singleInputStream = (SingleInputStream) inputStream;
        Window window = windowMap.get(singleInputStream.getStreamId());
        // If stream is from window, allow batch
        boolean batchProcessingAllowed = window != null;
        // processing
        ProcessStreamReceiver processStreamReceiver = new ProcessStreamReceiver(singleInputStream.getStreamId(), latencyTracker, queryName, siddhiAppContext);
        processStreamReceiver.setBatchProcessingAllowed(batchProcessingAllowed);
        return SingleInputStreamParser.parseInputStream((SingleInputStream) inputStream, siddhiAppContext, executors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, new MetaStreamEvent(), processStreamReceiver, true, outputExpectsExpiredEvents, queryName);
    } else if (inputStream instanceof JoinInputStream) {
        return JoinInputStreamParser.parseInputStream(((JoinInputStream) inputStream), siddhiAppContext, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, latencyTracker, outputExpectsExpiredEvents, queryName);
    } else if (inputStream instanceof StateInputStream) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(inputStream.getAllStreamIds().size());
        return StateInputStreamParser.parseInputStream(((StateInputStream) inputStream), siddhiAppContext, metaStateEvent, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, executors, latencyTracker, queryName);
    } else {
        throw new OperationNotSupportedException();
    }
}
Also used : Window(org.ballerinalang.siddhi.core.window.Window) OperationNotSupportedException(org.ballerinalang.siddhi.core.exception.OperationNotSupportedException) ProcessStreamReceiver(org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.JoinInputStream) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) StateInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.StateInputStream) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 2 with BasicSingleInputStream

use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitLogical_absent_stateful_source.

@Override
public Object visitLogical_absent_stateful_source(SiddhiQLParser.Logical_absent_stateful_sourceContext ctx) {
    // ;
    if (ctx.logical_absent_stateful_source() != null) {
        return visit(ctx.logical_absent_stateful_source());
    } else if (ctx.AND() != null) {
        if (ctx.basic_absent_pattern_source().size() == 2) {
            StateElement stateElement = State.logicalNotAnd((AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0)), (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(1)));
            populateQueryContext(stateElement, ctx);
            return stateElement;
        } else {
            StreamStateElement presentStreamState = (StreamStateElement) visit(ctx.standard_stateful_source());
            AbsentStreamStateElement absentStreamState;
            if (!ctx.basic_absent_pattern_source().isEmpty()) {
                absentStreamState = (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0));
            } else {
                absentStreamState = State.logicalNot(new StreamStateElement((BasicSingleInputStream) visit(ctx.basic_source())));
            }
            StateElement stateElement = State.logicalNotAnd(absentStreamState, presentStreamState);
            populateQueryContext(stateElement, ctx);
            return stateElement;
        }
    } else if (ctx.OR() != null) {
        if (ctx.basic_absent_pattern_source().size() == 2) {
            return State.logicalOr((AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0)), (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(1)));
        } else {
            StreamStateElement streamStateElement1 = (StreamStateElement) visit(ctx.standard_stateful_source());
            AbsentStreamStateElement streamStateElement2 = (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0));
            StateElement stateElement = State.logicalOr(streamStateElement2, streamStateElement1);
            populateQueryContext(stateElement, ctx);
            return stateElement;
        }
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) EveryStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement) StateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement) AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) NextStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement) CountStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)

Example 3 with BasicSingleInputStream

use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitStandard_stateful_source.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public StreamStateElement visitStandard_stateful_source(@NotNull SiddhiQLParser.Standard_stateful_sourceContext ctx) {
    if (ctx.event() != null) {
        activeStreams.add(visitEvent(ctx.event()));
    }
    BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.basic_source());
    if (ctx.event() != null) {
        if (basicSingleInputStream.isInnerStream()) {
            activeStreams.remove("#" + basicSingleInputStream.getStreamId());
        } else {
            activeStreams.remove(basicSingleInputStream.getStreamId());
        }
        StreamStateElement streamStateElement = new StreamStateElement(basicSingleInputStream.as((String) visit(ctx.event())));
        populateQueryContext(streamStateElement, ctx);
        return streamStateElement;
    } else {
        StreamStateElement streamStateElement = new StreamStateElement(basicSingleInputStream);
        populateQueryContext(streamStateElement, ctx);
        return streamStateElement;
    }
}
Also used : AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream)

Example 4 with BasicSingleInputStream

use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream 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)

Example 5 with BasicSingleInputStream

use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitStandard_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public SingleInputStream visitStandard_stream(@NotNull SiddhiQLParser.Standard_streamContext ctx) {
    // standard_stream
    // : io (basic_source_stream_handler)* window? (basic_source_stream_handler)*
    // ;
    Source source = (Source) visit(ctx.source());
    BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(null, source.streamId, source.isInnerStream);
    if (ctx.pre_window_handlers != null) {
        basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.pre_window_handlers));
    }
    if (ctx.window() == null && ctx.post_window_handlers == null) {
        populateQueryContext(basicSingleInputStream, ctx);
        return basicSingleInputStream;
    } else if (ctx.window() != null) {
        SingleInputStream singleInputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window()));
        if (ctx.post_window_handlers != null) {
            singleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.post_window_handlers));
        }
        populateQueryContext(singleInputStream, ctx);
        return singleInputStream;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : Window(org.ballerinalang.siddhi.query.api.execution.query.input.handler.Window) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) StreamHandler(org.ballerinalang.siddhi.query.api.execution.query.input.handler.StreamHandler) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

BasicSingleInputStream (org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream)9 AbsentStreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)4 StreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)4 StreamHandler (org.ballerinalang.siddhi.query.api.execution.query.input.handler.StreamHandler)3 SingleInputStream (org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream)3 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)2 CountStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement)2 EveryStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement)2 NextStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement)2 StateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement)2 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)1 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)1 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)1 EntryValveProcessor (org.ballerinalang.siddhi.core.query.input.stream.single.EntryValveProcessor)1 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)1