io.siddhi.query.api.definition.AbstractDefinition Java Examples

The following examples show how to use io.siddhi.query.api.definition.AbstractDefinition. 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: AttributeStreamFunction.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(AbstractDefinition inputDefinition,
                            ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 1) {
        throw new SiddhiAppCreationException("Only one attribute is expected but found " +
                attributeExpressionExecutors.length);
    }
    if (!(attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor)) {
        throw new SiddhiAppCreationException("Attribute is expected to be constant, but its not!");
    }
    newAttributes = new ArrayList<>();
    newAttributes.add(
            new Attribute(((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue().toString(),
                    inputDefinition.getAttributeList().get(0).getType()));
    return null;
}
 
Example #2
Source File: MetaStreamEvent.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public MetaStreamEvent clone() {
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    if (outputData != null) {
        for (Attribute attribute : outputData) {
            metaStreamEvent.addOutputData(attribute);
        }
    }
    if (this.onAfterWindowData != null) {
        metaStreamEvent.onAfterWindowData = new ArrayList<>(onAfterWindowData);
    }
    metaStreamEvent.beforeWindowData = new ArrayList<>(beforeWindowData);

    for (AbstractDefinition abstractDefinition : this.getInputDefinitions()) {
        metaStreamEvent.addInputDefinition(abstractDefinition);
    }
    metaStreamEvent.setInputReferenceId(this.getInputReferenceId());
    metaStreamEvent.setOutputDefinition(this.getOutputStreamDefinition());
    metaStreamEvent.setEventType(this.getEventType());
    metaStreamEvent.setMultiValue(this.isMultiValue());
    return metaStreamEvent;
}
 
Example #3
Source File: ExpressionWindowProcessor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(MetaStreamEvent metaStreamEvent,
                            AbstractDefinition inputDefinition,
                            ExpressionExecutor[] attributeExpressionExecutors,
                            ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder,
                            boolean outputExpectsExpiredEvents, boolean findToBeExecuted,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
        expressionString = (String) ((ConstantExpressionExecutor)
                attributeExpressionExecutors[0]).getValue();
        constructExpression(metaStreamEvent, siddhiQueryContext);
    } else {
        for (Attribute attribute : inputDefinition.getAttributeList()) {
            metaStreamEvent.addData(attribute);
        }
        expressionStringExecutor = attributeExpressionExecutors[0];
    }
    return () -> new WindowState();
}
 
Example #4
Source File: AbstractSiddhiOperator.java    From flink-siddhi with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void registerInputAndOutput() {
    Map<String, StreamDefinition> streamDefinitionMap = siddhiRuntime.getStreamDefinitionMap();

    for (String outputStreamId : siddhiPlan.getOutputStreamTypes().keySet()) {
        AbstractDefinition definition = this.siddhiRuntime.getStreamDefinitionMap().get(outputStreamId);
        if (streamDefinitionMap.containsKey(outputStreamId)) {
            siddhiRuntime.addCallback(outputStreamId,
                new StreamOutputHandler<>(outputStreamId, siddhiPlan.getOutputStreamType(outputStreamId), definition, output));
        }
    }

    for (String inputStreamId : siddhiPlan.getInputStreams()) {
        if (streamDefinitionMap.containsKey(inputStreamId)) {
            inputStreamHandlers.put(inputStreamId, siddhiRuntime.getInputHandler(inputStreamId));
        }
    }
}
 
