Search in sources :

Example 1 with ReturnStream

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

the class StoreQueryParser method buildExpectedOutputAttributes.

private static List<Attribute> buildExpectedOutputAttributes(StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition, MatchingMetaInfoHolder metaStreamInfoHolder) {
    MetaStateEvent selectMetaStateEvent = new MetaStateEvent(metaStreamInfoHolder.getMetaStateEvent().getMetaStreamEvents());
    SelectorParser.parse(storeQuery.getSelector(), new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS), siddhiAppContext, selectMetaStateEvent, tableMap, new ArrayList<>(), queryName, metaPosition);
    return selectMetaStateEvent.getOutputStreamDefinition().getAttributeList();
}
Also used : ReturnStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 2 with ReturnStream

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

the class StoreQueryParser method populateFindStoreQueryRuntime.

private static void populateFindStoreQueryRuntime(FindStoreQueryRuntime findStoreQueryRuntime, MatchingMetaInfoHolder metaStreamInfoHolder, Selector selector, List<VariableExpressionExecutor> variableExpressionExecutors, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition) {
    QuerySelector querySelector = SelectorParser.parse(selector, new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS), siddhiAppContext, metaStreamInfoHolder.getMetaStateEvent(), tableMap, variableExpressionExecutors, queryName, metaPosition);
    QueryParserHelper.reduceMetaComplexEvent(metaStreamInfoHolder.getMetaStateEvent());
    QueryParserHelper.updateVariablePosition(metaStreamInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
    querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStreamInfoHolder.getMetaStateEvent()));
    findStoreQueryRuntime.setStateEventPool(new StateEventPool(metaStreamInfoHolder.getMetaStateEvent(), 5));
    findStoreQueryRuntime.setSelector(querySelector);
    findStoreQueryRuntime.setOutputAttributes(metaStreamInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
}
Also used : StateEventPool(org.ballerinalang.siddhi.core.event.state.StateEventPool) QuerySelector(org.ballerinalang.siddhi.core.query.selector.QuerySelector) ReturnStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream)

Example 3 with ReturnStream

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

