io.siddhi.query.api.definition.StreamDefinition Java Examples
The following examples show how to use
io.siddhi.query.api.definition.StreamDefinition.
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: JsonSinkMapper.java From siddhi-map-json with Apache License 2.0 | 6 votes |
/** * Initialize the mapper and the mapping configurations. * * @param streamDefinition The stream definition * @param optionHolder Option holder containing static and dynamic options * @param payloadTemplateBuilderMap Unmapped list of payloads for reference */ @Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, ConfigReader mapperConfigReader, SiddhiAppContext siddhiAppContext) { this.attributeNameArray = streamDefinition.getAttributeNameArray(); this.enclosingElement = optionHolder.validateAndGetStaticValue(ENCLOSING_ELEMENT_IDENTIFIER, null); this.isJsonValidationEnabled = Boolean.parseBoolean(optionHolder .validateAndGetStaticValue(JSON_VALIDATION_IDENTIFIER, "false")); //if @payload() is added there must be at least 1 element in it, otherwise a SiddhiParserException raised if (payloadTemplateBuilderMap != null && payloadTemplateBuilderMap.size() != 1) { throw new SiddhiAppCreationException("Json sink-mapper does not support multiple @payload mappings, " + "error at the mapper of '" + streamDefinition.getId() + "'"); } if (payloadTemplateBuilderMap != null && payloadTemplateBuilderMap.get(payloadTemplateBuilderMap.keySet().iterator().next()).isObjectMessage()) { throw new SiddhiAppCreationException("Json sink-mapper does not support object @payload mappings, " + "error at the mapper of '" + streamDefinition.getId() + "'"); } }
Example #2
Source File: OutputParser.java From siddhi with Apache License 2.0 | 6 votes |
public static OutputCallback constructOutputCallback(OutputStream outStream, String key, ConcurrentMap<String, StreamJunction> streamJunctionMap, StreamDefinition outputStreamDefinition, SiddhiQueryContext siddhiQueryContext) { String id = outStream.getId(); //Construct CallBack if (outStream instanceof InsertIntoStream) { StreamJunction outputStreamJunction = streamJunctionMap.get(id + key); if (outputStreamJunction == null) { outputStreamJunction = new StreamJunction(outputStreamDefinition, siddhiQueryContext.getSiddhiAppContext().getExecutorService(), siddhiQueryContext.getSiddhiAppContext().getBufferSize(), null, siddhiQueryContext.getSiddhiAppContext()); streamJunctionMap.putIfAbsent(id + key, outputStreamJunction); } InsertIntoStreamCallback insertIntoStreamCallback = new InsertIntoStreamCallback(outputStreamDefinition, siddhiQueryContext.getName()); insertIntoStreamCallback.init(streamJunctionMap.get(id + key)); return insertIntoStreamCallback; } else { throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex()); } }
Example #3
Source File: SiddhiAppParser.java From siddhi with Apache License 2.0 | 6 votes |
private static void defineStreamDefinitions(SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder, Map<String, StreamDefinition> streamDefinitionMap, SiddhiAppContext siddhiAppContext) { for (StreamDefinition definition : streamDefinitionMap.values()) { try { Annotation onErrorAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_ON_ERROR, definition.getAnnotations()); if (onErrorAnnotation != null) { StreamJunction.OnErrorAction onErrorAction = StreamJunction.OnErrorAction.valueOf(onErrorAnnotation .getElement(SiddhiConstants.ANNOTATION_ELEMENT_ACTION).toUpperCase()); if (onErrorAction == StreamJunction.OnErrorAction.STREAM) { StreamDefinition faultStreamDefinition = createFaultStreamDefinition(definition); siddhiAppRuntimeBuilder.defineStream(faultStreamDefinition); } } siddhiAppRuntimeBuilder.defineStream(definition); } catch (Throwable t) { ExceptionUtil.populateQueryContext(t, definition, siddhiAppContext); throw t; } } }
Example #4
Source File: AbstractSiddhiOperator.java From flink-siddhi with Apache License 2.0 | 6 votes |
@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: AggregationRuntime.java From siddhi with Apache License 2.0 | 6 votes |
private static MetaStreamEvent alterMetaStreamEvent(boolean isOnDemandQuery, MetaStreamEvent originalMetaStreamEvent, List<Attribute> additionalAttributes) { StreamDefinition alteredStreamDef = new StreamDefinition(); String inputReferenceId = originalMetaStreamEvent.getInputReferenceId(); if (!isOnDemandQuery) { for (Attribute attribute : originalMetaStreamEvent.getLastInputDefinition().getAttributeList()) { alteredStreamDef.attribute(attribute.getName(), attribute.getType()); } if (inputReferenceId == null) { alteredStreamDef.setId(originalMetaStreamEvent.getLastInputDefinition().getId()); } } else { // If it is on-demand query, no original join stream alteredStreamDef.setId("OnDemandQueryStream"); } additionalAttributes.forEach(attribute -> alteredStreamDef.attribute(attribute.getName(), attribute.getType())); initMetaStreamEvent(originalMetaStreamEvent, alteredStreamDef, inputReferenceId); return originalMetaStreamEvent; }
Example #6
Source File: DefineStreamTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testMultilevelNestedAnnotations3() throws SiddhiParserException { StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition( "@sink(url='http://foo.com/test/{{data}}', " + " @map(type=\"\"\"xml\"\"\", " + "@payload(\"\"\"{ \"time\":{{time}}}\"\"\") " + " )" + ") " + "define stream fooStream (id int, name string);" ); AssertJUnit.assertEquals( StreamDefinition .id("fooStream") .attribute("id", Attribute.Type.INT) .attribute("name", Attribute.Type.STRING) .annotation(Annotation.annotation("sink") .element("url", "http://foo.com/test/{{data}}") .annotation(Annotation.annotation("map") .element("type", "xml") .annotation(Annotation.annotation("payload") .element("{ \"time\":{{time}}}")))), streamDefinition); }
Example #7
Source File: DefinitionParserHelper.java From siddhi with Apache License 2.0 | 6 votes |
private static List<OptionHolder> createDestinationOptionHolders(Annotation distributionAnnotation, StreamDefinition streamDefinition, Sink clientTransport, SiddhiAppContext siddhiAppContext) { io.siddhi.annotation.Extension sinkExt = clientTransport.getClass().getAnnotation(io.siddhi.annotation.Extension.class); List<OptionHolder> destinationOptHolders = new ArrayList<>(); distributionAnnotation.getAnnotations().stream() .filter(annotation -> annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_DESTINATION)) .forEach(destinationAnnotation -> destinationOptHolders.add(constructOptionHolder(streamDefinition, updateAnnotationRef(destinationAnnotation, SiddhiConstants.ANNOTATION_DESTINATION, siddhiAppContext), sinkExt, clientTransport.getSupportedDynamicOptions(), true))); return destinationOptHolders; }
Example #8
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void testFilterQuery49() throws InterruptedException { log.info("Filter test49"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("available", Attribute.Type.BOOL); Query query = new Query(); query.from(InputStream.stream("cseEventStream"). filter(Expression.variable("price"))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("price", Expression.variable("price")). select("available", Expression.variable("available")) ); query.insertInto("StockQuote"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); }
Example #9
Source File: AggregationParser.java From siddhi with Apache License 2.0 | 5 votes |
private static HashMap<TimePeriod.Duration, Table> initDefaultTables( String aggregatorName, List<TimePeriod.Duration> durations, StreamDefinition streamDefinition, SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder, List<Annotation> annotations, List<Variable> groupByVariableList, boolean isProcessingOnExternalTime, boolean enablePartioning) { HashMap<TimePeriod.Duration, Table> aggregationTableMap = new HashMap<>(); // Create annotations for primary key Annotation primaryKeyAnnotation = new Annotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY); primaryKeyAnnotation.element(null, AGG_START_TIMESTAMP_COL); if (enablePartioning) { primaryKeyAnnotation.element(null, AGG_SHARD_ID_COL); } if (isProcessingOnExternalTime) { primaryKeyAnnotation.element(null, AGG_EXTERNAL_TIMESTAMP_COL); } for (Variable groupByVariable : groupByVariableList) { primaryKeyAnnotation.element(null, groupByVariable.getAttributeName()); } annotations.add(primaryKeyAnnotation); for (TimePeriod.Duration duration : durations) { String tableId = aggregatorName + "_" + duration.toString(); TableDefinition tableDefinition = TableDefinition.id(tableId); for (Attribute attribute : streamDefinition.getAttributeList()) { tableDefinition.attribute(attribute.getName(), attribute.getType()); } annotations.forEach(tableDefinition::annotation); siddhiAppRuntimeBuilder.defineTable(tableDefinition); aggregationTableMap.put(duration, siddhiAppRuntimeBuilder.getTableMap().get(tableId)); } return aggregationTableMap; }
Example #10
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery69() throws InterruptedException { log.info("Filter test69"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.LONG); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(50)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50d, 60L}); inputHandler.send(new Object[]{"WSO2", 70d, 40L}); inputHandler.send(new Object[]{"WSO2", 44d, 200L}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example #11
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery98() throws InterruptedException { log.info("Filter test98"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE) .attribute("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(60L)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("quantity", Expression.variable("quantity"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 500f, 50d, 6}); inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2}); inputHandler.send(new Object[]{"WSO2", 50f, 300d, 4}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); AssertJUnit.assertEquals(2, count.get()); siddhiAppRuntime.shutdown(); }
Example #12
Source File: SourceHandler.java From siddhi with Apache License 2.0 | 5 votes |
final void initSourceHandler(String siddhiAppName, SourceSyncCallback sourceSyncCallback, StreamDefinition streamDefinition, SiddhiAppContext siddhiAppContext) { StateFactory<S> stateFactory = init(siddhiAppName, sourceSyncCallback, streamDefinition, siddhiAppContext); id = siddhiAppName + "-" + streamDefinition.getId() + "-" + this.getClass().getName(); stateHolder = siddhiAppContext.generateStateHolder( streamDefinition.getId() + "-" + this.getClass().getName(), stateFactory); }
Example #13
Source File: EventTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testStreamEventConverter() { Attribute price = new Attribute("price", Attribute.Type.DOUBLE); Attribute volume = new Attribute("volume", Attribute.Type.INT); Attribute symbol = new Attribute("symbol", Attribute.Type.STRING); MetaStreamEvent metaStreamEvent = new MetaStreamEvent(); metaStreamEvent.addData(volume); metaStreamEvent.initializeOnAfterWindowData(); metaStreamEvent.addData(price); metaStreamEvent.addOutputData(symbol); metaStreamEvent.addOutputData(null); //complex attribute StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT); Event event = new Event(System.currentTimeMillis(), new Object[]{"WSO2", 200, 50}); metaStreamEvent.addInputDefinition(streamDefinition); StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent); StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent); StreamEvent newEvent = eventPool.newInstance(); converter.convertEvent(event, newEvent); AssertJUnit.assertTrue(converter instanceof SelectiveStreamEventConverter); AssertJUnit.assertEquals(1, newEvent.getBeforeWindowData().length); //volume AssertJUnit.assertEquals(1, newEvent.getOnAfterWindowData().length); //price AssertJUnit.assertEquals(2, newEvent.getOutputData().length); //symbol and avgPrice AssertJUnit.assertEquals(50, newEvent.getBeforeWindowData()[0]); AssertJUnit.assertEquals(200, newEvent.getOnAfterWindowData()[0]); AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]); }
Example #14
Source File: Source.java From siddhi with Apache License 2.0 | 5 votes |
public final void init(String sourceType, OptionHolder transportOptionHolder, SourceMapper sourceMapper, String[] transportPropertyNames, ConfigReader configReader, String mapType, OptionHolder mapOptionHolder, List<AttributeMapping> attributeMappings, List<AttributeMapping> transportMappings, ConfigReader mapperConfigReader, SourceHandler sourceHandler, StreamDefinition streamDefinition, Map<String, String> deploymentProperties, SiddhiAppContext siddhiAppContext) { this.type = sourceType; sourceMapper.init(streamDefinition, mapType, mapOptionHolder, attributeMappings, sourceType, (this instanceof SourceSyncCallback) ? (SourceSyncCallback) this : null, transportMappings, sourceHandler, transportOptionHolder, mapperConfigReader, siddhiAppContext); this.mapper = sourceMapper; this.streamDefinition = streamDefinition; this.siddhiAppContext = siddhiAppContext; StateFactory<S> stateFactory = init(sourceMapper, transportOptionHolder, transportPropertyNames, configReader, siddhiAppContext); stateHolder = siddhiAppContext.generateStateHolder(streamDefinition.getId() + "-" + this.getClass().getName(), stateFactory); scheduledExecutorService = siddhiAppContext.getScheduledExecutorService(); serviceDeploymentInfo = exposeServiceDeploymentInfo(); if (serviceDeploymentInfo != null) { serviceDeploymentInfo.addDeploymentProperties(deploymentProperties); } else if (!deploymentProperties.isEmpty()) { throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties + "' are defined for source '" + sourceType + "' which does not expose a service"); } }
Example #15
Source File: InsertIntoTableCallback.java From siddhi with Apache License 2.0 | 5 votes |
public InsertIntoTableCallback(Table table, StreamDefinition outputStreamDefinition, boolean convertToStreamEvent, StreamEventFactory streamEventFactory, StreamEventConverter streamEventConverter, String queryName) { super(queryName); this.table = table; this.outputStreamDefinition = outputStreamDefinition; this.convertToStreamEvent = convertToStreamEvent; this.streamEventFactory = streamEventFactory; this.streamEventConverter = streamEventConverter; }
Example #16
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery79() throws InterruptedException { log.info("Filter test79"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute ("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(60L)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("quantity", Expression.variable("quantity"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 500f, 60L, 6}); inputHandler.send(new Object[]{"WSO2", 70f, 60L, 2}); inputHandler.send(new Object[]{"WSO2", 60f, 300L, 4}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example #17
Source File: SinkMapper.java From siddhi with Apache License 2.0 | 5 votes |
public final void init(StreamDefinition streamDefinition, String type, OptionHolder mapOptionHolder, List<Element> unmappedPayloadList, Sink sink, ConfigReader mapperConfigReader, LatencyTracker mapperLatencyTracker, OptionHolder sinkOptionHolder, SiddhiAppContext siddhiAppContext) { this.mapperLatencyTracker = mapperLatencyTracker; this.siddhiAppContext = siddhiAppContext; sink.setTrpDynamicOptions(trpDynamicOptions); this.sinkListener = sink; this.sinkType = sink.getType(); this.sinkOptionHolder = sinkOptionHolder; this.optionHolder = mapOptionHolder; this.type = type; buildMapperTemplate(streamDefinition, unmappedPayloadList); init(streamDefinition, mapOptionHolder, templateBuilderMap, mapperConfigReader, siddhiAppContext); }
Example #18
Source File: SinkMapper.java From siddhi with Apache License 2.0 | 5 votes |
/** * Method to create mapper template. * * @param streamDefinition Stream definition corresponding to mapper * @param unmappedPayloadList mapper payload template list */ protected void buildMapperTemplate(StreamDefinition streamDefinition, List<Element> unmappedPayloadList) { if (unmappedPayloadList != null && !unmappedPayloadList.isEmpty()) { templateBuilderMap = new HashMap<>(); for (Element e : unmappedPayloadList) { TemplateBuilder templateBuilder = new TemplateBuilder(streamDefinition, e.getValue()); if (templateBuilderMap.containsKey(e.getKey())) { throw new SiddhiAppCreationException("Duplicate Keys, " + e.getKey() + ", in @payload() "); } templateBuilderMap.put(e.getKey(), templateBuilder); } } }
Example #19
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery81() throws InterruptedException { log.info("Filter test81"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN, Expression.value(70f)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example #20
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery80() throws InterruptedException { log.info("Filter test80"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN, Expression.value(50d)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example #21
Source File: EventTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testSimpleStreamEventConverter() { Attribute price = new Attribute("price", Attribute.Type.DOUBLE); Attribute symbol = new Attribute("symbol", Attribute.Type.STRING); MetaStreamEvent metaStreamEvent = new MetaStreamEvent(); metaStreamEvent.addOutputData(symbol); metaStreamEvent.addOutputData(price); StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT); Event event = new Event(System.currentTimeMillis(), new Object[]{"WSO2", 200, 50}); metaStreamEvent.addInputDefinition(streamDefinition); StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent); StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent); StreamEvent newEvent = eventPool.newInstance(); converter.convertEvent(event, newEvent); AssertJUnit.assertTrue(converter instanceof SimpleStreamEventConverter); AssertJUnit.assertNull(newEvent.getBeforeWindowData()); AssertJUnit.assertNull(newEvent.getOnAfterWindowData()); AssertJUnit.assertEquals(2, newEvent.getOutputData().length); AssertJUnit.assertEquals(200, newEvent.getOutputData()[1]); AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]); }
Example #22
Source File: DefineStreamTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testAnnotatingStreamDefinition3() { Element element = new Element("name", "query1"); String annotationString = "[@map( type = \"xml\", namespace = \"h=uri, a=uri\", @attributes( \"//h:time\", " + "\"//h:data\"))]"; String elementString = "name = \"query1\""; Annotation annotation = Annotation.annotation("source") .element("type", "http") .element("context", "/test") .element("transport", "http,https") .annotation(Annotation.annotation("map") .element("type", "xml") .element("namespace", "h=uri, a=uri") .annotation(Annotation.annotation("attributes") .element("//h:time") .element("//h:data") ) ); StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type .FLOAT).annotation(annotation.element(element)); annotation.setName("sink"); AssertJUnit.assertEquals(annotationString, annotation.getAnnotations().toString()); AssertJUnit.assertEquals(annotationString, annotation.getAnnotations("map").toString()); AssertJUnit.assertEquals("sink", annotation.getName()); AssertJUnit.assertEquals("http", annotation.getElement("type")); AssertJUnit.assertEquals("name", element.getKey()); AssertJUnit.assertEquals("query1", element.getValue()); AssertJUnit.assertEquals(elementString, element.toString()); }
Example #23
Source File: DefineStreamTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testStreamDefinition5() { StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT); String[] list = new String[]{"symbol", "price", "volume"}; AssertJUnit.assertEquals(Arrays.toString(list), Arrays.toString(streamDefinition.getAttributeNameArray())); }
Example #24
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery114() throws InterruptedException { log.info("Filter test114"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price1", Attribute.Type.FLOAT).attribute("price2", Attribute.Type.FLOAT) .attribute("volume", Attribute.Type.LONG).attribute("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.value(true))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price1", Expression .variable("price1")).select("quantity", Expression.variable("quantity"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); if (count.get() == 1) { AssertJUnit.assertEquals(50.0f, inEvents[0].getData()[1]); } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60f, 60L, 6}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); AssertJUnit.assertEquals(1, count.get()); siddhiAppRuntime.shutdown(); }
Example #25
Source File: TemplateBuilder.java From siddhi with Apache License 2.0 | 5 votes |
private void assignTemplateArrayAttributePositions(String[] splitTemplateArray, StreamDefinition streamDefinition) { this.positionArray = new int[splitTemplateArray.length / 2]; int positionCount = 0; for (int i = 0; i < splitTemplateArray.length; i++) { if (i % 2 != 0) { try { positionArray[positionCount++] = Integer.parseInt(splitTemplateArray[i]); } catch (NumberFormatException e) { throw new SiddhiAppCreationException(String.format("Invalid mapping configuration provided in " + "%s. Mapping parameter should be surrounded only with '{{' and '}}'.", streamDefinition)); } } } }
Example #26
Source File: DefineStreamTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DuplicateDefinitionException.class) public void testCreatingStreamDefinition2() { SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type .FLOAT)).defineStream(StreamDefinition.id("StockStream").attribute("index", Attribute.Type.INT).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type .FLOAT)); }
Example #27
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery54() throws InterruptedException { log.info("Filter test54"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.value(50d)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example #28
Source File: DefinitionParserHelper.java From siddhi with Apache License 2.0 | 5 votes |
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 #29
Source File: DefineStreamTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingStreamDefinition() { SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type .FLOAT)); }
Example #30
Source File: JsonSourceMapper.java From siddhi-map-json with Apache License 2.0 | 5 votes |
@Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, List<AttributeMapping> attributeMappingList, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.streamDefinition = streamDefinition; this.streamAttributes = this.streamDefinition.getAttributeList(); this.streamAttributesSize = this.streamDefinition.getAttributeList().size(); this.failOnMissingAttribute = Boolean.parseBoolean(optionHolder. validateAndGetStaticValue(FAIL_ON_MISSING_ATTRIBUTE_IDENTIFIER, "true")); this.factory = new JsonFactory(); if (attributeMappingList != null && attributeMappingList.size() > 0) { this.mappingPositions = new MappingPositionData[attributeMappingList.size()]; isCustomMappingEnabled = true; enclosingElement = optionHolder.validateAndGetStaticValue(ENCLOSING_ELEMENT_IDENTIFIER, DEFAULT_ENCLOSING_ELEMENT); for (int i = 0; i < attributeMappingList.size(); i++) { AttributeMapping attributeMapping = attributeMappingList.get(i); String attributeName = attributeMapping.getName(); int position = this.streamDefinition.getAttributePosition(attributeName); this.mappingPositions[i] = new MappingPositionData(position, attributeMapping.getMapping()); } } else { this.mappingPositions = new MappingPositionData[streamAttributesSize]; for (int i = 0; i < streamAttributesSize; i++) { this.mappingPositions[i] = new MappingPositionData(i, DEFAULT_JSON_MAPPING_PREFIX + this .streamDefinition.getAttributeList().get(i).getName()); } } }