Search in sources :

Example 21 with Attribute

use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.

the class AggregationParser method createRestEvent.

public static StreamEvent createRestEvent(MetaStreamEvent metaStreamEvent, StreamEvent streamEvent) {
    streamEvent.setTimestamp(0);
    streamEvent.setType(ComplexEvent.Type.RESET);
    List<Attribute> outputData = metaStreamEvent.getOutputData();
    for (int i = 0, outputDataSize = outputData.size(); i < outputDataSize; i++) {
        Attribute attribute = outputData.get(i);
        switch(attribute.getType()) {
            case STRING:
                streamEvent.setOutputData("", i);
                break;
            case INT:
                streamEvent.setOutputData(0, i);
                break;
            case LONG:
                streamEvent.setOutputData(0L, i);
                break;
            case FLOAT:
                streamEvent.setOutputData(0f, i);
                break;
            case DOUBLE:
                streamEvent.setOutputData(0.0, i);
                break;
            case BOOL:
                streamEvent.setOutputData(false, i);
                break;
            case OBJECT:
                streamEvent.setOutputData(null, i);
                break;
        }
    }
    return streamEvent;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute)

Example 22 with Attribute

use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.

the class AggregationParser method generateCUDMetaStreamEvent.

private static MetaStreamEvent generateCUDMetaStreamEvent(boolean isProcessingOnExternalTime) {
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    Map<Attribute, int[]> cudInputStreamAttributesList = generateCUDInputStreamAttributes(isProcessingOnExternalTime);
    StreamDefinition inputDefinition = new StreamDefinition();
    for (Attribute attribute : cudInputStreamAttributesList.keySet()) {
        metaStreamEvent.addData(attribute);
        inputDefinition.attribute(attribute.getName(), attribute.getType());
    }
    metaStreamEvent.addInputDefinition(inputDefinition);
    metaStreamEvent.setEventType(MetaStreamEvent.EventType.DEFAULT);
    return metaStreamEvent;
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 23 with Attribute

use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.

the class AggregationParser method generateCUDInputStreamAttributes.

private static Map<Attribute, int[]> generateCUDInputStreamAttributes(boolean isProcessingOnExternalTime) {
    Map<Attribute, int[]> cudInputStreamAttributeList = new LinkedHashMap<>();
    if (isProcessingOnExternalTime) {
        cudInputStreamAttributeList.put(new Attribute(FROM_TIMESTAMP, Attribute.Type.LONG), new int[] { 0, 1, 3 });
        cudInputStreamAttributeList.put(new Attribute(TO_TIMESTAMP, Attribute.Type.LONG), new int[] { 2, 4 });
    } else {
        cudInputStreamAttributeList.put(new Attribute(FROM_TIMESTAMP, Attribute.Type.LONG), new int[] { 0, 1 });
        cudInputStreamAttributeList.put(new Attribute(TO_TIMESTAMP, Attribute.Type.LONG), new int[] { 2 });
    }
    return cudInputStreamAttributeList;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) LinkedHashMap(java.util.LinkedHashMap)

Example 24 with Attribute

use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.

the class AggregationParser method processAggregationSelectors.

private static void processAggregationSelectors(AggregationDefinition aggregationDefinition, SiddhiQueryContext siddhiQueryContext, Map<String, Table> tableMap, List<VariableExpressionExecutor> incomingVariableExpressionExecutors, MetaStreamEvent incomingMetaStreamEvent, List<ExpressionExecutor> incomingExpressionExecutors, List<Expression> outputExpressions, OutputAttribute outputAttribute, Expression expression) {
    ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    incomingExpressionExecutors.add(expressionExecutor);
    incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
    aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
    outputExpressions.add(Expression.variable(outputAttribute.getRename()));
}
Also used : ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute)

Example 25 with Attribute

use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.

the class AggregationParser method validateBaseAggregators.

private static void validateBaseAggregators(List<IncrementalAttributeAggregator> incrementalAttributeAggregators, IncrementalAttributeAggregator incrementalAttributeAggregator, Attribute[] baseAttributes, Expression[] baseAttributeInitialValues, Expression[] baseAggregators, int i) {
    for (int i1 = i; i1 < incrementalAttributeAggregators.size(); i1++) {
        IncrementalAttributeAggregator otherAttributeAggregator = incrementalAttributeAggregators.get(i1);
        if (otherAttributeAggregator != incrementalAttributeAggregator) {
            Attribute[] otherBaseAttributes = otherAttributeAggregator.getBaseAttributes();
            Expression[] otherBaseAttributeInitialValues = otherAttributeAggregator.getBaseAttributeInitialValues();
            Expression[] otherBaseAggregators = otherAttributeAggregator.getBaseAggregators();
            for (int j = 0; j < otherBaseAttributes.length; j++) {
                if (baseAttributes[i].equals(otherBaseAttributes[j])) {
                    if (!baseAttributeInitialValues[i].equals(otherBaseAttributeInitialValues[j])) {
                        throw new SiddhiAppCreationException("BaseAttributes having same name should " + "be defined with same initial values, but baseAttribute '" + baseAttributes[i] + "' is defined in '" + incrementalAttributeAggregator.getClass().getName() + "' and '" + otherAttributeAggregator.getClass().getName() + "' with different initial values.");
                    }
                    if (!baseAggregators[i].equals(otherBaseAggregators[j])) {
                        throw new SiddhiAppCreationException("BaseAttributes having same name should " + "be defined with same baseAggregators, but baseAttribute '" + baseAttributes[i] + "' is defined in '" + incrementalAttributeAggregator.getClass().getName() + "' and '" + otherAttributeAggregator.getClass().getName() + "' with different baseAggregators.");
                    }
                }
            }
        }
    }
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) IncrementalAttributeAggregator(io.siddhi.core.query.selector.attribute.aggregator.incremental.IncrementalAttributeAggregator)

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