io.siddhi.query.api.execution.query.input.handler.StreamHandler Java Examples

The following examples show how to use io.siddhi.query.api.execution.query.input.handler.StreamHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SiddhiExecutionPlanner.java    From flink-siddhi with Apache License 2.0 6 votes vote down vote up
private StreamPartition findStreamPartition(SingleInputStream inputStream, Selector selector) {
    // Window Spec
    List<Window> windows = new ArrayList<>();
    for (StreamHandler streamHandler : inputStream.getStreamHandlers()) {
        if (streamHandler instanceof Window) {
            windows.add((Window) streamHandler);
        }
    }

    // Group By Spec
    List<Variable> groupBy = selector.getGroupByList();
    if (windows.size() > 0 || groupBy.size() > 0) {
        return generatePartition(inputStream.getStreamId(), windows, groupBy);
    } else {
        return null;
    }
}
 
Example #2
Source File: PolicyExecutionPlannerImpl.java    From eagle with Apache License 2.0 6 votes vote down vote up
private StreamPartition findStreamPartition(SingleInputStream inputStream, Selector selector) {
    // Window Spec
    List<Window> windows = new ArrayList<>();
    for (StreamHandler streamHandler : inputStream.getStreamHandlers()) {
        if (streamHandler instanceof Window) {
            windows.add((Window) streamHandler);
        }
    }

    // Group By Spec
    List<Variable> groupBy = selector.getGroupByList();
    if (windows.size() > 0 || groupBy.size() >= 0) {
        return generatePartition(inputStream.getStreamId(), windows, groupBy);
    } else {
        return null;
    }
}
 
Example #3
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
     * {@inheritDoc}
     * <p>The default implementation returns the result of calling
     * {@link #visitChildren} on {@code ctx}.</p>
     *
     * @param ctx
     */
    @Override
    public BasicSingleInputStream visitBasic_source(@NotNull SiddhiQLParser.Basic_sourceContext ctx) {

//        basic_source
//        : io (basic_source_stream_handler)*
//        ;

        Source source = (Source) visit(ctx.source());

        BasicSingleInputStream basicSingleInputStream =
                new BasicSingleInputStream(null, source.streamId, source.isInnerStream, source.isFaultStream);

        if (ctx.basic_source_stream_handlers() != null) {
            basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.basic_source_stream_handlers()));
        }
        populateQueryContext(basicSingleInputStream, ctx);
        return basicSingleInputStream;
    }
 
Example #4
Source File: StateInputStream.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private List<StreamHandler> collectStreamHanders(StateElement stateElement,
                                                 List<StreamHandler> streamHandlers) {
    if (stateElement instanceof LogicalStateElement) {
        collectStreamHanders(((LogicalStateElement) stateElement).getStreamStateElement1(), streamHandlers);
        collectStreamHanders(((LogicalStateElement) stateElement).getStreamStateElement2(), streamHandlers);
    } else if (stateElement instanceof CountStateElement) {
        collectStreamHanders(((CountStateElement) stateElement).getStreamStateElement(), streamHandlers);
    } else if (stateElement instanceof EveryStateElement) {
        collectStreamHanders(((EveryStateElement) stateElement).getStateElement(), streamHandlers);
    } else if (stateElement instanceof NextStateElement) {
        collectStreamHanders(((NextStateElement) stateElement).getStateElement(), streamHandlers);
        collectStreamHanders(((NextStateElement) stateElement).getNextStateElement(), streamHandlers);
    } else if (stateElement instanceof StreamStateElement) {
        BasicSingleInputStream basicSingleInputStream = ((StreamStateElement) stateElement)
                .getBasicSingleInputStream();
        streamHandlers.addAll(basicSingleInputStream.getStreamHandlers());
    }
    return streamHandlers;
}
 
Example #5
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
     * {@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, source.isFaultStream);

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

    }
 
Example #6
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
     * {@inheritDoc}
     * <p>The default implementation returns the result of calling
     * {@link #visitChildren} on {@code ctx}.</p>
     *
     * @param ctx
     */
    @Override
    public Object visitJoin_source(@NotNull SiddhiQLParser.Join_sourceContext ctx) {

//        join_source
//        :io (basic_source_stream_handler)* window? (AS alias)?
//        ;

        Source source = (Source) visit(ctx.source());

        String streamAlias = null;
        if (ctx.alias() != null) {
            streamAlias = (String) visit(ctx.alias());
            activeStreams.remove(ctx.source().getText());
            activeStreams.add(streamAlias);
        }
        BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(streamAlias, source.streamId,
                source.isInnerStream, source.isFaultStream);

        if (ctx.basic_source_stream_handlers() != null) {
            basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.basic_source_stream_handlers()));
        }

        if (ctx.window() != null) {
            SingleInputStream inputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window()));
            populateQueryContext(inputStream, ctx);
            return inputStream;
        } else {
            populateQueryContext(basicSingleInputStream, ctx);
            return basicSingleInputStream;
        }
    }
 