Example #5
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static void validateDefinition(AbstractDefinition definition,
                                      ConcurrentMap<String, AbstractDefinition> streamDefinitionMap,
                                      ConcurrentMap<String, AbstractDefinition> tableDefinitionMap,
                                      ConcurrentMap<String, AbstractDefinition> windowDefinitionMap,
                                      ConcurrentMap<String, AbstractDefinition> aggregationDefinitionMap) {
    AbstractDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId());
    if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof
            StreamDefinition)) {
        throw new DuplicateDefinitionException("Table Definition with same Stream Id '" +
                definition.getId() + "' already exist : " + existingTableDefinition +
                ", hence cannot add " + definition, definition.getQueryContextStartIndex(),
                definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId());
    if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition
            instanceof TableDefinition)) {
        throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" +
                definition.getId() + "' already exist : " + existingStreamDefinition +
                ", hence cannot add " + definition, definition.getQueryContextStartIndex(),
                definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
    if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition
            instanceof WindowDefinition)) {
        throw new DuplicateDefinitionException("Window Definition with same Window Id '" +
                definition.getId() + "' already exist : " + existingWindowDefinition +
                ", hence cannot add " + definition, definition.getQueryContextStartIndex(),
                definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
    if (existingAggregationDefinition != null
            && (!existingAggregationDefinition.equals(definition)
            || definition instanceof AggregationDefinition)) {
        throw new DuplicateDefinitionException(
                "Aggregation Definition with same Aggregation Id '" + definition.getId() + "' already exist : "
                        + existingWindowDefinition + ", hence cannot add " + definition,
                definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
}
 
Example #6
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnnotatingStreamDefinition2() {
    Annotation annotation = AbstractDefinition.annotation("distribute");

    StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol",
            Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type
            .FLOAT).annotation(annotation.element("true"));

    String annotationString = "[@distribute( \"true\")]";

    SiddhiApp.siddhiApp("Test").defineStream(streamDefinition);

    AssertJUnit.assertEquals(annotationString, streamDefinition.getAnnotations().toString());
}
 
Example #7
Source File: PartitionParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static void validateStreamPartitions(Map<String, PartitionType> partitionTypeMap,
                                             ConcurrentMap<String, AbstractDefinition> streamDefinitionMap,
                                             ConcurrentMap<String, AbstractDefinition> windowDefinitionMap) {
    for (Map.Entry<String, PartitionType> entry : partitionTypeMap.entrySet()) {
        if ((!streamDefinitionMap.containsKey(entry.getKey())) &&
                (!windowDefinitionMap.containsKey(entry.getKey()))) {
            throw new SiddhiAppCreationException("Stream/window with name '" + entry.getKey() +
                    "' is not defined!",
                    entry.getValue().getQueryContextStartIndex(),
                    entry.getValue().getQueryContextEndIndex());
        }
    }
}
 
Example #8
Source File: PartitionParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static PartitionRuntimeImpl parse(SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder, Partition partition,
                                         SiddhiAppContext siddhiAppContext, int queryIndex, int partitionIndex) {
    ConcurrentMap<String, AbstractDefinition> streamDefinitionMap =
            siddhiAppRuntimeBuilder.getStreamDefinitionMap();
    ConcurrentMap<String, AbstractDefinition> windowDefinitionMap =
            siddhiAppRuntimeBuilder.getWindowDefinitionMap();
    validateStreamPartitions(partition.getPartitionTypeMap(), streamDefinitionMap, windowDefinitionMap);
    PartitionRuntimeImpl partitionRuntime = new PartitionRuntimeImpl(streamDefinitionMap, windowDefinitionMap,
            siddhiAppRuntimeBuilder.getStreamJunctions(), partition, partitionIndex, siddhiAppContext);
    for (Query query : partition.getQueryList()) {
        List<VariableExpressionExecutor> executors = new ArrayList<VariableExpressionExecutor>();
        ConcurrentMap<String, AbstractDefinition> combinedStreamMap =
                new ConcurrentHashMap<String, AbstractDefinition>();
        combinedStreamMap.putAll(streamDefinitionMap);
        combinedStreamMap.putAll(windowDefinitionMap);
        combinedStreamMap.putAll(partitionRuntime.getLocalStreamDefinitionMap());
        QueryRuntimeImpl queryRuntime = QueryParser.parse(query, siddhiAppContext, combinedStreamMap,
                siddhiAppRuntimeBuilder.getTableDefinitionMap(),
                siddhiAppRuntimeBuilder.getWindowDefinitionMap(),
                siddhiAppRuntimeBuilder.getAggregationDefinitionMap(),
                siddhiAppRuntimeBuilder.getTableMap(),
                siddhiAppRuntimeBuilder.getAggregationMap(),
                siddhiAppRuntimeBuilder.getWindowMap(),
                siddhiAppRuntimeBuilder.getLockSynchronizer(),
                String.valueOf(queryIndex), true, partitionRuntime.getPartitionName());
        queryIndex++;
        MetaStateEvent metaStateEvent = createMetaEventForPartitioner(queryRuntime.getMetaComplexEvent());
        partitionRuntime.addQuery(queryRuntime);
        partitionRuntime.addPartitionReceiver(queryRuntime, executors, metaStateEvent);
        QueryParserHelper.reduceMetaComplexEvent(metaStateEvent);
        if (queryRuntime.getMetaComplexEvent() instanceof MetaStateEvent) {
            QueryParserHelper.updateVariablePosition(metaStateEvent, executors);
        } else {
            QueryParserHelper.updateVariablePosition(metaStateEvent.getMetaStreamEvent(0), executors);
        }
    }
    partitionRuntime.init();
    return partitionRuntime;

}
 
Example #9
Source File: IndexEventHolderForCache.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public IndexEventHolderForCache(StreamEventFactory tableStreamEventFactory, StreamEventConverter eventConverter,
                                PrimaryKeyReferenceHolder[] primaryKeyReferenceHolders, boolean isPrimaryNumeric,
                                Map<String, Integer> indexMetaData, AbstractDefinition tableDefinition,
                                SiddhiAppContext siddhiAppContext) {
    super(tableStreamEventFactory, eventConverter, primaryKeyReferenceHolders, isPrimaryNumeric, indexMetaData,
            tableDefinition, siddhiAppContext);
}
 
Example #10
Source File: StreamInMemOutputHandler.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public StreamInMemOutputHandler(TypeInformation<R> typeInfo, AbstractDefinition definition) {
    this.typeInfo = typeInfo;
    this.definition = definition;
    this.objectMapper = new ObjectMapper();
    this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    this.collectedRecords = new LinkedList<>();
}
 
Example #11
Source File: SiddhiDefinitionAdapter.java    From eagle with Apache License 2.0 5 votes vote down vote up
public static StreamDefinition convertFromSiddiDefinition(AbstractDefinition siddhiDefinition) {
    StreamDefinition streamDefinition = new StreamDefinition();
    streamDefinition.setStreamId(siddhiDefinition.getId());
    List<StreamColumn> columns = new ArrayList<>(siddhiDefinition.getAttributeNameArray().length);
    for (Attribute attribute : siddhiDefinition.getAttributeList()) {
        StreamColumn column = new StreamColumn();
        column.setType(convertFromSiddhiAttributeType(attribute.getType()));
        column.setName(attribute.getName());
        columns.add(column);
    }
    streamDefinition.setColumns(columns);
    streamDefinition.setTimeseries(true);
    streamDefinition.setDescription("Auto-generated stream schema from siddhi for " + siddhiDefinition.getId());
    return streamDefinition;
}
 
Example #12
Source File: AggregationRuntime.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static void initMetaStreamEvent(MetaStreamEvent metaStreamEvent, AbstractDefinition inputDefinition,
                                        String inputReferenceId) {
    metaStreamEvent.addInputDefinition(inputDefinition);
    metaStreamEvent.setInputReferenceId(inputReferenceId);
    metaStreamEvent.initializeOnAfterWindowData();
    inputDefinition.getAttributeList().forEach(metaStreamEvent::addData);
}
 
Example #13
Source File: SiddhiTypeFactory.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public static <T extends Tuple> TypeInformation<T> getTupleTypeInformation(AbstractDefinition definition) {
    List<TypeInformation> types = new ArrayList<>();
    for (Attribute attribute : definition.getAttributeList()) {
        types.add(TypeInformation.of(getJavaType(attribute.getType())));
    }
    try {
        return Types.TUPLE(types.toArray(new TypeInformation[0]));
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException("Unable to parse ", ex);
    }
}
 
Example #14
Source File: SiddhiAppRuntimeImpl.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public Map<String, Map<String, AbstractDefinition>> getPartitionedInnerStreamDefinitionMap() {
    Map<String, Map<String, AbstractDefinition>> innerStreams = new HashMap<>();
    for (PartitionRuntime partition : partitionMap.values()) {
        innerStreams.put(partition.getPartitionName(), partition.getLocalStreamDefinitionMap());
    }
    return innerStreams;
}
 
Example #15
Source File: GroupingWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<S> init(MetaStreamEvent metaStreamEvent, AbstractDefinition inputDefinition,
                               ExpressionExecutor[] attributeExpressionExecutors,
                               ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder,
                               boolean outputExpectsExpiredEvents, boolean findToBeExecuted,
                               SiddhiQueryContext siddhiQueryContext) {
    StateFactory<S> stateFactory = init(attributeExpressionExecutors, configReader, outputExpectsExpiredEvents,
            siddhiQueryContext);
    Attribute groupingKey = new Attribute("_groupingKey", Attribute.Type.STRING);
    internalAttributes = new ArrayList<Attribute>(1);
    internalAttributes.add(groupingKey);
    metaStreamEvent.addData(groupingKey);
    return stateFactory;
}
 
Example #16
Source File: SlidingWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<S> init(MetaStreamEvent metaStreamEvent,
                               AbstractDefinition inputDefinition,
                               ExpressionExecutor[] attributeExpressionExecutors,
                               ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder,
                               boolean outputExpectsExpiredEvents, boolean findToBeExecuted,
                               SiddhiQueryContext siddhiQueryContext) {
    return init(attributeExpressionExecutors, configReader, siddhiQueryContext);
}
 
Example #17
Source File: HopingWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<S> init(MetaStreamEvent metaStreamEvent, AbstractDefinition inputDefinition,
                               ExpressionExecutor[] attributeExpressionExecutors,
                               ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder,
                               boolean outputExpectsExpiredEvents, boolean findToBeExecuted,
                               SiddhiQueryContext siddhiQueryContext) {
    StateFactory<S> stateFactory = init(attributeExpressionExecutors, configReader, outputExpectsExpiredEvents,
            siddhiQueryContext);
    Attribute groupingKey = new Attribute("_hopingTimestamp", Attribute.Type.STRING);
    internalAttributes = new ArrayList<Attribute>(1);
    internalAttributes.add(groupingKey);
    metaStreamEvent.addData(groupingKey);
    return stateFactory;
}
 
Example #18
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static void validateOutputStream(StreamDefinition outputStreamDefinition,
                                        AbstractDefinition existingStream) {
    if (!existingStream.equalsIgnoreAnnotations(outputStreamDefinition)) {
        throw new DuplicateDefinitionException("Different definition same as output '" +
                outputStreamDefinition + "' already exist as '" + existingStream + "'",
                outputStreamDefinition.getQueryContextStartIndex(),
                outputStreamDefinition.getQueryContextEndIndex());
    }
}
 
Example #19
Source File: JoinInputStreamParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static void setEventType(Map<String, AbstractDefinition> streamDefinitionMap,
                                 Map<String, AbstractDefinition> tableDefinitionMap,
                                 Map<String, AbstractDefinition> windowDefinitionMap,
                                 Map<String, AbstractDefinition> aggregationDefinitionMap,
                                 MetaStreamEvent metaStreamEvent, String inputStreamId) {
    if (windowDefinitionMap.containsKey(inputStreamId)) {
        metaStreamEvent.setEventType(WINDOW);
    } else if (tableDefinitionMap.containsKey(inputStreamId)) {
        metaStreamEvent.setEventType(TABLE);
    } else if (aggregationDefinitionMap.containsKey(inputStreamId)) {
        metaStreamEvent.setEventType(AGGREGATE);
    } else if (!streamDefinitionMap.containsKey(inputStreamId)) {
        throw new SiddhiParserException("Definition of \"" + inputStreamId + "\" is not given");
    }
}
 
Example #20
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();
    }
}
 
