Search in sources :

Example 1 with InMemoryTable

use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.

the class TestStoreForCacheMiss method init.

@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
    inMemoryTable = new InMemoryTable();
    MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
    cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        cacheTableMetaStreamEvent.addOutputData(attribute);
    }
    StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
    TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    for (Annotation annotation : tableDefinition.getAnnotations()) {
        if (!annotation.getName().equalsIgnoreCase("Store")) {
            testStoreContainingIMTableDefinition.annotation(annotation);
        }
    }
    inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) Attribute(io.siddhi.query.api.definition.Attribute) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) TableDefinition(io.siddhi.query.api.definition.TableDefinition) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Annotation(io.siddhi.query.api.annotation.Annotation)

Example 2 with InMemoryTable

use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.

the class TestStoreForCachePreLoading method init.

@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
    inMemoryTable = new InMemoryTable();
    MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
    cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        cacheTableMetaStreamEvent.addOutputData(attribute);
    }
    StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
    TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    for (Annotation annotation : tableDefinition.getAnnotations()) {
        if (!annotation.getName().equalsIgnoreCase("Store")) {
            testStoreContainingIMTableDefinition.annotation(annotation);
        }
    }
    inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
    ComplexEventChunk<StreamEvent> originalData = new ComplexEventChunk<>();
    StreamEvent data1 = new StreamEvent(0, 0, 3);
    data1.setOutputData(new Object[] { "WSO2", 55.6f, 100L });
    originalData.add(data1);
    StreamEvent data2 = new StreamEvent(0, 0, 3);
    data2.setOutputData(new Object[] { "IBM", 75.6f, 100L });
    originalData.add(data2);
    inMemoryTable.add(originalData);
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Attribute(io.siddhi.query.api.definition.Attribute) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) TableDefinition(io.siddhi.query.api.definition.TableDefinition) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Annotation(io.siddhi.query.api.annotation.Annotation)

Example 3 with InMemoryTable

use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.

the class SandboxTestCase method sandboxTest2.

@Test
public void sandboxTest2() throws InterruptedException {
    log.info("sandbox test2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + "   on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;";
    SiddhiApp siddhiApp = SiddhiCompiler.parse(app);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(siddhiApp);
    Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1);
    Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1);
    Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1);
    for (List<Source> sources : siddhiAppRuntime.getSources()) {
        for (Source source : sources) {
            Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory"));
        }
    }
    for (List<Sink> sinks : siddhiAppRuntime.getSinks()) {
        for (Sink sink : sinks) {
            Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory"));
        }
    }
    for (Table table : siddhiAppRuntime.getTables()) {
        Assert.assertTrue(table instanceof InMemoryTable);
    }
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
    InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream");
    siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
        }
    });
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    deleteStockStream.send(new Object[] { "IBM", 57.6f, 100L });
    countStockStream.send(new Object[] { "WSO2" });
    Thread.sleep(500);
    Assert.assertEquals(count.get(), 2);
    siddhiAppRuntime.shutdown();
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiApp(io.siddhi.query.api.SiddhiApp) Table(io.siddhi.core.table.Table) InMemoryTable(io.siddhi.core.table.InMemoryTable) Source(io.siddhi.core.stream.input.source.Source) StreamCallback(io.siddhi.core.stream.output.StreamCallback) Sink(io.siddhi.core.stream.output.sink.Sink) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 4 with InMemoryTable

use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.

the class DefinitionParserHelper method addTable.

