io.siddhi.query.api.execution.query.input.stream.SingleInputStream Java Examples

The following examples show how to use io.siddhi.query.api.execution.query.input.stream.SingleInputStream. 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: QueryRuntimeImpl.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public boolean isFromLocalStream() {
    if (query.getInputStream() instanceof SingleInputStream) {
        return ((SingleInputStream) query.getInputStream()).isInnerStream();
    } else if (query.getInputStream() instanceof JoinInputStream) {
        return ((SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream())
                .isInnerStream() || ((SingleInputStream) ((JoinInputStream) query.getInputStream())
                .getRightInputStream()).isInnerStream();
    } else if (query.getInputStream() instanceof StateInputStream) {
        for (String streamId : query.getInputStream().getAllStreamIds()) {
            if (streamId.startsWith("#")) {
                return true;
            }
        }
    }
    return false;
}
 
Example #4
Source File: StreamPartitioner.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private void createExecutors(InputStream inputStream, Partition partition, MetaComplexEvent metaEvent,
                             List<VariableExpressionExecutor> executors, SiddhiQueryContext siddhiQueryContext) {
    if (inputStream instanceof SingleInputStream) {
        if (metaEvent instanceof MetaStateEvent) {
            createSingleInputStreamExecutors((SingleInputStream) inputStream, partition,
                    ((MetaStateEvent) metaEvent).getMetaStreamEvent(0), executors, null,
                    siddhiQueryContext);
        } else {
            createSingleInputStreamExecutors((SingleInputStream) inputStream, partition, (MetaStreamEvent)
                    metaEvent, executors, null, siddhiQueryContext);
        }
    } else if (inputStream instanceof JoinInputStream) {
        createJoinInputStreamExecutors((JoinInputStream) inputStream, partition, (MetaStateEvent) metaEvent,
                executors, siddhiQueryContext);
    } else if (inputStream instanceof StateInputStream) {
        createStateInputStreamExecutors(((StateInputStream) inputStream).getStateElement(), partition,
                (MetaStateEvent) metaEvent, executors, 0, siddhiQueryContext);
    }
}
 
Example #5
Source File: PartitionRuntimeImpl.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public void addPartitionReceiver(QueryRuntimeImpl queryRuntime, List<VariableExpressionExecutor> executors,
                                 MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(),
            partition, metaEvent, executors, queryRuntime.getSiddhiQueryContext()).getPartitionExecutorLists();
    if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
        SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent
                .getMetaStreamEvent(0), partitionExecutors.get(0));
    } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
        SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream())
                .getLeftInputStream();
        addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(),
                metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
        SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream())
                .getRightInputStream();
        addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(),
                metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
    } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
        StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
        addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
    }
}
 
Example #6
Source File: SiddhiExecutionPlanner.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
private String retrieveStreamId(Variable variable, Map<String, SingleInputStream> aliasMap) throws Exception {
    Preconditions.checkNotNull(variable.getStreamId(), "streamId");
    if (inputStreams.containsKey(variable.getStreamId()) && aliasMap.containsKey(variable.getStreamId())) {
        throw new Exception("Duplicated streamId and alias: " + variable.getStreamId());
    } else if (inputStreams.containsKey(variable.getStreamId())) {
        return variable.getStreamId();
    } else if (aliasMap.containsKey(variable.getStreamId())) {
        return aliasMap.get(variable.getStreamId()).getStreamId();
    } else {
        throw new Exception(variable.getStreamId() + " does not exist!");
    }
}
 
Example #7
Source File: SiddhiExecutionPlanner.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
private void retrieveAliasForQuery(SingleInputStream inputStream, Map<String, SingleInputStream> aliasStreamMapping) throws Exception {
    if (inputStream.getStreamReferenceId() != null) {
        if (aliasStreamMapping.containsKey(inputStream.getStreamReferenceId())) {
            throw new Exception("Duplicated stream alias " + inputStream.getStreamId() + " -> " + inputStream);
        } else {
            aliasStreamMapping.put(inputStream.getStreamReferenceId(), inputStream);
        }
    }
}
 
Example #8
Source File: PolicyExecutionPlannerImpl.java    From eagle with Apache License 2.0 5 votes vote down vote up
private String retrieveStreamId(Variable variable, Map<String, List<StreamColumn>> streamMap, Map<String, SingleInputStream> aliasMap) {
    Preconditions.checkNotNull(variable.getStreamId(), "streamId");
    if (streamMap.containsKey(variable.getStreamId()) && aliasMap.containsKey(variable.getStreamId())) {
        throw new DuplicateDefinitionException("Duplicated streamId and alias: " + variable.getStreamId(),
                variable.getQueryContextStartIndex(), variable.getQueryContextEndIndex());
    } else if (streamMap.containsKey(variable.getStreamId())) {
        return variable.getStreamId();
    } else if (aliasMap.containsKey(variable.getStreamId())) {
        return aliasMap.get(variable.getStreamId()).getStreamId();
    } else {
        throw new DefinitionNotExistException(variable.getStreamId());
    }
}
 
Example #9
Source File: PolicyExecutionPlannerImpl.java    From eagle with Apache License 2.0 5 votes vote down vote up
private void retrieveAliasForQuery(SingleInputStream inputStream, Map<String, SingleInputStream> aliasStreamMapping) {
    if (inputStream.getStreamReferenceId() != null) {
        if (aliasStreamMapping.containsKey(inputStream.getStreamReferenceId())) {
            throw new SiddhiAppValidationException("Duplicated stream alias " + inputStream.getStreamId() + " -> " + inputStream);
        } else {
            aliasStreamMapping.put(inputStream.getStreamReferenceId(), inputStream);
        }
    }
}
 
