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);
}
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);
}
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();
}
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();
}
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;
}
Aggregations