use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreContainingInMemoryTable 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);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method convForDelete.
private ComplexEventChunk<StateEvent> convForDelete(List<Map<String, Object>> deleteConditionParameterMaps) {
List<Object[]> objectList = new LinkedList<>();
for (Map<String, Object> parameterMap : deleteConditionParameterMaps) {
List<Object> outputData = new ArrayList<>();
List<Attribute> attributeList = inMemoryTable.getTableDefinition().getAttributeList();
for (int i = 0; i < attributeList.size(); i++) {
if (parameterMap.get(attributeList.get(i).getName()) != null) {
outputData.add(parameterMap.get(attributeList.get(i).getName()));
} else {
outputData.add(null);
}
}
objectList.add(outputData.toArray());
}
ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>();
for (Object[] record : objectList) {
StreamEvent event = new StreamEvent(0, 0, record.length);
StateEvent stateEvent = new StateEvent(2, record.length);
event.setOutputData(record);
stateEvent.addEvent(0, event);
complexEventChunk.add(stateEvent);
}
return complexEventChunk;
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class SimpleQueryTestCase method testForAttribute.
@Test
public void testForAttribute() {
String attributeString = "Attribute{id='symbol', type=STRING}";
Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
AssertJUnit.assertEquals(attributeString, symbolAttribute.toString());
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class EventTestCase method testStreamEventConverter.
@Test
public void testStreamEventConverter() {
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addData(volume);
metaStreamEvent.initializeOnAfterWindowData();
metaStreamEvent.addData(price);
metaStreamEvent.addOutputData(symbol);
// complex attribute
metaStreamEvent.addOutputData(null);
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 SelectiveStreamEventConverter);
// volume
AssertJUnit.assertEquals(1, newEvent.getBeforeWindowData().length);
// price
AssertJUnit.assertEquals(1, newEvent.getOnAfterWindowData().length);
// symbol and avgPrice
AssertJUnit.assertEquals(2, newEvent.getOutputData().length);
AssertJUnit.assertEquals(50, newEvent.getBeforeWindowData()[0]);
AssertJUnit.assertEquals(200, newEvent.getOnAfterWindowData()[0]);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class EventTestCase method testUpdateMetaEvent.
@Test
public void testUpdateMetaEvent() {
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
Attribute price = new Attribute("price", Attribute.Type.FLOAT);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addData(volume);
metaStreamEvent.addData(price);
metaStreamEvent.addData(symbol);
metaStreamEvent.initializeOnAfterWindowData();
metaStreamEvent.addData(price);
metaStreamEvent.addOutputData(symbol);
metaStreamEvent.addOutputData(null);
MetaStateEvent metaStateEvent = new MetaStateEvent(1);
metaStateEvent.addEvent(metaStreamEvent);
VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
VariableExpressionExecutor symbolVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("symbol", Attribute.Type.STRING), 0, 0);
QueryParserHelper.reduceMetaComplexEvent(metaStateEvent);
QueryParserHelper.updateVariablePosition(metaStateEvent, Arrays.asList(priceVariableExpressionExecutor, volumeVariableExpressionExecutor, symbolVariableExpressionExecutor));
AssertJUnit.assertEquals(1, metaStreamEvent.getBeforeWindowData().size());
AssertJUnit.assertEquals(1, metaStreamEvent.getOnAfterWindowData().size());
AssertJUnit.assertEquals(2, metaStreamEvent.getOutputData().size());
AssertJUnit.assertArrayEquals(new int[] { 0, 0, 1, 0 }, priceVariableExpressionExecutor.getPosition());
AssertJUnit.assertArrayEquals(new int[] { 0, 0, 0, 0 }, volumeVariableExpressionExecutor.getPosition());
AssertJUnit.assertArrayEquals(new int[] { 0, 0, 2, 0 }, symbolVariableExpressionExecutor.getPosition());
}
Aggregations