Search in sources :

Example 36 with Attribute

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);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 37 with Attribute

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;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 38 with Attribute

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 };
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException)

Example 39 with Attribute

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());
    }
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 40 with Attribute

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 };
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) Expression(io.siddhi.query.api.expression.Expression)

Aggregations

Attribute (io.siddhi.query.api.definition.Attribute)86 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)43 ArrayList (java.util.ArrayList)29 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)27 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)23 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)23 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)22 StreamEvent (io.siddhi.core.event.stream.StreamEvent)21 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)19 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Variable (io.siddhi.query.api.expression.Variable)18 Expression (io.siddhi.query.api.expression.Expression)17 Test (org.testng.annotations.Test)17 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)15 HashMap (java.util.HashMap)15 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)14 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)14 TableDefinition (io.siddhi.query.api.definition.TableDefinition)13 Map (java.util.Map)13 Annotation (io.siddhi.query.api.annotation.Annotation)12