Example #10
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 #11
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 #12
Source File: StreamPartitioner.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private void createSingleInputStreamExecutors(SingleInputStream inputStream, Partition partition,
                                              MetaStreamEvent metaEvent,
                                              List<VariableExpressionExecutor> executors,
                                              Map<String, Table> tableMap,
                                              SiddhiQueryContext siddhiQueryContext) {
    List<PartitionExecutor> executorList = new ArrayList<PartitionExecutor>();
    partitionExecutorLists.add(executorList);
    if (!inputStream.isInnerStream()) {
        for (PartitionType partitionType : partition.getPartitionTypeMap().values()) {
            if (partitionType instanceof ValuePartitionType) {
                if (partitionType.getStreamId().equals(inputStream.getStreamId())) {
                    executorList.add(new ValuePartitionExecutor(ExpressionParser.parseExpression((
                                    (ValuePartitionType) partitionType).getExpression(),
                            metaEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, executors,
                            false, 0,
                            ProcessingMode.BATCH, false, siddhiQueryContext)));
                }
            } else {
                for (RangePartitionType.RangePartitionProperty rangePartitionProperty : ((RangePartitionType)
                        partitionType).getRangePartitionProperties()) {
                    if (partitionType.getStreamId().equals(inputStream.getStreamId())) {
                        executorList.add(new RangePartitionExecutor((ConditionExpressionExecutor)
                                ExpressionParser.parseExpression(rangePartitionProperty.getCondition(), metaEvent,
                                        SiddhiConstants.UNKNOWN_STATE, tableMap, executors,
                                        false, 0, ProcessingMode.BATCH,
                                        false, siddhiQueryContext),
                                rangePartitionProperty.getPartitionKey()));
                    }
                }
            }
        }
    }
}
 
Example #13
Source File: PartitionRuntimeImpl.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private int addPartitionReceiverForStateElement(StateElement stateElement, MetaStateEvent metaEvent,
                                                List<List<PartitionExecutor>> partitionExecutors,
                                                int executorIndex) {
    if (stateElement instanceof EveryStateElement) {
        return addPartitionReceiverForStateElement(((EveryStateElement) stateElement).getStateElement(),
                metaEvent, partitionExecutors, executorIndex);
    } else if (stateElement instanceof NextStateElement) {
        executorIndex = addPartitionReceiverForStateElement(((NextStateElement) stateElement).getStateElement(),
                metaEvent, partitionExecutors, executorIndex);
        return addPartitionReceiverForStateElement(((NextStateElement) stateElement).getNextStateElement(),
                metaEvent, partitionExecutors, executorIndex);
    } else if (stateElement instanceof CountStateElement) {
        return addPartitionReceiverForStateElement(((CountStateElement) stateElement).getStreamStateElement(),
                metaEvent, partitionExecutors, executorIndex);
    } else if (stateElement instanceof LogicalStateElement) {
        executorIndex = addPartitionReceiverForStateElement(((LogicalStateElement) stateElement)
                        .getStreamStateElement1(), metaEvent,
                partitionExecutors, executorIndex);
        return addPartitionReceiverForStateElement(((LogicalStateElement) stateElement).getStreamStateElement2(),
                metaEvent, partitionExecutors, executorIndex);
    } else {  //if stateElement is an instanceof StreamStateElement
        SingleInputStream singleInputStream = ((StreamStateElement) stateElement).getBasicSingleInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent
                .getMetaStreamEvent(executorIndex), partitionExecutors.get(executorIndex));
        return ++executorIndex;
    }
}
 
Example #14
Source File: InputStreamParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an InputStream returning corresponding StreamRuntime
 *
 * @param inputStream                input stream to be parsed
 * @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 outputExpectsExpiredEvents is expired events sent as output
 * @param siddhiQueryContext         Siddhi query context.
 * @return StreamRuntime
 */
public static StreamRuntime parse(InputStream inputStream, Query query,
                                  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,
                                  boolean outputExpectsExpiredEvents,
                                  SiddhiQueryContext siddhiQueryContext) {

    if (inputStream instanceof BasicSingleInputStream || inputStream instanceof SingleInputStream) {
        SingleInputStream singleInputStream = (SingleInputStream) inputStream;
        ProcessStreamReceiver processStreamReceiver = new ProcessStreamReceiver(singleInputStream.getStreamId(),
                siddhiQueryContext);
        return SingleInputStreamParser.parseInputStream((SingleInputStream) inputStream,
                executors, streamDefinitionMap,
                tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap,
                new MetaStreamEvent(), processStreamReceiver, true,
                outputExpectsExpiredEvents, false, false, siddhiQueryContext);
    } else if (inputStream instanceof JoinInputStream) {
        return JoinInputStreamParser.parseInputStream(((JoinInputStream) inputStream),
                query, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap,
                aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors,
                outputExpectsExpiredEvents, siddhiQueryContext);
    } else if (inputStream instanceof StateInputStream) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(inputStream.getAllStreamIds().size());
        return StateInputStreamParser.parseInputStream(((StateInputStream) inputStream),
                metaStateEvent, streamDefinitionMap, tableDefinitionMap,
                windowDefinitionMap, aggregationDefinitionMap, tableMap, executors,
                siddhiQueryContext);
    } else {
        throw new OperationNotSupportedException();
    }
}