Example #7
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public List<StreamHandler> visitBasic_source_stream_handlers(
        @NotNull SiddhiQLParser.Basic_source_stream_handlersContext ctx) {
    List<StreamHandler> streamHandlers = new ArrayList<StreamHandler>();
    for (SiddhiQLParser.Basic_source_stream_handlerContext handlerContext : ctx.basic_source_stream_handler()) {
        streamHandlers.add((StreamHandler) visit(handlerContext));
    }
    return streamHandlers;
}
 
Example #8
Source File: BasicSingleInputStream.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public List<StreamHandler> getStreamHandlers() {
    return streamHandlers;
}
 
Example #9
Source File: BasicSingleInputStream.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public void addStreamHandlers(List<StreamHandler> streamHandlers) {
    this.streamHandlers = streamHandlers;
}
 
Example #10
Source File: SingleInputStream.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public List<StreamHandler> getStreamHandlers() {
    return streamHandlers;
}
 
Example #11
Source File: SingleInputStream.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public void addStreamHandlers(List<StreamHandler> streamHandlers) {
    this.streamHandlers.addAll(streamHandlers);
}
 
Example #12
Source File: StateInputStream.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public List<StreamHandler> getStreamHandlers() {
    return streamHandlers;
}
 
Example #13
Source File: SingleInputStreamParser.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent,
                                          List<VariableExpressionExecutor> variableExpressionExecutors,
                                          Map<String, Table> tableMap,
                                          boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents,
                                          boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
    Expression[] parameters = streamHandler.getParameters();
    MetaStreamEvent metaStreamEvent;
    int stateIndex = SiddhiConstants.UNKNOWN_STATE;
    if (metaEvent instanceof MetaStateEvent) {
        stateIndex = ((MetaStateEvent) metaEvent).getStreamEventCount() - 1;
        metaStreamEvent = ((MetaStateEvent) metaEvent).getMetaStreamEvent(stateIndex);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaEvent;
    }

    if (streamHandler instanceof Window) {
        metaStreamEvent.initializeOnAfterWindowData();
    }

    ExpressionExecutor[] attributeExpressionExecutors;
    if (parameters != null) {
        if (parameters.length > 0) {
            attributeExpressionExecutors = new ExpressionExecutor[parameters.length];
            for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) {
                attributeExpressionExecutors[i] = ExpressionParser.parseExpression(parameters[i], metaEvent,
                        stateIndex, tableMap, variableExpressionExecutors, false,
                        SiddhiConstants.CURRENT, ProcessingMode.BATCH, false,
                        siddhiQueryContext);
            }
        } else {
            List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
            int parameterSize = attributeList.size();
            attributeExpressionExecutors = new ExpressionExecutor[parameterSize];
            for (int i = 0; i < parameterSize; i++) {
                attributeExpressionExecutors[i] = ExpressionParser.parseExpression(new Variable(attributeList.get
                                (i).getName()), metaEvent, stateIndex, tableMap, variableExpressionExecutors,
                        false, SiddhiConstants.CURRENT, ProcessingMode.BATCH,
                        false, siddhiQueryContext);
            }
        }
    } else {
        attributeExpressionExecutors = new ExpressionExecutor[0];
    }

    ConfigReader configReader;
    if (streamHandler instanceof Filter) {
        return new FilterProcessor(attributeExpressionExecutors[0]);

    } else if (streamHandler instanceof Window) {
        WindowProcessor windowProcessor = (WindowProcessor) SiddhiClassLoader.loadExtensionImplementation(
                (Extension) streamHandler,
                WindowProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
        configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().
                generateConfigReader(((Window) streamHandler).getNamespace(),
                        ((Window) streamHandler).getName());
        windowProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors,
                configReader, outputExpectsExpiredEvents, findToBeExecuted, false, streamHandler, siddhiQueryContext);
        return windowProcessor;

    } else if (streamHandler instanceof StreamFunction) {
        AbstractStreamProcessor abstractStreamProcessor;
        configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().
                generateConfigReader(((StreamFunction) streamHandler).getNamespace(),
                        ((StreamFunction) streamHandler).getName());
        if (supportsBatchProcessing) {
            try {
                abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation(
                        (Extension) streamHandler,
                        StreamProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
                abstractStreamProcessor.initProcessor(metaStreamEvent,
                        attributeExpressionExecutors, configReader,
                        outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext);
                return abstractStreamProcessor;
            } catch (SiddhiAppCreationException e) {
                if (!e.isClassLoadingIssue()) {
                    ExceptionUtil.populateQueryContext(e, streamHandler, siddhiQueryContext.getSiddhiAppContext(),
                            siddhiQueryContext);
                    throw e;
                }
            }
        }
        abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation(
                (Extension) streamHandler,
                StreamFunctionProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
        abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors,
                configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext);
        return abstractStreamProcessor;
    } else {
        throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported",
                streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex());
    }
}