use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test12.
@Test
public void test12() {
log.info("Test12 - Test output attributes and its types for table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String storeQuery = "" + "from StockTable " + "select * ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.start();
Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
Attribute volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute, volumeAttribute };
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
storeQuery = "" + "from StockTable " + "select symbol, sum(volume) as totalVolume ;";
actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
siddhiAppRuntime.shutdown();
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method parameterMapToStateEvent.
private StateEvent parameterMapToStateEvent(Map<String, Object> parameterMap) {
StateEvent stateEvent = new StateEvent(2, parameterMap.size());
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);
}
}
StreamEvent event = storeEventPool.newInstance();
event.setOutputData(outputData.toArray());
stateEvent.addEvent(0, event);
return stateEvent;
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class AvgIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
// Send the relevant attribute to this
Attribute sum;
Attribute count;
Expression sumInitialValue;
Expression countInitialValue;
if (attributeName == null) {
throw new SiddhiAppCreationException("Average incremental attribute aggregation cannot be executed " + "when no parameters are given");
}
SumIncrementalAttributeAggregator sumIncrementalAttributeAggregator = new SumIncrementalAttributeAggregator();
sumIncrementalAttributeAggregator.init(attributeName, attributeType);
CountIncrementalAttributeAggregator countIncrementalAttributeAggregator = new CountIncrementalAttributeAggregator();
countIncrementalAttributeAggregator.init(null, null);
// Only one attribute exists for sum and count
sum = sumIncrementalAttributeAggregator.getBaseAttributes()[0];
count = countIncrementalAttributeAggregator.getBaseAttributes()[0];
// Only one init value exists for sum and count
sumInitialValue = sumIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
countInitialValue = countIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
this.baseAttributes = new Attribute[] { sum, count };
this.baseAttributesInitialValues = new Expression[] { sumInitialValue, countInitialValue };
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class MaxIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
if (attributeName == null) {
throw new SiddhiAppCreationException("Max incremental attribute aggregation cannot be executed " + "when no parameters are given");
}
if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG) || attributeType.equals(Attribute.Type.DOUBLE) || attributeType.equals(Attribute.Type.FLOAT)) {
this.baseAttributes = new Attribute[] { new Attribute("AGG_MAX_".concat(attributeName), attributeType) };
this.baseAttributesInitialValues = new Expression[] { Expression.variable(attributeName) };
this.returnType = attributeType;
} else {
throw new SiddhiAppRuntimeException("Max aggregation cannot be executed on attribute type " + attributeType.toString());
}
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class CountIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
if (attributeName != null) {
LOG.warn("Aggregation count function will return the count of all events and count(" + attributeName + ") will be considered as count().");
}
Attribute count;
Expression countInitialValue;
// Since we set the initial value of count, we can simply set it as long
// However, since count is summed internally (in avg incremental calculation),
// ensure that either double or long is used here (since return value of sum is long or
// double. Long is chosen here)
count = new Attribute("AGG_COUNT", Attribute.Type.LONG);
countInitialValue = Expression.value(1L);
this.baseAttributes = new Attribute[] { count };
this.baseAttributesInitialValues = new Expression[] { countInitialValue };
}
Aggregations