Search in sources :

Example 1 with StreamStateElement

use of org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement 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 2 with StreamStateElement

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

the class SiddhiQLBaseVisitorImpl method visitSequence_collection_stateful_source.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public CountStateElement visitSequence_collection_stateful_source(@NotNull SiddhiQLParser.Sequence_collection_stateful_sourceContext ctx) {
    // sequence_collection_stateful_source
    // :standard_stateful_source ('<' collect '>'|zero_or_more='*'|zero_or_one='?'|one_or_more='+')
    // ;
    StreamStateElement streamStateElement = (StreamStateElement) visit(ctx.standard_stateful_source());
    if (ctx.one_or_more != null) {
        CountStateElement countStateElement = new CountStateElement(streamStateElement, 1, CountStateElement.ANY);
        populateQueryContext(countStateElement, ctx);
        return countStateElement;
    } else if (ctx.zero_or_more != null) {
        CountStateElement countStateElement = new CountStateElement(streamStateElement, 0, CountStateElement.ANY);
        populateQueryContext(countStateElement, ctx);
        return countStateElement;
    } else if (ctx.zero_or_one != null) {
        CountStateElement countStateElement = new CountStateElement(streamStateElement, 0, 1);
        populateQueryContext(countStateElement, ctx);
        return countStateElement;
    } else if (ctx.collect() != null) {
        Object[] minMax = (Object[]) visit(ctx.collect());
        int min = CountStateElement.ANY;
        int max = CountStateElement.ANY;
        if (minMax[0] != null) {
            min = (Integer) minMax[0];
        }
        if (minMax[1] != null) {
            max = (Integer) minMax[1];
        }
        CountStateElement countStateElement = new CountStateElement(streamStateElement, min, max);
        populateQueryContext(countStateElement, ctx);
        return countStateElement;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : CountStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)

Example 3 with StreamStateElement

use of org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement 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 StreamStateElement

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

the class SiddhiQLBaseVisitorImpl method visitPattern_collection_stateful_source.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public CountStateElement visitPattern_collection_stateful_source(@NotNull SiddhiQLParser.Pattern_collection_stateful_sourceContext ctx) {
    StreamStateElement streamStateElement = (StreamStateElement) visit(ctx.standard_stateful_source());
    if (ctx.collect() != null) {
        Object[] minMax = (Object[]) visit(ctx.collect());
        int min = CountStateElement.ANY;
        int max = CountStateElement.ANY;
        if (minMax[0] != null) {
            min = (Integer) minMax[0];
        }
        if (minMax[1] != null) {
            max = (Integer) minMax[1];
        }
        CountStateElement stateElement = new CountStateElement(streamStateElement, min, max);
        populateQueryContext(stateElement, ctx);
        return stateElement;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : CountStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)

Example 5 with StreamStateElement

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

the class SiddhiQLBaseVisitorImpl method visitLogical_stateful_source.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitLogical_stateful_source(@NotNull SiddhiQLParser.Logical_stateful_sourceContext ctx) {
    if (ctx.AND() != null) {
        StreamStateElement streamStateElement1 = (StreamStateElement) visit(ctx.standard_stateful_source(0));
        StreamStateElement streamStateElement2 = (StreamStateElement) visit(ctx.standard_stateful_source(1));
        StateElement stateElement = State.logicalAnd(streamStateElement1, streamStateElement2);
        populateQueryContext(stateElement, ctx);
        return stateElement;
    } else if (ctx.OR() != null) {
        StreamStateElement streamStateElement1 = (StreamStateElement) visit(ctx.standard_stateful_source(0));
        StreamStateElement streamStateElement2 = (StreamStateElement) visit(ctx.standard_stateful_source(1));
        StateElement stateElement = State.logicalOr(streamStateElement1, streamStateElement2);
        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) 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)

Aggregations

AbsentStreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)7 StreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)7 CountStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement)5 BasicSingleInputStream (org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream)4 EveryStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement)3 NextStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement)3 StateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement)3 AbstractMap (java.util.AbstractMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1 EntryValveProcessor (org.ballerinalang.siddhi.core.query.input.stream.single.EntryValveProcessor)1 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 AbsentLogicalPostStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.AbsentLogicalPostStateProcessor)1 AbsentLogicalPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor)1 AbsentStreamPostStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.AbsentStreamPostStateProcessor)1 AbsentStreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)1 CountPostStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.CountPostStateProcessor)1 CountPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.CountPreStateProcessor)1 LogicalPostStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.LogicalPostStateProcessor)1