Search in sources :

Example 6 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest5.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionTest5() throws InterruptedException {
    log.info("convert function test 5");
    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','int') as valueB1 " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 7 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionExceptionTest10.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionExceptionTest10() throws InterruptedException {
    log.info("convert function test 10");
    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,'invalidType') 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 8 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project siddhi by wso2.

the class FunctionTestCase method functionTest2.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void functionTest2() throws InterruptedException {
    log.info("function test 2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price1 double, price2 float, volume " + "long , quantity int);";
    String query = "@info(name = 'query1') from cseEventStream select symbol, coalesce(price1,price2) as price," + "quantity 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++;
                if (count == 1) {
                    AssertJUnit.assertEquals(50.0f, inEvent.getData()[1]);
                } else if (count == 2) {
                    AssertJUnit.assertEquals(70.0f, inEvent.getData()[1]);
                } else if (count == 3) {
                    AssertJUnit.assertEquals(44.0f, inEvent.getData()[1]);
                } else if (count == 4) {
                    AssertJUnit.assertEquals(null, inEvent.getData()[1]);
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60f, 60L, 6 });
    inputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10 });
    inputHandler.send(new Object[] { "WSO2", null, 44f, 200L, 56 });
    inputHandler.send(new Object[] { "WSO2", null, null, 200L, 56 });
    Thread.sleep(100);
    AssertJUnit.assertEquals(4, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 9 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project siddhi by wso2.

the class FunctionTestCase method functionTest3.

@Test
public void functionTest3() throws InterruptedException {
    log.info("function test 3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price1 float, price2 float, volume long" + " , quantity int);";
    String query = "@info(name = 'query1') from cseEventStream[coalesce(price1,price2) > 0f] select symbol, " + "coalesce(price1,price2) as price,quantity 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++;
                if (count == 1) {
                    AssertJUnit.assertEquals(50.0f, inEvent.getData()[1]);
                } else if (count == 2) {
                    AssertJUnit.assertEquals(70.0f, inEvent.getData()[1]);
                } else if (count == 3) {
                    AssertJUnit.assertEquals(44.0f, inEvent.getData()[1]);
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60f, 60L, 6 });
    inputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10 });
    inputHandler.send(new Object[] { "WSO2", null, 44f, 200L, 56 });
    inputHandler.send(new Object[] { "WSO2", null, null, 200L, 56 });
    Thread.sleep(100);
    org.testng.AssertJUnit.assertEquals(3, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 10 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitAttribute_reference.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Variable visitAttribute_reference(@NotNull SiddhiQLParser.Attribute_referenceContext ctx) {
    // attribute_reference
    // : hash1='#'? name1=name ('['attribute_index1=attribute_index']')? (hash2='#' name2=name
    // ('['attribute_index2=attribute_index']')?)? '.'  attribute_name
    // | attribute_name
    // ;
    Variable variable = Expression.variable((String) visit(ctx.attribute_name()));
    if (ctx.name1 != null && ctx.name2 != null) {
        // Stream and Function
        variable.setStreamId(ctx.hash1 != null, (String) visit(ctx.name1));
        if (ctx.attribute_index1 != null) {
            variable.setStreamIndex((Integer) visit(ctx.attribute_index1));
        }
        variable.setFunctionId((String) visit(ctx.name2));
        if (ctx.attribute_index2 != null) {
            variable.setFunctionIndex((Integer) visit(ctx.attribute_index2));
        }
    } else if (ctx.name1 != null) {
        // name2 == null
        if (ctx.hash1 == null) {
            // Stream
            variable.setStreamId((String) visit(ctx.name1));
            if (ctx.attribute_index1 != null) {
                variable.setStreamIndex((Integer) visit(ctx.attribute_index1));
            }
        } else {
            // InnerStream or Function
            String name = (String) visit(ctx.name1);
            if (activeStreams.contains("#" + name)) {
                // InnerStream
                variable.setStreamId(true, name);
                if (ctx.attribute_index1 != null) {
                    variable.setStreamIndex((Integer) visit(ctx.attribute_index1));
                }
            } else {
                // Function
                variable.setFunctionId(name);
                if (ctx.attribute_index1 != null) {
                    variable.setFunctionIndex((Integer) visit(ctx.attribute_index1));
                }
            }
        }
    }
    populateQueryContext(variable, ctx);
    return variable;
}
Also used : Variable(org.wso2.siddhi.query.api.expression.Variable)

Aggregations

Test (org.testng.annotations.Test)94 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)49 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)44 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)39 ArrayList (java.util.ArrayList)37 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)35 BString (org.ballerinalang.model.values.BString)30 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)29 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)20 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)20 BJSON (org.ballerinalang.model.values.BJSON)19 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)19 List (java.util.List)18 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)18 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)16 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)15 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)14 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)14