public static void addTable(TableDefinition tableDefinition, ConcurrentMap<String, Table> tableMap, SiddhiAppContext siddhiAppContext) {
    if (!tableMap.containsKey(tableDefinition.getId())) {
        MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
        tableMetaStreamEvent.addInputDefinition(tableDefinition);
        for (Attribute attribute : tableDefinition.getAttributeList()) {
            tableMetaStreamEvent.addOutputData(attribute);
        }
        StreamEventFactory tableStreamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
        StreamEventCloner tableStreamEventCloner = new StreamEventCloner(tableMetaStreamEvent, tableStreamEventFactory);
        Annotation annotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_STORE, tableDefinition.getAnnotations());
        Table table;
        ConfigReader configReader = null;
        RecordTableHandlerManager recordTableHandlerManager = null;
        RecordTableHandler recordTableHandler = null;
        if (annotation != null) {
            annotation = updateAnnotationRef(annotation, SiddhiConstants.NAMESPACE_STORE, siddhiAppContext);
            String tableType = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
            if (tableType == null) {
                throw new SiddhiAppCreationException("Attribute 'type' does not exist for annotation '" + annotation + "'", annotation, siddhiAppContext);
            }
            Extension extension = new Extension() {

                @Override
                public String getNamespace() {
                    return SiddhiConstants.NAMESPACE_STORE;
                }

                @Override
                public String getName() {
                    return tableType;
                }
            };
            recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
            if (recordTableHandlerManager != null) {
                recordTableHandler = recordTableHandlerManager.generateRecordTableHandler();
            }
            table = (Table) SiddhiClassLoader.loadExtensionImplementation(extension, TableExtensionHolder.getInstance(siddhiAppContext));
            configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
        } else {
            table = new InMemoryTable();
        }
        table.initTable(tableDefinition, tableStreamEventFactory, tableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
        if (recordTableHandler != null) {
            recordTableHandlerManager.registerRecordTableHandler(recordTableHandler.getId(), recordTableHandler);
        }
        tableMap.putIfAbsent(tableDefinition.getId(), table);
    }
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) Table(io.siddhi.core.table.Table) InMemoryTable(io.siddhi.core.table.InMemoryTable) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) ConfigReader(io.siddhi.core.util.config.ConfigReader) RecordTableHandler(io.siddhi.core.table.record.RecordTableHandler) Annotation(io.siddhi.query.api.annotation.Annotation) Extension(io.siddhi.query.api.extension.Extension) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) RecordTableHandlerManager(io.siddhi.core.table.record.RecordTableHandlerManager) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 5 with InMemoryTable

use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.

the class SandboxTestCase method sandboxTest1.

@Test
public void sandboxTest1() throws InterruptedException {
    log.info("sandbox test1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + "   on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(app);
    Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1);
    Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1);
    Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1);
    for (List<Source> sources : siddhiAppRuntime.getSources()) {
        for (Source source : sources) {
            Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory"));
        }
    }
    for (List<Sink> sinks : siddhiAppRuntime.getSinks()) {
        for (Sink sink : sinks) {
            Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory"));
        }
    }
    for (Table table : siddhiAppRuntime.getTables()) {
        Assert.assertTrue(table instanceof InMemoryTable);
    }
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
    InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream");
    siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
        }
    });
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    deleteStockStream.send(new Object[] { "IBM", 57.6f, 100L });
    countStockStream.send(new Object[] { "WSO2" });
    Thread.sleep(500);
    Assert.assertEquals(count.get(), 2);
    siddhiAppRuntime.shutdown();
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) InputHandler(io.siddhi.core.stream.input.InputHandler) Table(io.siddhi.core.table.Table) InMemoryTable(io.siddhi.core.table.InMemoryTable) Source(io.siddhi.core.stream.input.source.Source) StreamCallback(io.siddhi.core.stream.output.StreamCallback) Sink(io.siddhi.core.stream.output.sink.Sink) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

InMemoryTable (io.siddhi.core.table.InMemoryTable)6 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)4 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)4 Annotation (io.siddhi.query.api.annotation.Annotation)4 Attribute (io.siddhi.query.api.definition.Attribute)4 Table (io.siddhi.core.table.Table)3 TableDefinition (io.siddhi.query.api.definition.TableDefinition)3 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)2 SiddhiManager (io.siddhi.core.SiddhiManager)2 Event (io.siddhi.core.event.Event)2 InputHandler (io.siddhi.core.stream.input.InputHandler)2 Source (io.siddhi.core.stream.input.source.Source)2 StreamCallback (io.siddhi.core.stream.output.StreamCallback)2 Sink (io.siddhi.core.stream.output.sink.Sink)2 Test (org.testng.annotations.Test)2 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)1 StreamEvent (io.siddhi.core.event.stream.StreamEvent)1 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)1 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)1 RecordTableHandler (io.siddhi.core.table.record.RecordTableHandler)1