Example #21
Source File: OnDemandQueryParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static MatchingMetaInfoHolder generateMatchingMetaInfoHolder(MetaStreamEvent metaStreamEvent,
                                                                     AbstractDefinition definition) {
    MetaStateEvent metaStateEvent = new MetaStateEvent(1);
    metaStateEvent.addEvent(metaStreamEvent);
    return new MatchingMetaInfoHolder(metaStateEvent, -1, 0, definition,
            definition, 0);
}
 
Example #22
Source File: OnDemandQueryParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static AbstractDefinition generateTableDefinitionFromOnDemandQuery(OnDemandQuery onDemandQuery,
                                                                           List<Attribute> expectedOutputAttributes) {
    TableDefinition tableDefinition = TableDefinition.id(onDemandQuery.getInputStore().getStoreId());
    for (Attribute attribute : expectedOutputAttributes) {
        tableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    return tableDefinition;
}
 
Example #23
Source File: OnDemandQueryParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static MatchingMetaInfoHolder generateMatchingMetaInfoHolder(MetaStreamEvent metaStreamEvent,
                                                                     AbstractDefinition streamDefinition,
                                                                     AbstractDefinition storeDefinition) {
    MetaStateEvent metaStateEvent = new MetaStateEvent(1);
    metaStateEvent.addEvent(metaStreamEvent);
    return new MatchingMetaInfoHolder(metaStateEvent, -1, 0, streamDefinition,
            storeDefinition, 0);
}
 
Example #24
Source File: OnDemandQueryParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static AbstractDefinition getInputDefinition(OnDemandQuery onDemandQuery, Table table) {
    if (onDemandQuery.getSelector().getSelectionList().isEmpty()) {
        return table.getTableDefinition();
    } else {
        StreamDefinition streamDefinition = new StreamDefinition();
        streamDefinition.setId(table.getTableDefinition().getId() + "InputStream");
        return streamDefinition;
    }
}
 
Example #25
Source File: SiddhiAppRuntimeBuilder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public void defineTable(TableDefinition tableDefinition) {
    DefinitionParserHelper.validateDefinition(tableDefinition, streamDefinitionMap, tableDefinitionMap,
            windowDefinitionMap, aggregationDefinitionMap);
    AbstractDefinition currentDefinition = tableDefinitionMap.putIfAbsent(tableDefinition.getId(), tableDefinition);
    if (currentDefinition != null) {
        tableDefinition = (TableDefinition) currentDefinition;
    }
    DefinitionParserHelper.addTable(tableDefinition, tableMap, siddhiAppContext);
}
 
Example #26
Source File: SiddhiAppRuntimeBuilder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public void defineWindow(WindowDefinition windowDefinition) {
    DefinitionParserHelper.validateDefinition(windowDefinition, streamDefinitionMap, tableDefinitionMap,
            windowDefinitionMap, aggregationDefinitionMap);
    DefinitionParserHelper.addStreamJunction(windowDefinition, streamJunctionMap, siddhiAppContext);
    AbstractDefinition currentDefinition = windowDefinitionMap
            .putIfAbsent(windowDefinition.getId(), windowDefinition);
    if (currentDefinition != null) {
        windowDefinition = (WindowDefinition) currentDefinition;
    }
    DefinitionParserHelper.addWindow(windowDefinition, windowMap, siddhiAppContext);
}
 
Example #27
Source File: MatchingMetaInfoHolder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public MatchingMetaInfoHolder(MetaStateEvent metaStateEvent, int matchingStreamEventIndex, int storeEventIndex,
                              AbstractDefinition matchingStreamDefinition, AbstractDefinition storeDefinition,
                              int currentState) {
    this.metaStateEvent = metaStateEvent;
    this.matchingStreamEventIndex = matchingStreamEventIndex;
    this.storeEventIndex = storeEventIndex;
    this.matchingStreamDefinition = matchingStreamDefinition;
    this.storeDefinition = storeDefinition;
    this.currentState = currentState;
}
 
Example #28
Source File: EventTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryParser() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT);
    Query query = new Query();
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.NOT_EQUAL, Expression.value(50))));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")));
    query.insertInto("outputStream");
    Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
    Map<String, Table> tableMap = new HashMap<String, Table>();
    Map<String, Window> eventWindowMap = new HashMap<String, Window>();
    Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
    Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
    Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
    Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
    LockSynchronizer lockSynchronizer = new LockSynchronizer();
    streamDefinitionMap.put("cseEventStream", streamDefinition);
    streamDefinitionMap.put("outputStream", outStreamDefinition);
    SiddhiContext siddhicontext = new SiddhiContext();
    SiddhiAppContext context = new SiddhiAppContext();
    context.setSiddhiContext(siddhicontext);
    context.setIdGenerator(new IdGenerator());
    context.setSnapshotService(new SnapshotService(context));
    QueryRuntimeImpl runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap,
            windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap,
            lockSynchronizer, "1", false, SiddhiConstants.PARTITION_ID_DEFAULT);
    AssertJUnit.assertNotNull(runtime);
    AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
    AssertJUnit.assertNotNull(runtime.getSelector());
    AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
 
