Search in sources :

Example 46 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class SiddhiAppRuntime method getStoreQueryOutputAttributes.

/**
 * This method get the storeQuery and return the corresponding output and its types.
 *
 * @param storeQuery       this storeQuery is processed and get the output attributes.
 * @param storeQueryString this passed to report errors with context if there are any.
 * @return List of output attributes
 */
private Attribute[] getStoreQueryOutputAttributes(StoreQuery storeQuery, String storeQueryString) {
    try {
        StoreQueryRuntime storeQueryRuntime = storeQueryRuntimeMap.get(storeQuery);
        if (storeQueryRuntime == null) {
            storeQueryRuntime = StoreQueryParser.parse(storeQuery, siddhiAppContext, tableMap, windowMap, aggregationMap);
            storeQueryRuntimeMap.put(storeQuery, storeQueryRuntime);
        }
        return storeQueryRuntime.getStoreQueryOutputAttributes();
    } catch (RuntimeException e) {
        if (e instanceof SiddhiAppContextException) {
            throw new StoreQueryCreationException(((SiddhiAppContextException) e).getMessageWithOutContext(), e, ((SiddhiAppContextException) e).getQueryContextStartIndex(), ((SiddhiAppContextException) e).getQueryContextEndIndex(), null, siddhiAppContext.getSiddhiAppString());
        }
        throw new StoreQueryCreationException(e.getMessage(), e);
    }
}
Also used : SiddhiAppContextException(org.wso2.siddhi.query.api.exception.SiddhiAppContextException) StoreQueryRuntime(org.wso2.siddhi.core.query.StoreQueryRuntime) StoreQueryCreationException(org.wso2.siddhi.core.exception.StoreQueryCreationException)

Example 47 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest4.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionTest4() throws InterruptedException {
    log.info("convert function test 4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "" + "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " + "bool) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS) as valueB1 " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 48 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionExceptionTest9.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionExceptionTest9() throws InterruptedException {
    log.info("convert function test 9");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream typeStream (typeS object, typeF float, typeD double, typeI int, typeL " + "long, typeB bool, typeN double) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,typeS) as valueS, convert(typeF,'float') as valueF, convert(typeD," + "'double') as valueD , convert(typeI,'int') as valueI , convert(typeL,'long') as valueL , " + "convert(typeB,'bool') as valueB, convert(typeN,'string') as valueN " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 49 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest6.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void convertFunctionTest6() throws InterruptedException {
    log.info("convert function test 6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "" + "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " + "bool) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,string) as valueB1 " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 50 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest1.

@Test
public void convertFunctionTest1() throws InterruptedException {
    log.info("convert function test 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "" + "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " + "bool, typeN double) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,'string') as valueS, convert(typeF,'float') as valueF, convert(typeD,'double') " + "as valueD , convert(typeI,'int') as valueI , convert(typeL,'long') as valueL , convert(typeB,'bool')" + " as valueB, convert(typeN,'string') as valueN " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            for (Event inEvent : inEvents) {
                count++;
                AssertJUnit.assertTrue(inEvent.getData(0) instanceof String);
                AssertJUnit.assertTrue(inEvent.getData(1) instanceof Float);
                AssertJUnit.assertTrue(inEvent.getData(2) instanceof Double);
                AssertJUnit.assertTrue(inEvent.getData(3) instanceof Integer);
                AssertJUnit.assertTrue(inEvent.getData(4) instanceof Long);
                AssertJUnit.assertTrue(inEvent.getData(5) instanceof Boolean);
                AssertJUnit.assertTrue(inEvent.getData(6) == null);
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("typeStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 2f, 3d, 4, 5L, true, null });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3