use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class EventTestCase method testPassThroughStreamEventConverter.
@Test
public void testPassThroughStreamEventConverter() {
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputDataAllowingDuplicate(symbol);
metaStreamEvent.addOutputDataAllowingDuplicate(price);
metaStreamEvent.addOutputDataAllowingDuplicate(volume);
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.0, 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 ZeroStreamEventConverter);
AssertJUnit.assertEquals(3, newEvent.getOutputData().length);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
AssertJUnit.assertEquals(200.0, newEvent.getOutputData()[1]);
AssertJUnit.assertEquals(50, newEvent.getOutputData()[2]);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class EventTestCase method testSimpleStreamEventConverter.
@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]);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class EventTestCase method testConditionExpressionExecutors.
@Test
public void testConditionExpressionExecutors() {
// StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
// .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
priceVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 1 });
VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
volumeVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 2 });
ExpressionExecutor compareLessThanExecutor = new LessThanCompareConditionExpressionExecutorFloatFloat(new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT), priceVariableExpressionExecutor);
ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(compareLessThanExecutor, compareGreaterThanExecutor);
int count = 0;
for (int i = 0; i < 3; i++) {
StreamEvent event = new StreamEvent(0, 0, 3);
event.setOutputData(new Object[] { "WSO2", i * 11f, 5 });
if ((Boolean) andExecutor.execute(event)) {
count++;
}
}
AssertJUnit.assertEquals("Two events should pass through executor", 2, count);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class EventTestCase method testExpressionExecutors.
@Test
public void testExpressionExecutors() {
// StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
// .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
priceVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 1 });
ExpressionExecutor addExecutor = new AddExpressionExecutorFloat(new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT), priceVariableExpressionExecutor);
StreamEvent event = new StreamEvent(0, 0, 3);
event.setOutputData(new Object[] { "WSO2", 10f, 5 });
AssertJUnit.assertEquals("Result of adding should be 20.0", 20f, addExecutor.execute(event));
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreForCachePreLoading method compileSelection.
@Override
protected CompiledSelection compileSelection(List<SelectAttributeBuilder> selectAttributeBuilders, List<ExpressionBuilder> groupByExpressionBuilder, ExpressionBuilder havingExpressionBuilder, List<OrderByAttributeBuilder> orderByAttributeBuilders, Long limit, Long offset) {
CompiledSelectionWithCache compiledSelectionWithCache;
MetaStateEvent metaStateEvent = matchingMetaInfoHolderForTestOnDemandQuery.getMetaStateEvent().clone();
ReturnStream returnStream = new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS);
int metaPosition = SiddhiConstants.UNKNOWN_STATE;
List<VariableExpressionExecutor> variableExpressionExecutorsForQuerySelector = new ArrayList<>();
if (metaStateEvent.getOutputDataAttributes().size() == 0) {
for (Attribute outputAttribute : metaStateEvent.getMetaStreamEvents()[0].getOnAfterWindowData()) {
metaStateEvent.getMetaStreamEvents()[0].addOutputData(outputAttribute);
}
}
QuerySelector querySelector = SelectorParser.parse(selectorForTestOnDemandQuery, returnStream, metaStateEvent, tableMap, variableExpressionExecutorsForQuerySelector, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContextForTestOnDemandQuery);
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutorsForQuerySelector);
querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStateEvent));
compiledSelectionWithCache = new CompiledSelectionWithCache(null, querySelector, metaStateEvent, 0, null);
return compiledSelectionWithCache;
}
Aggregations