Example #29
Source File: StreamOutputHandler.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public StreamOutputHandler(String outputStreamId, TypeInformation<R> typeInfo, AbstractDefinition definition, Output<StreamRecord<R>> output) {
    this.outputStreamId = outputStreamId;
    this.typeInfo = typeInfo;
    this.definition = definition;
    this.output = output;
    this.objectMapper = new ObjectMapper();
    this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
 
Example #30
Source File: StreamEventConverterFactory.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static List<StreamEventConverter.ConversionMapping> getConversionElements(
        MetaStreamEvent metaStreamEvent, int size) {

    AbstractDefinition inputDefinition = metaStreamEvent.getInputDefinitions().get(0);
    List<StreamEventConverter.ConversionMapping> conversionMappings = new ArrayList<StreamEventConverter
            .ConversionMapping>(size);

    for (int j = 0; j < 3; j++) {
        List<Attribute> currentDataList = null;
        if (j == 0) {
            currentDataList = metaStreamEvent.getBeforeWindowData();
        } else if (j == 1) {
            currentDataList = metaStreamEvent.getOnAfterWindowData();
        } else if (j == 2) {
            currentDataList = metaStreamEvent.getOutputData();
        }
        if (currentDataList != null) {
            int i = 0;
            for (Attribute attribute : currentDataList) {           //Only variable slots will be filled.
                if (attribute == null) {
                    i++;
                } else if (!inputDefinition.getAttributeList().contains(attribute)) {
                    i++;
                } else {
                    int fromPosition = inputDefinition.getAttributePosition(attribute.getName());
                    StreamEventConverter.ConversionMapping conversionMapping = new StreamEventConverter
                            .ConversionMapping();
                    conversionMapping.setFromPosition(fromPosition);
                    int[] toPosition = new int[2];
                    toPosition[0] = j;
                    toPosition[1] = i;
                    conversionMapping.setToPosition(toPosition);
                    conversionMappings.add(conversionMapping);
                    i++;
                }
            }
        }
    }
    return conversionMappings;
}