Search in sources :

Example 36 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class SinkMapper method buildMapperTemplate.

/**
 * Method to create mapper template.
 *
 * @param streamDefinition    Stream definition corresponding to mapper
 * @param unmappedPayloadList mapper payload template list
 */
protected void buildMapperTemplate(StreamDefinition streamDefinition, List<Element> unmappedPayloadList) {
    if (unmappedPayloadList != null && !unmappedPayloadList.isEmpty()) {
        templateBuilderMap = new HashMap<>();
        for (Element e : unmappedPayloadList) {
            TemplateBuilder templateBuilder = new TemplateBuilder(streamDefinition, e.getValue());
            if (templateBuilderMap.containsKey(e.getKey())) {
                throw new SiddhiAppCreationException("Duplicate Keys, " + e.getKey() + ", in @payload() ");
            }
            templateBuilderMap.put(e.getKey(), templateBuilder);
        }
    }
}
Also used : SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) Element(io.siddhi.query.api.annotation.Element) TemplateBuilder(io.siddhi.core.util.transport.TemplateBuilder)

Example 37 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class Sink method initOnlyTransport.

public final void initOnlyTransport(StreamDefinition streamDefinition, OptionHolder transportOptionHolder, ConfigReader sinkConfigReader, String type, DistributedTransport.ConnectionCallback connectionCallback, Map<String, String> deploymentProperties, SiddhiAppContext siddhiAppContext) {
    this.type = type;
    this.streamDefinition = streamDefinition;
    this.connectionCallback = connectionCallback;
    this.siddhiAppContext = siddhiAppContext;
    init(streamDefinition, transportOptionHolder, sinkConfigReader, siddhiAppContext);
    scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
    serviceDeploymentInfo = exposeServiceDeploymentInfo();
    if (serviceDeploymentInfo != null) {
        serviceDeploymentInfo.addDeploymentProperties(deploymentProperties);
    } else if (!deploymentProperties.isEmpty()) {
        throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties + "' are defined for sink '" + type + "' which does not expose a service");
    }
}
Also used : SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException)

Example 38 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class SumIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    Attribute sum;
    Expression sumInitialValue;
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Sum incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    if (attributeType.equals(Attribute.Type.FLOAT) || attributeType.equals(Attribute.Type.DOUBLE)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.DOUBLE);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("double"));
        returnType = Attribute.Type.DOUBLE;
    } else if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.LONG);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("long"));
        returnType = Attribute.Type.LONG;
    } else {
        throw new SiddhiAppRuntimeException("Sum aggregation cannot be executed on attribute type " + attributeType.toString());
    }
    this.baseAttributes = new Attribute[] { sum };
    // Original attribute names
    this.baseAttributesInitialValues = new Expression[] { sumInitialValue };
// used for initial values, since those would be executed using original meta
}
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) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 39 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class AbstractStreamProcessor method initProcessor.

public void initProcessor(MetaStreamEvent metaStreamEvent, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, boolean groupBy, SiddhiElement siddhiElement, SiddhiQueryContext siddhiQueryContext) {
    this.metaStreamEvent = metaStreamEvent;
    this.siddhiQueryContext = siddhiQueryContext;
    try {
        this.inputDefinition = metaStreamEvent.getLastInputDefinition();
        this.attributeExpressionExecutors = attributeExpressionExecutors;
        this.attributeExpressionLength = attributeExpressionExecutors.length;
        InputParameterValidator.validateExpressionExecutors(this, attributeExpressionExecutors);
        StateFactory<S> stateFactory = init(metaStreamEvent, metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, streamEventClonerHolder, outputExpectsExpiredEvents, findToBeExecuted, siddhiQueryContext);
        this.additionalAttributes = getReturnAttributes();
        this.stateHolder = siddhiQueryContext.generateStateHolder(this.getClass().getName(), groupBy, stateFactory);
        siddhiQueryContext.getSiddhiAppContext().addEternalReferencedHolder(this);
        if (additionalAttributes.size() > 0) {
            StreamDefinition outputDefinition = StreamDefinition.id(inputDefinition.getId());
            outputDefinition.setQueryContextStartIndex(siddhiElement.getQueryContextStartIndex());
            outputDefinition.setQueryContextEndIndex(siddhiElement.getQueryContextEndIndex());
            for (Attribute attribute : inputDefinition.getAttributeList()) {
                outputDefinition.attribute(attribute.getName(), attribute.getType());
            }
            for (Attribute attribute : additionalAttributes) {
                outputDefinition.attribute(attribute.getName(), attribute.getType());
            }
            metaStreamEvent.addInputDefinition(outputDefinition);
        }
    } catch (Throwable t) {
        throw new SiddhiAppCreationException(t.getMessage(), t, siddhiElement.getQueryContextStartIndex(), siddhiElement.getQueryContextEndIndex(), siddhiQueryContext.getSiddhiAppContext());
    }
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException)

Example 40 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class OutputParser method constructOutputCallback.

public static OutputCallback constructOutputCallback(OutputStream outStream, String key, ConcurrentMap<String, StreamJunction> streamJunctionMap, StreamDefinition outputStreamDefinition, SiddhiQueryContext siddhiQueryContext) {
    String id = outStream.getId();
    // Construct CallBack
    if (outStream instanceof InsertIntoStream) {
        StreamJunction outputStreamJunction = streamJunctionMap.get(id + key);
        if (outputStreamJunction == null) {
            outputStreamJunction = new StreamJunction(outputStreamDefinition, siddhiQueryContext.getSiddhiAppContext().getExecutorService(), siddhiQueryContext.getSiddhiAppContext().getBufferSize(), null, siddhiQueryContext.getSiddhiAppContext());
            streamJunctionMap.putIfAbsent(id + key, outputStreamJunction);
        }
        InsertIntoStreamCallback insertIntoStreamCallback = new InsertIntoStreamCallback(outputStreamDefinition, siddhiQueryContext.getName());
        insertIntoStreamCallback.init(streamJunctionMap.get(id + key));
        return insertIntoStreamCallback;
    } else {
        throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
    }
}
Also used : SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) InsertIntoStream(io.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(io.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(io.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Aggregations

SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)54 Attribute (io.siddhi.query.api.definition.Attribute)23 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)16 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)15 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)12 SiddhiManager (io.siddhi.core.SiddhiManager)12 ArrayList (java.util.ArrayList)12 Expression (io.siddhi.query.api.expression.Expression)11 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)10 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)10 Annotation (io.siddhi.query.api.annotation.Annotation)10 Variable (io.siddhi.query.api.expression.Variable)10 ConfigReader (io.siddhi.core.util.config.ConfigReader)9 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 Element (io.siddhi.query.api.annotation.Element)8 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)8 Table (io.siddhi.core.table.Table)7 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)7