the class SiddhiQLBaseVisitorImpl method visitQuery_output.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public OutputStream visitQuery_output(@NotNull SiddhiQLParser.Query_outputContext ctx) {
    if (ctx.INSERT() != null) {
        Source source = (Source) visit(ctx.target());
        if (ctx.UPDATE() != null && ctx.OR() != null) {
            if (source.isInnerStream) {
                throw newSiddhiParserException(ctx, "UPDATE OR INTO INSERT be only used with Tables!");
            }
            if (ctx.output_event_type() != null) {
                if (ctx.set_clause() != null) {
                    OutputStream outputStream = new UpdateOrInsertStream(source.streamId, (OutputStream.OutputEventType) visit(ctx.output_event_type()), (UpdateSet) visit(ctx.set_clause()), (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                } else {
                    OutputStream outputStream = new UpdateOrInsertStream(source.streamId, (OutputStream.OutputEventType) visit(ctx.output_event_type()), (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                }
            } else {
                if (ctx.set_clause() != null) {
                    OutputStream outputStream = new UpdateOrInsertStream(source.streamId, (UpdateSet) visit(ctx.set_clause()), (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                } else {
                    OutputStream outputStream = new UpdateOrInsertStream(source.streamId, (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                }
            }
        } else {
            if (ctx.output_event_type() != null) {
                OutputStream outputStream = new InsertIntoStream(source.streamId, source.isInnerStream, (OutputStream.OutputEventType) visit(ctx.output_event_type()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            } else {
                OutputStream outputStream = new InsertIntoStream(source.streamId, source.isInnerStream);
                populateQueryContext(outputStream, ctx);
                return outputStream;
            }
        }
    } else if (ctx.DELETE() != null) {
        Source source = (Source) visit(ctx.target());
        if (source.isInnerStream) {
            throw newSiddhiParserException(ctx, "DELETE can be only used with Tables!");
        }
        if (ctx.output_event_type() != null) {
            OutputStream outputStream = new DeleteStream(source.streamId, (OutputStream.OutputEventType) visit(ctx.output_event_type()), (Expression) visit(ctx.expression()));
            populateQueryContext(outputStream, ctx);
            return outputStream;
        } else {
            OutputStream outputStream = new DeleteStream(source.streamId, (Expression) visit(ctx.expression()));
            populateQueryContext(outputStream, ctx);
            return outputStream;
        }
    } else if (ctx.UPDATE() != null) {
        Source source = (Source) visit(ctx.target());
        if (source.isInnerStream) {
            throw newSiddhiParserException(ctx, "DELETE can be only used with Tables!");
        }
        if (ctx.output_event_type() != null) {
            if (ctx.set_clause() != null) {
                OutputStream outputStream = new UpdateStream(source.streamId, (OutputStream.OutputEventType) visit(ctx.output_event_type()), (UpdateSet) visit(ctx.set_clause()), (Expression) visit(ctx.expression()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            } else {
                OutputStream outputStream = new UpdateStream(source.streamId, (OutputStream.OutputEventType) visit(ctx.output_event_type()), (Expression) visit(ctx.expression()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            }
        } else {
            if (ctx.set_clause() != null) {
                OutputStream outputStream = new UpdateStream(source.streamId, (UpdateSet) visit(ctx.set_clause()), (Expression) visit(ctx.expression()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            } else {
                OutputStream outputStream = new UpdateStream(source.streamId, (Expression) visit(ctx.expression()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            }
        }
    } else if (ctx.RETURN() != null) {
        if (ctx.output_event_type() != null) {
            OutputStream outputStream = new ReturnStream((OutputStream.OutputEventType) visit(ctx.output_event_type()));
            populateQueryContext(outputStream, ctx);
            return outputStream;
        } else {
            OutputStream outputStream = new ReturnStream();
            populateQueryContext(outputStream, ctx);
            return outputStream;
        }
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : UpdateOrInsertStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) DeleteStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.DeleteStream) OutputStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.OutputStream) InsertIntoStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream) UpdateStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateStream) ReturnStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream)

Example 4 with ReturnStream

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

the class SiddhiQLBaseVisitorImpl method visitAnonymous_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public AnonymousInputStream visitAnonymous_stream(@NotNull SiddhiQLParser.Anonymous_streamContext ctx) {
    if (ctx.anonymous_stream() != null) {
        return (AnonymousInputStream) visit(ctx.anonymous_stream());
    }
    Set<String> activeStreamsBackup = activeStreams;
    try {
        activeStreams = new HashSet<String>();
        Query query = Query.query().from((InputStream) visit(ctx.query_input()));
        if (ctx.query_section() != null) {
            query.select((Selector) visit(ctx.query_section()));
        }
        if (ctx.output_rate() != null) {
            query.output((OutputRate) visit(ctx.output_rate()));
        }
        if (ctx.output_event_type() != null) {
            query.outStream(new ReturnStream((OutputStream.OutputEventType) visit(ctx.output_event_type())));
        } else {
            query.outStream(new ReturnStream());
        }
        AnonymousInputStream anonymousInputStream = new AnonymousInputStream(query);
        populateQueryContext(anonymousInputStream, ctx);
        return anonymousInputStream;
    } finally {
        activeStreams.clear();
        activeStreams = activeStreamsBackup;
    }
}
Also used : StoreQuery(org.ballerinalang.siddhi.query.api.execution.query.StoreQuery) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) AnonymousInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.AnonymousInputStream) ReturnStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream)

Aggregations

ReturnStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream)4 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)1 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)1 QuerySelector (org.ballerinalang.siddhi.core.query.selector.QuerySelector)1 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)1 StoreQuery (org.ballerinalang.siddhi.query.api.execution.query.StoreQuery)1 AnonymousInputStream (org.ballerinalang.siddhi.query.api.execution.query.input.stream.AnonymousInputStream)1 DeleteStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.DeleteStream)1 InsertIntoStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream)1 OutputStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.OutputStream)1 UpdateOrInsertStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream)1 UpdateStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateStream)1 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)1